| 1 |
/* Check that certain subnormal numbers (formerly known as denormalized |
| 2 |
numbers) are rounded to within 0.5 ulp. PR other/14354. */ |
| 3 |
|
| 4 |
/* This test requires that float and unsigned int are the same size and |
| 5 |
that the sign-bit of the float is at MSB of the unsigned int. */ |
| 6 |
|
| 7 |
void abort (void); |
| 8 |
void exit (int); |
| 9 |
|
| 10 |
#if __INT_MAX__ != 2147483647L |
| 11 |
int main () { exit (0); } |
| 12 |
#else |
| 13 |
|
| 14 |
union uf |
| 15 |
{ |
| 16 |
unsigned int u; |
| 17 |
float f; |
| 18 |
}; |
| 19 |
|
| 20 |
static float |
| 21 |
u2f (unsigned int v) |
| 22 |
{ |
| 23 |
union uf u; |
| 24 |
u.u = v; |
| 25 |
return u.f; |
| 26 |
} |
| 27 |
|
| 28 |
static unsigned int |
| 29 |
f2u (float v) |
| 30 |
{ |
| 31 |
union uf u; |
| 32 |
u.f = v; |
| 33 |
return u.u; |
| 34 |
} |
| 35 |
|
| 36 |
int ok = 1; |
| 37 |
|
| 38 |
static void |
| 39 |
tstmul (unsigned int ux, unsigned int uy, unsigned int ur) |
| 40 |
{ |
| 41 |
float x = u2f (ux); |
| 42 |
float y = u2f (uy); |
| 43 |
|
| 44 |
if (f2u (x * y) != ur) |
| 45 |
/* Set a variable rather than aborting here, to simplify tracing when |
| 46 |
several computations are wrong. */ |
| 47 |
ok = 0; |
| 48 |
} |
| 49 |
|
| 50 |
/* We don't want to make this const and static, or else we risk inlining |
| 51 |
causing the test to fold as constants at compile-time. */ |
| 52 |
struct |
| 53 |
{ |
| 54 |
unsigned int p1, p2, res; |
| 55 |
} expected[] = |
| 56 |
{ |
| 57 |
{0xfff, 0x3f800400, 0xfff}, |
| 58 |
{0xf, 0x3fc88888, 0x17}, |
| 59 |
{0xf, 0x3f844444, 0xf} |
| 60 |
}; |
| 61 |
|
| 62 |
int |
| 63 |
main () |
| 64 |
{ |
| 65 |
unsigned int i; |
| 66 |
|
| 67 |
for (i = 0; i < sizeof (expected) / sizeof (expected[0]); i++) |
| 68 |
{ |
| 69 |
tstmul (expected[i].p1, expected[i].p2, expected[i].res); |
| 70 |
tstmul (expected[i].p2, expected[i].p1, expected[i].res); |
| 71 |
} |
| 72 |
|
| 73 |
if (!ok) |
| 74 |
abort (); |
| 75 |
|
| 76 |
exit (0); |
| 77 |
} |
| 78 |
#endif |