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
30 #include <math-barriers.h>
31 #include <math_private.h>
34 double __nexttoward(double x
, long double y
)
37 uint32_t lx
,hy
,ly
,esy
;
39 EXTRACT_WORDS(hx
,lx
,x
);
40 GET_LDOUBLE_WORDS(esy
,hy
,ly
,y
);
41 ix
= hx
&0x7fffffff; /* |x| */
42 iy
= esy
&0x7fff; /* |y| */
44 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
45 ((iy
>=0x7fff)&&(hy
|ly
)!=0)) /* y is nan */
47 if((long double) x
==y
) return y
; /* x=y, return y */
48 if((ix
|lx
)==0) { /* x == 0 */
50 INSERT_WORDS(x
,(esy
&0x8000)<<16,1); /* return +-minsub */
51 u
= math_opt_barrier (x
);
53 math_force_eval (u
); /* raise underflow flag */
56 if(hx
>=0) { /* x > 0 */
57 if (x
> y
) { /* x -= ulp */
60 } else { /* x < y, x += ulp */
65 if (x
< y
) { /* x -= ulp */
68 } else { /* x > y, x += ulp */
75 double u
= x
+x
; /* overflow */
80 double u
= x
*x
; /* underflow */
81 math_force_eval (u
); /* raise underflow flag */
84 INSERT_WORDS(x
,hx
,lx
);
87 weak_alias (__nexttoward
, nexttoward
)