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 * ====================================================
14 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.11 2005/03/07 21:27:37 das Exp $";
19 * return the next machine floating-point number of x in the
24 #include <aros/system.h>
28 #include "math_private.h"
31 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 */
47 INSERT_WORDS(x
,hy
&0x80000000,1); /* return +-minsubnormal */
49 if(t
==x
) return t
; else return x
; /* raise underflow flag */
51 if(hx
>=0) { /* x > 0 */
52 if(hx
>hy
||((hx
==hy
)&&(lx
>ly
))) { /* x > y, x -= ulp */
55 } else { /* x < y, x += ulp */
60 if(hy
>=0||hx
>hy
||((hx
==hy
)&&(lx
>ly
))){/* x < y, x -= ulp */
63 } else { /* x > y, x += ulp */
69 if(hy
>=0x7ff00000) return x
+x
; /* overflow */
70 if(hy
<0x00100000) { /* underflow */
72 if(t
!=x
) { /* raise underflow flag */
73 INSERT_WORDS(y
,hx
,lx
);
77 INSERT_WORDS(x
,hx
,lx
);
81 #if (LDBL_MANT_DIG == 53)
82 /* Alias nextafter -> nexttoward */
83 AROS_MAKE_ASM_SYM(typeof(nexttoward
), nexttoward
, AROS_CSYM_FROM_ASM_NAME(nexttoward
), AROS_CSYM_FROM_ASM_NAME(nextafter
));
84 AROS_EXPORT_ASM_SYM(AROS_CSYM_FROM_ASM_NAME(nexttoward
));
86 /* Alias nextafter -> nexttowardl */
87 AROS_MAKE_ASM_SYM(typeof(nexttowardl
), nexttowardl
, AROS_CSYM_FROM_ASM_NAME(nexttowardl
), AROS_CSYM_FROM_ASM_NAME(nextafter
));
88 AROS_EXPORT_ASM_SYM(AROS_CSYM_FROM_ASM_NAME(nexttowardl
));
90 /* Alias nextafter -> nextafterl */
91 AROS_MAKE_ASM_SYM(typeof(nextafterl
), nextafterl
, AROS_CSYM_FROM_ASM_NAME(nextafterl
), AROS_CSYM_FROM_ASM_NAME(nextafter
));
92 AROS_EXPORT_ASM_SYM(AROS_CSYM_FROM_ASM_NAME(nextafterl
));