git: 26321b7ee340 - releng/15.2 - msun: fix behaviour of nextafter*() and nexttoward*() for MAX value
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 07 Nov 2026 02:29:23 UTC
The branch releng/15.2 has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=26321b7ee3409dee08b704cac9e989353288496a
commit 26321b7ee3409dee08b704cac9e989353288496a
Author: Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2026-10-31 10:18:06 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-07 02:28:57 +0000
msun: fix behaviour of nextafter*() and nexttoward*() for MAX value
For an edge case at an extreme, e.g., nextafter(-DBL_MAX,-INFINITY)
do not return x+x. Instead, evaluate x+x and assign it to a volatile
to raise an exception, and then fall through to return the correct
result in current rounding mode.
Approved by: re (cperciva)
PR: 299389
MFC after: 6 days (for inclusion into releng/15.2)
(cherry picked from commit 1fb5d8265bc4bbbf1f5bc79cc1d2a7f280b446b2)
(cherry picked from commit 42f926513b74cbac09d4d63a9daf8cb489078671)
---
lib/msun/src/s_nextafter.c | 2 +-
lib/msun/src/s_nextafterf.c | 2 +-
lib/msun/src/s_nextafterl.c | 2 +-
lib/msun/src/s_nexttoward.c | 2 +-
lib/msun/src/s_nexttowardf.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/msun/src/s_nextafter.c b/lib/msun/src/s_nextafter.c
index 1b394e5109c2..350c94e982fc 100644
--- a/lib/msun/src/s_nextafter.c
+++ b/lib/msun/src/s_nextafter.c
@@ -60,7 +60,7 @@ nextafter(double x, double y)
}
}
hy = hx&0x7ff00000;
- if(hy>=0x7ff00000) return x+x; /* overflow */
+ if(hy>=0x7ff00000) t = x+x; /* overflow */
if(hy<0x00100000) { /* underflow */
t = x*x;
if(t!=x) { /* raise underflow flag */
diff --git a/lib/msun/src/s_nextafterf.c b/lib/msun/src/s_nextafterf.c
index 418b126a27ab..379d00f5f390 100644
--- a/lib/msun/src/s_nextafterf.c
+++ b/lib/msun/src/s_nextafterf.c
@@ -50,7 +50,7 @@ nextafterf(float x, float y)
}
}
hy = hx&0x7f800000;
- if(hy>=0x7f800000) return x+x; /* overflow */
+ if(hy>=0x7f800000) t = x+x; /* overflow */
if(hy<0x00800000) { /* underflow */
t = x*x;
if(t!=x) { /* raise underflow flag */
diff --git a/lib/msun/src/s_nextafterl.c b/lib/msun/src/s_nextafterl.c
index fe5a010e89f5..a6f5ce0a3e7b 100644
--- a/lib/msun/src/s_nextafterl.c
+++ b/lib/msun/src/s_nextafterl.c
@@ -63,7 +63,7 @@ nextafterl(long double x, long double y)
ux.bits.exp += 1;
}
}
- if(ux.bits.exp==0x7fff) return x+x; /* overflow */
+ if(ux.bits.exp==0x7fff) t = x+x; /* overflow */
if(ux.bits.exp==0) { /* underflow */
mask_nbit_l(ux);
t = ux.e * ux.e;
diff --git a/lib/msun/src/s_nexttoward.c b/lib/msun/src/s_nexttoward.c
index 5482dc21606d..1cb502669011 100644
--- a/lib/msun/src/s_nexttoward.c
+++ b/lib/msun/src/s_nexttoward.c
@@ -55,7 +55,7 @@ nexttoward(double x, long double y)
if(lx==0) hx += 1;
}
ix = hx&0x7ff00000;
- if(ix>=0x7ff00000) return x+x; /* overflow */
+ if(ix>=0x7ff00000) t = x+x; /* overflow */
if(ix<0x00100000) { /* underflow */
t = x*x;
if(t!=x) { /* raise underflow flag */
diff --git a/lib/msun/src/s_nexttowardf.c b/lib/msun/src/s_nexttowardf.c
index 05c89f4554ec..50325be8c184 100644
--- a/lib/msun/src/s_nexttowardf.c
+++ b/lib/msun/src/s_nexttowardf.c
@@ -43,7 +43,7 @@ nexttowardf(float x, long double y)
else /* x += ulp */
hx += 1;
ix = hx&0x7f800000;
- if(ix>=0x7f800000) return x+x; /* overflow */
+ if(ix>=0x7f800000)t = x+x; /* overflow */
if(ix<0x00800000) { /* underflow */
t = x*x;
if(t!=x) { /* raise underflow flag */