1 /* s_nextafterf.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
17 #include "math_private.h"
19 float nextafterf(float x
, float y
)
21 int32_t hx
, hy
, ix
, iy
;
23 GET_FLOAT_WORD(hx
, x
);
24 GET_FLOAT_WORD(hy
, y
);
25 ix
= hx
& 0x7fffffff; /* |x| */
26 iy
= hy
& 0x7fffffff; /* |y| */
28 /* x is nan or y is nan? */
29 if ((ix
> 0x7f800000) || (iy
> 0x7f800000))
35 if (ix
== 0) { /* x == 0? */
36 /* glibc 2.4 does not seem to set underflow? */
38 /* return +-minsubnormal */
39 SET_FLOAT_WORD(x
, (hy
& 0x80000000) | 1);
40 /* u = x * x; raise underflow flag */
41 /* math_force_eval(u); */
45 if (hx
>= 0) { /* x > 0 */
46 if (hx
> hy
) { /* x > y: x -= ulp */
48 } else { /* x < y: x += ulp */
52 if (hy
>= 0 || hx
> hy
) { /* x < y: x -= ulp */
54 } else { /* x > y: x += ulp */
59 if (hy
>= 0x7f800000) {
60 x
= x
+ x
; /* overflow */
61 return x
; /* overflow */
63 if (hy
< 0x00800000) {
64 float u
= x
* x
; /* underflow */
65 math_force_eval(u
); /* raise underflow flag */
67 SET_FLOAT_WORD(x
, hx
);
73 * calculates a = nextafterf(a, b) and prints a as float
74 * and as raw bytes; repeats it N times.
79 int main(int argc
, char **argv
)
84 a
= strtod(argv
[2], NULL
);
85 b
= strtod(argv
[3], NULL
);
87 for (i
= 0; i
< sizeof(a
); i
++) {
88 unsigned char c
= ((char*)(&a
))[i
];
89 printf("%x%x", (c
>> 4), (c
& 0xf));