fix compile with DODEBUG=y
[uclibc-ng.git] / libm / s_nextafterf.c
blobe0cb8161300aac78afde6f237781f6bccb322cbc
1 /* s_nextafterf.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
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
12 * is preserved.
13 * ====================================================
16 #include "math.h"
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))
30 return x + y;
32 if (x == y)
33 return y;
35 if (ix == 0) { /* x == 0? */
36 /* glibc 2.4 does not seem to set underflow? */
37 /* float u; */
38 /* return +-minsubnormal */
39 SET_FLOAT_WORD(x, (hy & 0x80000000) | 1);
40 /* u = x * x; raise underflow flag */
41 /* math_force_eval(u); */
42 return x;
45 if (hx >= 0) { /* x > 0 */
46 if (hx > hy) { /* x > y: x -= ulp */
47 hx -= 1;
48 } else { /* x < y: x += ulp */
49 hx += 1;
51 } else { /* x < 0 */
52 if (hy >= 0 || hx > hy) { /* x < y: x -= ulp */
53 hx -= 1;
54 } else { /* x > y: x += ulp */
55 hx += 1;
58 hy = hx & 0x7f800000;
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);
68 return x;
71 #if 0
72 /* "testprog N a b"
73 * calculates a = nextafterf(a, b) and prints a as float
74 * and as raw bytes; repeats it N times.
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <math.h>
79 int main(int argc, char **argv)
81 int cnt, i;
82 float a, b;
83 cnt = atoi(argv[1]);
84 a = strtod(argv[2], NULL);
85 b = strtod(argv[3], NULL);
86 while (cnt-- > 0) {
87 for (i = 0; i < sizeof(a); i++) {
88 unsigned char c = ((char*)(&a))[i];
89 printf("%x%x", (c >> 4), (c & 0xf));
91 printf(" %f\n", a);
92 a = nextafterf(a, b);
94 return 0;
96 #endif