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
30 #include <math_private.h>
33 double __nexttoward(double x
, long double y
)
40 EXTRACT_WORDS(hx
,lx
,x
);
41 GET_LDOUBLE_WORDS64(hy
,ly
,y
);
42 ix
= hx
&0x7fffffff; /* |x| */
43 iy
= hy
&0x7fffffffffffffffLL
; /* |y| */
45 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
46 ((iy
>=0x7fff000000000000LL
)&&((iy
-0x7fff000000000000LL
)|ly
)!=0))
49 if((long double) x
==y
) return y
; /* x=y, return y */
50 if((ix
|lx
)==0) { /* x == 0 */
52 INSERT_WORDS(x
,(uint32_t)((hy
>>32)&0x80000000),1);/* return +-minsub */
53 u
= math_opt_barrier (x
);
55 math_force_eval (u
); /* raise underflow flag */
58 if(hx
>=0) { /* x > 0 */
59 if (x
> y
) { /* x -= ulp */
62 } else { /* x < y, x += ulp */
67 if (x
< y
) { /* x -= ulp */
70 } else { /* x > y, x += ulp */
77 double u
= x
+x
; /* overflow */
82 double u
= x
*x
; /* underflow */
83 math_force_eval (u
); /* raise underflow flag */
86 INSERT_WORDS(x
,hx
,lx
);
89 weak_alias (__nexttoward
, nexttoward
)