libm: Fixes scalbnf rounding up to minimum magnitude.

Message ID 20260311235602.12655-1-bavier@posteo.net
State New
Headers
Series libm: Fixes scalbnf rounding up to minimum magnitude. |

Commit Message

Eric Bavier March 11, 2026, 11:59 p.m. UTC
  Previously, results that should have rounded up to the minimum
magnitude floating-point value would instead return zero, in
round-to-nearest-even mode.  E.g. scalbnf(0x1.000002p0,-150) with
subnormal support of scalbnf(0x1.000002p0,-127) without.

* newlib/libm/common/fdlibm.h (FLT_SMALLEST_EXP): Adjust down by one.
Adjust documentation.
---
 newlib/libm/common/fdlibm.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Corinna Vinschen March 17, 2026, 3:46 p.m. UTC | #1
On Mar 11 23:59, Eric Bavier wrote:
> Previously, results that should have rounded up to the minimum
> magnitude floating-point value would instead return zero, in
> round-to-nearest-even mode.  E.g. scalbnf(0x1.000002p0,-150) with
> subnormal support of scalbnf(0x1.000002p0,-127) without.
> 
> * newlib/libm/common/fdlibm.h (FLT_SMALLEST_EXP): Adjust down by one.
> Adjust documentation.
> ---
>  newlib/libm/common/fdlibm.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Pushed.

Thanks,
Corinna
  

Patch

diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
index 7a49e29e0..595a5206d 100644
--- a/newlib/libm/common/fdlibm.h
+++ b/newlib/libm/common/fdlibm.h
@@ -101,8 +101,8 @@ 
 	The bitmask of |log(REAL_FLT_MIN)|, rounding down.
 
    FLT_SMALLEST_EXP
-	REAL_FLT_MIN's exponent - EXP_BIAS (1 if denormals are not supported,
-	-22 if they are).
+	REAL_FLT_MIN's exponent + EXP_BIAS - 1 (0 if denormals are not
+	supported, -23 if they are).
 */
 
 #ifdef _FLT_NO_DENORMALS
@@ -111,14 +111,14 @@ 
 #define FLT_UWORD_MIN 0x00800000
 #define FLT_UWORD_EXP_MIN 0x42fc0000
 #define FLT_UWORD_LOG_MIN 0x42aeac50
-#define FLT_SMALLEST_EXP 1
+#define FLT_SMALLEST_EXP 0
 #else
 #define FLT_UWORD_IS_ZERO(x) ((x)==0)
 #define FLT_UWORD_IS_SUBNORMAL(x) ((x)<0x00800000L)
 #define FLT_UWORD_MIN 0x00000001
 #define FLT_UWORD_EXP_MIN 0x43160000
 #define FLT_UWORD_LOG_MIN 0x42cff1b5
-#define FLT_SMALLEST_EXP -22
+#define FLT_SMALLEST_EXP -23
 #endif
 
 #ifdef __STDC__