2 * Conversion freom 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"
32 double __nextafterx(double x
, long double y
)
34 double __nextafterx(x
,y
)
40 u_int32_t lx
,hy
,ly
,esy
;
42 EXTRACT_WORDS(hx
,lx
,x
);
43 GET_LDOUBLE_WORDS(esy
,hy
,ly
,y
);
44 ix
= hx
&0x7fffffff; /* |x| */
45 iy
= esy
&0x7fff; /* |y| */
47 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
48 ((iy
>=0x7fff)&&((hy
|ly
)|-(hy
|ly
))!=0)) /* y is nan */
50 if((long double) x
==y
) return x
; /* x=y, return x */
51 if((ix
|lx
)==0) { /* x == 0 */
53 INSERT_WORDS(x
,esy
&0x8000?0x80000000:0,1);/* return +-minsub */
55 if(x2
==x
) return x2
; else return x
; /* raise underflow flag */
57 if(hx
>=0) { /* x > 0 */
58 if (esy
>=0x8000||((ix
>>20)&0x7ff)>iy
59 || (((ix
>>20)&0x7ff)==iy
60 && (((hx
<<11)|(lx
>>21))>(hy
&0x7fffffff)
61 || (((hx
<<11)|(lx
>>21))==(hy
&0x7fffffff)
62 && (lx
<<11)>ly
)))) { /* x > y, x -= ulp */
65 } else { /* x < y, x += ulp */
70 if (esy
<0x8000||((ix
>>20)&0x7ff)>iy
71 || (((ix
>>20)&0x7ff)==iy
72 && (((hx
<<11)|(lx
>>21))>(hy
&0x7fffffff)
73 || (((hx
<<11)|(lx
>>21))==(hy
&0x7fffffff)
74 && (lx
<<11)>ly
)))) {/* x < y, x -= ulp */
77 } else { /* x > y, x += ulp */
83 if(hy
>=0x7ff00000) return x
+x
; /* overflow */
84 if(hy
<0x00100000) { /* underflow */
86 if(x2
!=x
) { /* raise underflow flag */
87 INSERT_WORDS(x2
,hx
,lx
);
91 INSERT_WORDS(x
,hx
,lx
);
94 weak_alias (__nextafterx
, nextafterx
)
96 strong_alias (__nextafterx
, __nextafterxl
)
97 weak_alias (__nextafterx
, nextafterxl
)