4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-01 03:50:28 +08:00

libm/common: Fix nextafter and nextafterf when x == y

That according to C99/POSIX, nextafter(x,y) should return y if x==y.

[1] NetBSD fix for this: 3bc6852241
[2] glibc fix for this: bc9f6000f6 (diff-bcc0628a39c3c2003047dcb5a40a8b50c00f01a74b1c8c1100d770a8e48b1ce2)
[3] Linux man page: https://man7.org/linux/man-pages/man3/nextafter.3.html

(cherry picked from commit 7ccfe49e8ce908c581f82c8dbf0f9064df488a24)
This commit is contained in:
Kito Cheng 2024-12-05 16:39:56 +08:00 committed by Corinna Vinschen
parent bb854e0f11
commit bbf8484a5b
2 changed files with 2 additions and 2 deletions

View File

@ -70,7 +70,7 @@ PORTABILITY
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
return x+y;
if(x==y) return x; /* x=y, return x */
if(x==y) return y; /* x=y, return y */
if((ix|lx)==0) { /* x == 0 */
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
y = x*x;

View File

@ -32,7 +32,7 @@
if(FLT_UWORD_IS_NAN(ix) ||
FLT_UWORD_IS_NAN(iy))
return x+y;
if(x==y) return x; /* x=y, return x */
if(x==y) return y; /* x=y, return y */
if(FLT_UWORD_IS_ZERO(ix)) { /* x == 0 */
SET_FLOAT_WORD(x,(hy&0x80000000)|FLT_UWORD_MIN);
y = x*x;