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 #include <sys/cdefs.h>
14 #if defined(LIBM_SCCS) && !defined(lint)
15 __RCSID("$NetBSD: s_nextafter.c,v 1.14 2014/03/18 18:20:37 riastradh Exp $");
20 * return the next machine floating-point number of x in the
26 #include "math_private.h"
28 #ifndef __HAVE_LONG_DOUBLE
29 __strong_alias(nextafterl
, nextafter
)
33 nextafter(double x
, double y
)
38 EXTRACT_WORDS(hx
,lx
,x
);
39 EXTRACT_WORDS(hy
,ly
,y
);
40 ix
= hx
&0x7fffffff; /* |x| */
41 iy
= hy
&0x7fffffff; /* |y| */
43 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=0) || /* x is nan */
44 ((iy
>=0x7ff00000)&&((iy
-0x7ff00000)|ly
)!=0)) /* y is nan */
46 if(x
==y
) return y
; /* x=y, return y */
47 if((ix
|lx
)==0) { /* x == 0 */
48 INSERT_WORDS(x
,hy
&0x80000000,1); /* return +-minsubnormal */
50 if(y
==x
) return y
; else return x
; /* raise underflow flag */
52 if(hx
>=0) { /* x > 0 */
53 if(hx
>hy
||((hx
==hy
)&&(lx
>ly
))) { /* x > y, x -= ulp */
56 } else { /* x < y, x += ulp */
61 if(hy
>=0||hx
>hy
||((hx
==hy
)&&(lx
>ly
))){/* x < y, x -= ulp */
64 } else { /* x > y, x += ulp */
70 if(hy
>=0x7ff00000) return x
+x
; /* overflow */
71 if(hy
<0x00100000) { /* underflow */
73 if(y
!=x
) { /* raise underflow flag */
74 INSERT_WORDS(y
,hx
,lx
);
78 INSERT_WORDS(x
,hx
,lx
);