3 * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support,
8 * ====================================================
9 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11 * Developed at SunPro, a Sun Microsystems, Inc. business.
12 * Permission to use, copy, modify, and distribute this
13 * software is freely granted, provided that this notice
15 * ====================================================
18 #if defined(LIBM_SCCS) && !defined(lint)
19 static char rcsid
[] = "$NetBSD: $";
24 * return the next machine floating-point number of x in the
31 #include <math-barriers.h>
32 #include <math_private.h>
35 double __nexttoward(double x
, long double y
)
38 uint32_t lx
,hy
,ly
,esy
;
40 EXTRACT_WORDS(hx
,lx
,x
);
41 GET_LDOUBLE_WORDS(esy
,hy
,ly
,y
);
42 ix
= hx
&0x7fffffff; /* |x| */
43 iy
= esy
&0x7fff; /* |y| */
45 /* Intel's extended format has the normally implicit 1 explicit
47 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
48 ((iy
>=0x7fff)&&((hy
&0x7fffffff)|ly
)!=0)) /* y is nan */
50 if((long double) x
==y
) return y
; /* x=y, return y */
51 if((ix
|lx
)==0) { /* x == 0 */
53 INSERT_WORDS(x
,(esy
&0x8000)<<16,1); /* return +-minsub */
54 u
= math_opt_barrier (x
);
56 math_force_eval (u
); /* raise underflow flag */
59 if(hx
>=0) { /* x > 0 */
60 if (x
> y
) { /* x -= ulp */
63 } else { /* x < y, x += ulp */
68 if (x
< y
) { /* x -= ulp */
71 } else { /* x > y, x += ulp */
78 double u
= x
+x
; /* overflow */
83 double u
= x
*x
; /* underflow */
84 math_force_eval (u
); /* raise underflow flag */
87 INSERT_WORDS(x
,hx
,lx
);
90 weak_alias (__nexttoward
, nexttoward
)
92 strong_alias (__nexttoward
, __nexttowardl
)
93 weak_alias (__nexttoward
, nexttowardl
)