mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
libc/math: Fix wrong ouput in ceil() API
Ex:for input x = 1.0, the ouput should be 1.0, but the ouput was 2.0. Signed-off-by: Lokesh B V <lokeshbv333@gmail.com>
This commit is contained in:
@@ -41,8 +41,10 @@
|
|||||||
#ifdef CONFIG_HAVE_DOUBLE
|
#ifdef CONFIG_HAVE_DOUBLE
|
||||||
double ceil(double x)
|
double ceil(double x)
|
||||||
{
|
{
|
||||||
|
double x1 = x;
|
||||||
|
|
||||||
modf(x, &x);
|
modf(x, &x);
|
||||||
if (x > 0.0)
|
if (x1 > 0.0 && fabs(x1 - x) > 0.0)
|
||||||
{
|
{
|
||||||
x += 1.0;
|
x += 1.0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,10 @@
|
|||||||
|
|
||||||
float ceilf(float x)
|
float ceilf(float x)
|
||||||
{
|
{
|
||||||
|
float x1 = x;
|
||||||
|
|
||||||
modff(x, &x);
|
modff(x, &x);
|
||||||
if (x > 0.0F)
|
if (x1 > 0.0F && fabsf(x1 - x) > 0.0F)
|
||||||
{
|
{
|
||||||
x += 1.0F;
|
x += 1.0F;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,10 @@
|
|||||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||||
long double ceill(long double x)
|
long double ceill(long double x)
|
||||||
{
|
{
|
||||||
|
long double x1 = x;
|
||||||
|
|
||||||
modfl(x, &x);
|
modfl(x, &x);
|
||||||
if (x > 0.0)
|
if (x1 > 0.0 && fabsl(x1 - x) > 0.0)
|
||||||
{
|
{
|
||||||
x += 1.0;
|
x += 1.0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user