From a310b0952f9329ea483e642c6b55c6e52f041fcb Mon Sep 17 00:00:00 2001 From: zouboan Date: Fri, 21 Jan 2022 22:46:34 +0800 Subject: [PATCH] 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 76284fd3a81..e8a6b1feb44 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; }