2 * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support,
3 * drepper@cygnus.com and Jakub Jelinek, jj@ultra.linux.cz.
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
)
45 EXTRACT_WORDS(hx
,lx
,x
);
46 GET_LDOUBLE_WORDS64(hy
,ly
,y
);
47 ix
= hx
&0x7fffffff; /* |x| */
48 iy
= hy
&0x7fffffffffffffffLL
; /* |y| */
50 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
51 ((iy
>=0x7fff000000000000LL
)&&((iy
-0x7fff000000000000LL
)|ly
)!=0))
54 if((long double) x
==y
) return y
; /* x=y, return y */
55 if((ix
|lx
)==0) { /* x == 0 */
57 INSERT_WORDS(x
,(u_int32_t
)((hy
>>32)&0x80000000),1);/* return +-minsub */
59 if(x2
==x
) return x2
; else return x
; /* raise underflow flag */
61 if(hx
>=0) { /* x > 0 */
62 if (hy
<0||(ix
>>20)>(iy
>>48)-0x3c00
63 || ((ix
>>20)==(iy
>>48)-0x3c00
64 && (((((int64_t)hx
)<<28)|(lx
>>4))>(hy
&0x0000ffffffffffffLL
)
65 || (((((int64_t)hx
)<<28)|(lx
>>4))==(hy
&0x0000ffffffffffffLL
)
66 && (lx
&0xf)>(ly
>>60))))) { /* x > y, x -= ulp */
69 } else { /* x < y, x += ulp */
74 if (hy
>=0||(ix
>>20)>(iy
>>48)-0x3c00
75 || ((ix
>>20)==(iy
>>48)-0x3c00
76 && (((((int64_t)hx
)<<28)|(lx
>>4))>(hy
&0x0000ffffffffffffLL
)
77 || (((((int64_t)hx
)<<28)|(lx
>>4))==(hy
&0x0000ffffffffffffLL
)
78 && (lx
&0xf)>(ly
>>60))))) { /* x < y, x -= ulp */
81 } else { /* x > y, x += ulp */
88 x
= x
+x
; /* overflow */
89 if (FLT_EVAL_METHOD
!= 0 && FLT_EVAL_METHOD
!= 1)
90 /* Force conversion to float. */
91 asm ("" : "=m"(x
) : "m"(x
));
94 if(hy
<0x00100000) { /* underflow */
96 if(x2
!=x
) { /* raise underflow flag */
97 INSERT_WORDS(x2
,hx
,lx
);
101 INSERT_WORDS(x
,hx
,lx
);
104 weak_alias (__nexttoward
, nexttoward
)