2 * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support,
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid
[] = "$NetBSD: $";
23 * return the next machine floating-point number of x in the
29 #include <math_private.h>
33 double __nexttoward(double x
, long double y
)
35 double __nexttoward(x
,y
)
41 u_int32_t lx
,hy
,ly
,esy
;
43 EXTRACT_WORDS(hx
,lx
,x
);
44 GET_LDOUBLE_WORDS(esy
,hy
,ly
,y
);
45 ix
= hx
&0x7fffffff; /* |x| */
46 iy
= esy
&0x7fff; /* |y| */
48 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
49 ((iy
>=0x7fff)&&(hy
|ly
)!=0)) /* y is nan */
51 if((long double) x
==y
) return y
; /* x=y, return y */
52 if((ix
|lx
)==0) { /* x == 0 */
54 INSERT_WORDS(x
,(esy
&0x8000)<<16,1); /* return +-minsub */
55 u
= math_opt_barrier (x
);
57 math_force_eval (u
); /* raise underflow flag */
60 if(hx
>=0) { /* x > 0 */
61 if (esy
>=0x8000||((ix
>>20)&0x7ff)>iy
-0x3c00
62 || (((ix
>>20)&0x7ff)==iy
-0x3c00
63 && (((hx
<<11)|(lx
>>21))>(hy
&0x7fffffff)
64 || (((hx
<<11)|(lx
>>21))==(hy
&0x7fffffff)
65 && (lx
<<11)>ly
)))) { /* x > y, x -= ulp */
68 } else { /* x < y, x += ulp */
73 if (esy
<0x8000||((ix
>>20)&0x7ff)>iy
-0x3c00
74 || (((ix
>>20)&0x7ff)==iy
-0x3c00
75 && (((hx
<<11)|(lx
>>21))>(hy
&0x7fffffff)
76 || (((hx
<<11)|(lx
>>21))==(hy
&0x7fffffff)
77 && (lx
<<11)>ly
)))) {/* x < y, x -= ulp */
80 } else { /* x > y, x += ulp */
87 x
= x
+x
; /* overflow */
88 if (FLT_EVAL_METHOD
!= 0 && FLT_EVAL_METHOD
!= 1)
89 /* Force conversion to double. */
94 double u
= x
*x
; /* underflow */
95 math_force_eval (u
); /* raise underflow flag */
97 INSERT_WORDS(x
,hx
,lx
);
100 weak_alias (__nexttoward
, nexttoward
)