git: 1fb5d8265bc4 - main - msun: fix behaviour of nextafter*() and nexttoward*() for MAX value
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 31 Oct 2026 12:16:58 UTC
The branch main has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=1fb5d8265bc4bbbf1f5bc79cc1d2a7f280b446b2
commit 1fb5d8265bc4bbbf1f5bc79cc1d2a7f280b446b2
Author: Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2026-10-31 10:18:06 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2026-10-31 10:19:54 +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.
PR: 299389
MFC after: 6 days (for inclusion into releng/15.2)
---
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 8ac5b9550946..33efb15ae355 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 e8527e989190..5b177fac8188 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 65717aa461a8..1f0ce71ea2ad 100644
--- a/lib/msun/src/s_nextafterl.c
+++ b/lib/msun/src/s_nextafterl.c
@@ -61,7 +61,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 d8e04b107e25..ef3623d2e2cf 100644
--- a/lib/msun/src/s_nexttoward.c
+++ b/lib/msun/src/s_nexttoward.c
@@ -54,7 +54,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 53ca3b9806af..2682c81e2b04 100644
--- a/lib/msun/src/s_nexttowardf.c
+++ b/lib/msun/src/s_nexttowardf.c
@@ -42,7 +42,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 */