mirror of
https://github.com/apache/nuttx.git
synced 2026-10-08 23:05:20 +00:00
* Squash round() commits
- Add check in roundx() functions for infinite or NaN cases - Add block to avoid style warnings - Define long double constants and macros for infinity and nan - Correct return syntax to match NuttX style - Make c89 compliant - Fix definitions of INFINITY_L/NAN_L * include/nuttx/lib/math.h - match standard naming conventions - Rename isinf_l to isinfl - Rename isinf_f to isinff - Add finite() - Add finitel() - Add finitef() - Define isnanl and isnanf - Define isfinite() so that it uses the appropriate macro * libs/libc/math/lib_asinf.c libs/libc/math/lib_asinl.c libs/libc/math/lib_roundf.c libs/libc/math/lib_roundl.c libs/libc/math/lib_sqrtf.c libs/libc/math/lib_sqrtl.c - Use renamed macros - Use correct NAN_x or INFINIT_x macro on returns
This commit is contained in:
parent
5e22dcb73b
commit
213b954a90
10 changed files with 54 additions and 21 deletions
|
|
@ -70,7 +70,7 @@ float asinf(float x)
|
|||
|
||||
/* Verify that the input value is in the domain of the function */
|
||||
|
||||
if (x < -1.0F || x > 1.0F || isnan(x))
|
||||
if (x < -1.0F || x > 1.0F || isnanf(x))
|
||||
{
|
||||
return NAN_F;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ long double asinl(long double x)
|
|||
|
||||
/* Verify that the input value is in the domain of the function */
|
||||
|
||||
if (x < -1.0 || x > 1.0 || isnan(x))
|
||||
if (x < -1.0 || x > 1.0 || isnanl(x))
|
||||
{
|
||||
return NAN;
|
||||
return NAN_L;
|
||||
}
|
||||
|
||||
/* if x is > sqrt(2), use identity for faster convergence */
|
||||
|
|
|
|||
|
|
@ -102,12 +102,12 @@ float logf(float x)
|
|||
|
||||
if (y == FLT_MAX_EXP_X)
|
||||
{
|
||||
return INFINITY;
|
||||
return INFINITY_F;
|
||||
}
|
||||
|
||||
if (y == -FLT_MAX_EXP_X)
|
||||
{
|
||||
return INFINITY;
|
||||
return INFINITY_F;
|
||||
}
|
||||
|
||||
return y;
|
||||
|
|
|
|||
|
|
@ -78,12 +78,12 @@ long double logl(long double x)
|
|||
|
||||
if (y == LDBL_MAX_EXP_X)
|
||||
{
|
||||
return INFINITY;
|
||||
return INFINITY_L;
|
||||
}
|
||||
|
||||
if (y == -LDBL_MAX_EXP_X)
|
||||
{
|
||||
return INFINITY;
|
||||
return INFINITY_L;
|
||||
}
|
||||
|
||||
return y;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,14 @@
|
|||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
double round(double x)
|
||||
{
|
||||
double f = modf(x, &x);
|
||||
double f;
|
||||
|
||||
if (isinf(x) || isnan(x))
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
f = modf(x, &x);
|
||||
if (x <= 0.0 && f <= -0.5)
|
||||
{
|
||||
x -= 1.0;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,14 @@
|
|||
|
||||
float roundf(float x)
|
||||
{
|
||||
float f = modff(x, &x);
|
||||
float f;
|
||||
|
||||
if (isinff(x) || isnanf(x))
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
f = modff(x, &x);
|
||||
if (x <= 0.0f && f <= -0.5f)
|
||||
{
|
||||
x -= 1.0f;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,14 @@
|
|||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double roundl(long double x)
|
||||
{
|
||||
long double f = modfl(x, &x);
|
||||
long double f;
|
||||
|
||||
if (isinfl(x) || isnanl(x))
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
f = modfl(x, &x);
|
||||
if (x <= 0.0 && f <= -0.5)
|
||||
{
|
||||
x -= 1.0;
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ float sqrtf(float x)
|
|||
return NAN_F;
|
||||
}
|
||||
|
||||
if (isnan(x))
|
||||
if (isnanf(x))
|
||||
{
|
||||
return NAN_F;
|
||||
}
|
||||
|
||||
if (isinf_f(x))
|
||||
if (isinff(x))
|
||||
{
|
||||
return INFINITY_F;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,17 +52,17 @@ long double sqrtl(long double x)
|
|||
if (x < 0.0)
|
||||
{
|
||||
set_errno(EDOM);
|
||||
return NAN;
|
||||
return NAN_L;
|
||||
}
|
||||
|
||||
if (isnan(x))
|
||||
if (isnanl(x))
|
||||
{
|
||||
return NAN;
|
||||
return NAN_L;
|
||||
}
|
||||
|
||||
if (isinf(x))
|
||||
if (isinfl(x))
|
||||
{
|
||||
return INFINITY;
|
||||
return INFINITY_L;
|
||||
}
|
||||
|
||||
if (x == 0.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue