1 /* @(#)s_nextafter.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid
[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp $";
19 * return the next machine floating-point number of x in the
24 /* Ugly hack so that the aliasing works. */
25 #define __nexttoward __internal___nexttoward
26 #define nexttoward __internal_nexttoward
29 #include <math_private.h>
32 double __nextafter(double x
, double y
)
37 EXTRACT_WORDS(hx
,lx
,x
);
38 EXTRACT_WORDS(hy
,ly
,y
);
39 ix
= hx
&0x7fffffff; /* |x| */
40 iy
= hy
&0x7fffffff; /* |y| */
42 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
43 ((iy
>=0x7ff00000)&&((iy
-0x7ff00000)|ly
)!=0)) /* y is nan */
45 if(x
==y
) return y
; /* x=y, return y */
46 if((ix
|lx
)==0) { /* x == 0 */
48 INSERT_WORDS(x
,hy
&0x80000000,1); /* return +-minsubnormal */
49 u
= math_opt_barrier (x
);
51 math_force_eval (u
); /* raise underflow flag */
54 if(hx
>=0) { /* x > 0 */
55 if(hx
>hy
||((hx
==hy
)&&(lx
>ly
))) { /* x > y, x -= ulp */
58 } else { /* x < y, x += ulp */
63 if(hy
>=0||hx
>hy
||((hx
==hy
)&&(lx
>ly
))){/* x < y, x -= ulp */
66 } else { /* x > y, x += ulp */
73 double u
= x
+x
; /* overflow */
77 double u
= x
*x
; /* underflow */
78 math_force_eval (u
); /* raise underflow flag */
80 INSERT_WORDS(x
,hx
,lx
);
83 weak_alias (__nextafter
, nextafter
)
85 strong_alias (__nextafter
, __nextafterl
)
86 weak_alias (__nextafter
, nextafterl
)
87 strong_alias (__nextafter
, __nexttowardl
)
88 weak_alias (__nexttowardl
, nexttowardl
)
90 strong_alias (__nextafter
, __nexttoward
)
92 weak_alias (__nextafter
, nexttoward
)