| 1 |
#include <string.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <float.h> |
| 4 |
|
| 5 |
#define fpsizeoff sizeof(float) |
| 6 |
#define fpsizeof sizeof(double) |
| 7 |
#define fpsizeofl sizeof(long double) |
| 8 |
|
| 9 |
/* Work around the fact that with the Intel double-extended precision, |
| 10 |
we've got a 10 byte type stuffed into some amount of padding. And |
| 11 |
the fact that -ffloat-store is going to stuff this value temporarily |
| 12 |
into some bit of stack frame that we've no control over and can't zero. */ |
| 13 |
#if LDBL_MANT_DIG == 64 |
| 14 |
# if defined(__i386__) || defined(__x86_64__) || defined (__ia64__) |
| 15 |
# undef fpsizeofl |
| 16 |
# define fpsizeofl 10 |
| 17 |
# endif |
| 18 |
#endif |
| 19 |
|
| 20 |
/* Work around the fact that the sign of the second double in the IBM |
| 21 |
double-double format is not strictly specified when it contains a zero. |
| 22 |
For instance, -0.0L can be represented with either (-0.0, +0.0) or |
| 23 |
(-0.0, -0.0). The former is what we'll get from the compiler when it |
| 24 |
builds constants; the later is what we'll get from the negation operator |
| 25 |
at runtime. */ |
| 26 |
/* ??? This hack only works for big-endian, which is fortunately true for |
| 27 |
AIX and Darwin. */ |
| 28 |
#if LDBL_MANT_DIG == 106 |
| 29 |
# undef fpsizeofl |
| 30 |
# define fpsizeofl sizeof(double) |
| 31 |
#endif |
| 32 |
|
| 33 |
|
| 34 |
#define TEST(TYPE, EXT) \ |
| 35 |
static TYPE Y##EXT[] = { \ |
| 36 |
2.0, -2.0, -2.0, -2.0, -2.0, 2.0, -0.0, __builtin_inf##EXT () \ |
| 37 |
}; \ |
| 38 |
static const TYPE Z##EXT[] = { \ |
| 39 |
1.0, -1.0, -1.0, -0.0, -0.0, 0.0, -__builtin_inf##EXT (), \ |
| 40 |
__builtin_nan##EXT ("") \ |
| 41 |
}; \ |
| 42 |
\ |
| 43 |
void test##EXT (void) \ |
| 44 |
{ \ |
| 45 |
TYPE r[8]; \ |
| 46 |
int i; \ |
| 47 |
r[0] = __builtin_copysign##EXT (1.0, Y##EXT[0]); \ |
| 48 |
r[1] = __builtin_copysign##EXT (1.0, Y##EXT[1]); \ |
| 49 |
r[2] = __builtin_copysign##EXT (-1.0, Y##EXT[2]); \ |
| 50 |
r[3] = __builtin_copysign##EXT (0.0, Y##EXT[3]); \ |
| 51 |
r[4] = __builtin_copysign##EXT (-0.0, Y##EXT[4]); \ |
| 52 |
r[5] = __builtin_copysign##EXT (-0.0, Y##EXT[5]); \ |
| 53 |
r[6] = __builtin_copysign##EXT (__builtin_inf##EXT (), Y##EXT[6]); \ |
| 54 |
r[7] = __builtin_copysign##EXT (-__builtin_nan##EXT (""), Y##EXT[7]); \ |
| 55 |
for (i = 0; i < 8; ++i) \ |
| 56 |
if (memcmp (r+i, Z##EXT+i, fpsizeof##EXT) != 0) \ |
| 57 |
abort (); \ |
| 58 |
} |
| 59 |
|
| 60 |
TEST(float, f) |
| 61 |
TEST(double, ) |
| 62 |
TEST(long double, l) |
| 63 |
|
| 64 |
int main() |
| 65 |
{ |
| 66 |
testf(); |
| 67 |
test(); |
| 68 |
testl(); |
| 69 |
return 0; |
| 70 |
} |