If x == y, return y, not x. C99 (though not IEEE 754) requires that

nextafter(+0.0, -0.0) returns -0.0 and nextafter(-0.0, +0.0) returns +0.0.
This commit is contained in:
David Schultz 2005-01-23 15:46:22 +00:00
parent b8a3e40819
commit 3c4d0a0973
2 changed files with 2 additions and 2 deletions

View File

@ -38,7 +38,7 @@ nextafter(double x, double y)
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 x */
if((ix|lx)==0) { /* x == 0 */
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
y = x*x;

View File

@ -33,7 +33,7 @@ nextafterf(float x, float y)
if((ix>0x7f800000) || /* x is nan */
(iy>0x7f800000)) /* y is nan */
return x+y;
if(x==y) return x; /* x=y, return x */
if(x==y) return y; /* x=y, return x */
if(ix==0) { /* x == 0 */
SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
y = x*x;