You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/12/31 12:51:31 UTC
[incubator-nuttx] branch master updated: libc/math: fix fmod family operation
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8462b14 libc/math: fix fmod family operation
8462b14 is described below
commit 8462b14d4e8dc9b164d9f14e35a8a3f64c516a09
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Thu Dec 30 21:21:45 2021 +0200
libc/math: fix fmod family operation
Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
libs/libc/math/lib_fmod.c | 6 ++----
libs/libc/math/lib_fmodf.c | 6 ++----
libs/libc/math/lib_fmodl.c | 6 ++----
libs/libc/math/lib_modf.c | 4 ++--
libs/libc/math/lib_modff.c | 2 +-
libs/libc/math/lib_modfl.c | 4 ++--
6 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/libs/libc/math/lib_fmod.c b/libs/libc/math/lib_fmod.c
index c321086..7f6a789 100644
--- a/libs/libc/math/lib_fmod.c
+++ b/libs/libc/math/lib_fmod.c
@@ -43,10 +43,8 @@ double fmod(double x, double div)
{
double n0;
- x /= div;
- x = modf(x, &n0);
- x *= div;
+ modf(x / div, &n0);
- return x;
+ return x - n0 * div;
}
#endif
diff --git a/libs/libc/math/lib_fmodf.c b/libs/libc/math/lib_fmodf.c
index 9db3376..b907af9 100644
--- a/libs/libc/math/lib_fmodf.c
+++ b/libs/libc/math/lib_fmodf.c
@@ -39,9 +39,7 @@ float fmodf(float x, float div)
{
float n0;
- x /= div;
- x = modff(x, &n0);
- x *= div;
+ modff(x / div, &n0);
- return x;
+ return x - n0 * div;
}
diff --git a/libs/libc/math/lib_fmodl.c b/libs/libc/math/lib_fmodl.c
index eb2b663..593ba03 100644
--- a/libs/libc/math/lib_fmodl.c
+++ b/libs/libc/math/lib_fmodl.c
@@ -43,10 +43,8 @@ long double fmodl(long double x, long double div)
{
long double n0;
- x /= div;
- x = modfl(x, &n0);
- x *= div;
+ modfl(x / div, &n0);
- return x;
+ return x - n0 * div;
}
#endif
diff --git a/libs/libc/math/lib_modf.c b/libs/libc/math/lib_modf.c
index bbd45a1..e1ac235 100644
--- a/libs/libc/math/lib_modf.c
+++ b/libs/libc/math/lib_modf.c
@@ -46,12 +46,12 @@ double modf(double x, double *iptr)
}
else if (fabs(x) < 1.0)
{
- *iptr = (x * 0.0);
+ *iptr = 0.0;
return x;
}
else
{
- *iptr = (double)(int64_t) x;
+ *iptr = (double)(int64_t)x;
return (x - *iptr);
}
}
diff --git a/libs/libc/math/lib_modff.c b/libs/libc/math/lib_modff.c
index 8757c3a..7c06850 100644
--- a/libs/libc/math/lib_modff.c
+++ b/libs/libc/math/lib_modff.c
@@ -44,7 +44,7 @@ float modff(float x, float *iptr)
}
else if (fabsf(x) < 1.0F)
{
- *iptr = (x * 0.0F);
+ *iptr = 0.0F;
return x;
}
else
diff --git a/libs/libc/math/lib_modfl.c b/libs/libc/math/lib_modfl.c
index b28f2aa..49fd4f1 100644
--- a/libs/libc/math/lib_modfl.c
+++ b/libs/libc/math/lib_modfl.c
@@ -49,12 +49,12 @@ long double modfl(long double x, long double *iptr)
}
else if (fabsl(x) < 1.0)
{
- *iptr = (x * 0.0);
+ *iptr = 0.0;
return x;
}
else
{
- *iptr = (long double)(int64_t) x;
+ *iptr = (long double)(int64_t)x;
return (x - *iptr);
}
}