You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2022/01/21 16:37:42 UTC
[incubator-nuttx] branch master updated: bug patch for frexpf function
This is an automated email from the ASF dual-hosted git repository.
acassis 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 a310b09 bug patch for frexpf function
a310b09 is described below
commit a310b0952f9329ea483e642c6b55c6e52f041fcb
Author: zouboan <ff...@feedforward.com.cn>
AuthorDate: Fri Jan 21 22:46:34 2022 +0800
bug patch for frexpf function
---
libs/libc/math/lib_frexpf.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/libs/libc/math/lib_frexpf.c b/libs/libc/math/lib_frexpf.c
index 76284fd..e8a6b1f 100644
--- a/libs/libc/math/lib_frexpf.c
+++ b/libs/libc/math/lib_frexpf.c
@@ -37,6 +37,21 @@
float frexpf(float x, int *exponent)
{
- *exponent = (int)ceilf(log2f(x));
- return x / ldexpf(1.0F, *exponent);
+ float res;
+
+ *exponent = (int)ceilf(log2f(fabsf(x)));
+ res = x / ldexpf(1.0F, *exponent);
+ if (res >= 1.0)
+ {
+ res -= 0.5;
+ *exponent += 1;
+ }
+
+ if (res <= -1.0)
+ {
+ res += 0.5;
+ *exponent += 1;
+ }
+
+ return res;
}