Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.c-torture / compile / 980506-2.c
blob6f6fe19270c4eb4a12484c8d985267394f95668e
1 /*
2 * inspired by glibc-2.0.6/sysdeps/libm-ieee754/s_nextafterf.c
4 * gcc -O2 -S -DOP=+ gives faddp %st(1),%st
5 * gcc -O2 -S -DOP=* gives fmulp %st(1),%st
6 * gcc -O2 -S -DOP=- gives fsubrp %st(1),%st
7 * gcc -O2 -S -DOP=/ gives fdivrp %st(1),%st
8 */
10 #ifndef OP
11 #define OP *
12 #endif
14 typedef int int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
15 typedef unsigned int u_int32_t __attribute__ ((__mode__ ( __SI__ ))) ;
17 typedef union
19 float value;
20 u_int32_t word;
21 } ieee_float_shape_type;
23 float __nextafterf(float x, float y)
25 int32_t hx,hy,ix,iy;
28 ieee_float_shape_type gf_u;
29 gf_u.value = x;
30 hx = gf_u.word;
33 ieee_float_shape_type gf_u;
34 gf_u.value = y;
35 hy = gf_u.word;
37 ix = hx&0x7fffffff;
38 iy = hy&0x7fffffff;
40 if ( ix > 0x7f800000 || iy > 0x7f800000 )
41 return x+y;
42 if (x == y) return x;
43 if (ix == 0)
46 ieee_float_shape_type sf_u;
47 sf_u.word = (hy&0x80000000) | 1;
48 x = sf_u.value;
50 y = x*x;
51 if (y == x) return y; else return x;
53 if (hx >= 0)
55 if (hx > hy)
56 hx -= 1;
57 else
58 hx += 1;
60 else
62 if (hy >= 0 || hx > hy)
63 hx -= 1;
64 else
65 hx += 1;
67 hy = hx & 0x7f800000;
68 if (hy >= 0x7f800000)
69 return x+x;
70 if (hy < 0x00800000)
72 y = x OP x;
73 if (y != x)
75 ieee_float_shape_type sf_u;
76 sf_u.word = hx;
77 y = sf_u.value;
78 return y;
82 ieee_float_shape_type sf_u;
83 sf_u.word = hx;
84 x = sf_u.value;
86 return x;