math: Implement cbrt
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
7356b5a2ed
commit
57e1211ed6
@ -372,6 +372,10 @@ double cosh (double x);
|
|||||||
long double coshl (long double x);
|
long double coshl (long double x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_HAVE_DOUBLE
|
||||||
|
double cbrt (double x);
|
||||||
|
#endif
|
||||||
|
|
||||||
float tanhf (float x);
|
float tanhf (float x);
|
||||||
#ifdef CONFIG_HAVE_DOUBLE
|
#ifdef CONFIG_HAVE_DOUBLE
|
||||||
double tanh (double x);
|
double tanh (double x);
|
||||||
|
@ -49,7 +49,7 @@ CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_fmod.c lib_frexp.c
|
|||||||
CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c
|
CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c
|
||||||
CSRCS += lib_pow.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c
|
CSRCS += lib_pow.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c
|
||||||
CSRCS += lib_tanh.c lib_asinh.c lib_acosh.c lib_atanh.c lib_erf.c
|
CSRCS += lib_tanh.c lib_asinh.c lib_acosh.c lib_atanh.c lib_erf.c
|
||||||
CSRCS += lib_copysign.c
|
CSRCS += lib_copysign.c lib_cbrt.c
|
||||||
|
|
||||||
CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c
|
CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c
|
||||||
CSRCS += lib_cosl.c lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c
|
CSRCS += lib_cosl.c lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c
|
||||||
|
55
libs/libc/math/lib_cbrt.c
Normal file
55
libs/libc/math/lib_cbrt.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* libs/libc/math/lib_cbrt.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 <sys/types.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_HAVE_DOUBLE
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
double cbrt(double x)
|
||||||
|
{
|
||||||
|
if (fabs(x) < DBL_EPSILON)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x > 0.0)
|
||||||
|
{
|
||||||
|
return pow(x, 1.0 / 3.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -pow(-x, 1.0 / 3.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user