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>
30 #include <math_ldbl_opt.h>
34 double __nexttoward(double x
, long double y
)
36 double __nexttoward(x
,y
)
46 EXTRACT_WORDS(hx
,lx
,x
);
47 GET_LDOUBLE_WORDS64(hy
,ly
,y
);
48 ix
= hx
&0x7fffffff; /* |x| */
49 iy
= hy
&0x7fffffffffffffffLL
; /* |y| */
50 uly
= ly
&0x7fffffffffffffffLL
; /* |y| */
52 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
53 ((iy
>=0x7ff0000000000000LL
)&&((iy
-0x7ff0000000000000LL
)|uly
)!=0))
56 if((long double) x
==y
) return y
; /* x=y, return y */
57 if((ix
|lx
)==0) { /* x == 0 */
59 INSERT_WORDS(x
,(u_int32_t
)((hy
>>32)&0x80000000),1);/* return +-minsub */
60 u
= math_opt_barrier (x
);
62 math_force_eval (u
); /* raise underflow flag */
65 if(hx
>=0) { /* x > 0 */
66 if (hy
<0||(ix
>>20)>(iy
>>52)
67 || ((ix
>>20)==(iy
>>52)
68 && (((((int64_t)hx
)<<32)|(lx
))>(hy
&0x000fffffffffffffLL
)
69 || (((((int64_t)hx
)<<32)|(lx
))==(hy
&0x000fffffffffffffLL
)
70 )))) { /* x > y, x -= ulp */
73 } else { /* x < y, x += ulp */
78 if (hy
>=0||(ix
>>20)>(iy
>>52)
79 || ((ix
>>20)==(iy
>>52)
80 && (((((int64_t)hx
)<<32)|(lx
))>(hy
&0x000fffffffffffffLL
)
81 || (((((int64_t)hx
)<<32)|(lx
))==(hy
&0x000fffffffffffffLL
)
82 )))) { /* x < y, x -= ulp */
85 } else { /* x > y, x += ulp */
92 x
= x
+x
; /* overflow */
93 if (FLT_EVAL_METHOD
!= 0 && FLT_EVAL_METHOD
!= 1)
94 /* Force conversion to double. */
99 double u
= x
*x
; /* underflow */
100 math_force_eval (u
); /* raise underflow flag */
102 INSERT_WORDS(x
,hx
,lx
);
105 long_double_symbol (libm
, __nexttoward
, nexttoward
);