2 /* @(#)s_nextafter.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 <<nextafter>>, <<nextafterf>>---get next number
25 double nextafter(double <[val]>, double <[dir]>);
26 float nextafterf(float <[val]>, float <[dir]>);
29 <<nextafter>> returns the double-precision floating-point number
30 closest to <[val]> in the direction toward <[dir]>. <<nextafterf>>
31 performs the same operation in single precision. For example,
32 <<nextafter(0.0,1.0)>> returns the smallest positive number which is
33 representable in double precision.
36 Returns the next closest number to <[val]> in the direction toward
40 Neither <<nextafter>> nor <<nextafterf>> is required by ANSI C
41 or by the System V Interface Definition (Issue 2).
46 * return the next machine floating-point number of x in the
53 #ifndef _DOUBLE_IS_32BITS
56 double nextafter(double x
, double y
)
62 __int32_t hx
,hy
,ix
,iy
;
65 EXTRACT_WORDS(hx
,lx
,x
);
66 EXTRACT_WORDS(hy
,ly
,y
);
67 ix
= hx
&0x7fffffff; /* |x| */
68 iy
= hy
&0x7fffffff; /* |y| */
70 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
71 ((iy
>=0x7ff00000)&&((iy
-0x7ff00000)|ly
)!=0)) /* y is nan */
73 if(x
==y
) return y
; /* x=y, return y */
74 if((ix
|lx
)==0) { /* x == 0 */
75 INSERT_WORDS(x
,hy
&0x80000000,1); /* return +-minsubnormal */
77 if(y
==x
) return y
; else return x
; /* raise underflow flag */
79 if(hx
>=0) { /* x > 0 */
80 if(hx
>hy
||((hx
==hy
)&&(lx
>ly
))) { /* x > y, x -= ulp */
83 } else { /* x < y, x += ulp */
88 if(hy
>=0||hx
>hy
||((hx
==hy
)&&(lx
>ly
))){/* x < y, x -= ulp */
91 } else { /* x > y, x += ulp */
97 if(hy
>=0x7ff00000) return x
+x
; /* overflow */
98 if(hy
<0x00100000) { /* underflow */
100 if(y
!=x
) { /* raise underflow flag */
101 INSERT_WORDS(y
,hx
,lx
);
105 INSERT_WORDS(x
,hx
,lx
);
109 #endif /* _DOUBLE_IS_32BITS */