libc/math: add simple implementation for sincos API

Signed-off-by: Xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xuxingliang 2023-01-10 14:32:07 +08:00 committed by Xiang Xiao
parent ef65d443ad
commit 431e31b6b2
5 changed files with 131 additions and 0 deletions

View File

@ -394,6 +394,14 @@ long double frexpl(long double x, int *exp);
/* Trigonometric Functions **************************************************/
void sincosf(float, float *, float *);
#ifdef CONFIG_HAVE_DOUBLE
void sincos(double, double *, double *);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
void sincosl(long double, long double *, long double *);
#endif
float sinf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sin (double x);

View File

@ -28,6 +28,7 @@ CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c
CSRCS += lib_powf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c
CSRCS += lib_tanhf.c lib_asinhf.c lib_acoshf.c lib_atanhf.c lib_erff.c
CSRCS += lib_copysignf.c lib_scalbnf.c lib_scalbn.c lib_scalbnl.c
CSRCS += lib_sincos.c lib_sincosf.c lib_sincosl.c
CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_cos.c
CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_fmod.c lib_frexp.c

View File

@ -0,0 +1,42 @@
/****************************************************************************
* libs/libc/math/lib_sincos.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <math.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_HAVE_DOUBLE
void sincos(double x, double *s, double *c)
{
*s = sin(x);
*c = cos(x);
}
#endif

View File

@ -0,0 +1,38 @@
/****************************************************************************
* libs/libc/math/lib_sincosf.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <math.h>
/****************************************************************************
* Public Functions
****************************************************************************/
void sincosf(float x, float *s, float *c)
{
*s = sinf(x);
*c = cosf(x);
}

View File

@ -0,0 +1,42 @@
/****************************************************************************
* libs/libc/math/lib_sincosl.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <math.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_HAVE_LONG_DOUBLE
void sincosl(long double x, long double *s, long double *c)
{
*s = sinl(x);
*c = cosl(x);
}
#endif