newlib: libm: nexttoward: test the sign bit for the direction
Commit Message
hx > 0 is false for the smallest subnormals, whose high word is 0, so
nexttoward() stepped them away from y: nexttoward(DBL_TRUE_MIN, 0) gave
2 * DBL_TRUE_MIN. x == 0 is handled before, so hx >= 0 means x > 0.
Signed-off-by: Bernie Innocenti <bernie@codewiz.org>
Assisted-By: Claude Opus 5 <noreply@anthropic.com>
---
newlib/libm/ld/s_nexttoward.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -51,7 +51,7 @@ nexttoward(double x, long double y)
t = x*x;
if(t==x) return t; else return x; /* raise underflow flag */
}
- if(hx>0.0 ^ x < y) { /* x -= ulp */
+ if((hx>=0) ^ (x < y)) { /* x -= ulp */
if(lx==0) hx -= 1;
lx -= 1;
} else { /* x += ulp */