1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/* Test __builtin_complex semantics. */
/* { dg-do run } */
/* { dg-options "-std=c11 -pedantic-errors" } */
/* { dg-require-effective-target inf } */
/* { dg-add-options ieee } */
/* { dg-skip-if "double support is incomplete" { "avr-*-*" } } */
extern void exit (int);
extern void abort (void);
#define COMPARE_BODY(A, B, TYPE, COPYSIGN) \
do { \
TYPE s1 = COPYSIGN ((TYPE) 1.0, A); \
TYPE s2 = COPYSIGN ((TYPE) 1.0, B); \
if (s1 != s2) \
abort (); \
if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0)) \
abort (); \
if ((A != B) != (__builtin_isnan (A) != 0)) \
abort (); \
} while (0)
void
comparef (float a, float b)
{
COMPARE_BODY (a, b, float, __builtin_copysignf);
}
void
compare (double a, double b)
{
COMPARE_BODY (a, b, double, __builtin_copysign);
}
void
comparel (long double a, long double b)
{
COMPARE_BODY (a, b, long double, __builtin_copysignl);
}
void
comparecf (_Complex float a, float r, float i)
{
comparef (__real__ a, r);
comparef (__imag__ a, i);
}
void
comparec (_Complex double a, double r, double i)
{
compare (__real__ a, r);
compare (__imag__ a, i);
}
void
comparecl (_Complex long double a, long double r, long double i)
{
comparel (__real__ a, r);
comparel (__imag__ a, i);
}
#define VERIFY(A, B, TYPE, COMPARE) \
do { \
TYPE a = A; \
TYPE b = B; \
_Complex TYPE cr = __builtin_complex (a, b); \
static _Complex TYPE cs = __builtin_complex (A, B); \
COMPARE (cr, A, B); \
COMPARE (cs, A, B); \
} while (0)
#define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE) \
do { \
VERIFY (PZ, PZ, TYPE, COMPARE); \
VERIFY (PZ, NZ, TYPE, COMPARE); \
VERIFY (PZ, NAN, TYPE, COMPARE); \
VERIFY (PZ, INF, TYPE, COMPARE); \
VERIFY (NZ, PZ, TYPE, COMPARE); \
VERIFY (NZ, NZ, TYPE, COMPARE); \
VERIFY (NZ, NAN, TYPE, COMPARE); \
VERIFY (NZ, INF, TYPE, COMPARE); \
VERIFY (NAN, PZ, TYPE, COMPARE); \
VERIFY (NAN, NZ, TYPE, COMPARE); \
VERIFY (NAN, NAN, TYPE, COMPARE); \
VERIFY (NAN, INF, TYPE, COMPARE); \
VERIFY (INF, PZ, TYPE, COMPARE); \
VERIFY (INF, NZ, TYPE, COMPARE); \
VERIFY (INF, NAN, TYPE, COMPARE); \
VERIFY (INF, INF, TYPE, COMPARE); \
} while (0)
void
check_float (void)
{
ALL_CHECKS (0.0f, -0.0f, __builtin_nanf(""), __builtin_inff(),
float, comparecf);
}
void
check_double (void)
{
ALL_CHECKS (0.0, -0.0, __builtin_nan(""), __builtin_inf(),
double, comparec);
}
void
check_long_double (void)
{
ALL_CHECKS (0.0l, -0.0l, __builtin_nanl(""), __builtin_infl(),
long double, comparecl);
}
int
main (void)
{
check_float ();
check_double ();
check_long_double ();
exit (0);
}
|