Add _FloatN, _FloatNx tests for __builtin_fpclassify.
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-math-7.c
blob064e28641a7de7d63aa3934de61b6181a7fc4124
1 /* Copyright (C) 2009 Free Software Foundation.
3 Verify that folding of complex mul and div work correctly.
5 Origin: Kaveh R. Ghazi, August 13, 2009. */
7 /* { dg-do run } */
8 /* C6X fails due to -freciprocal-math default. */
9 /* { dg-skip-if "" { tic6x-*-* } "*" "" } */
10 /* { dg-add-options ieee } */
11 /* { dg-require-effective-target large_double } */
13 extern void link_error(int);
15 /* Evaluate this expression at compile-time. */
16 #define COMPILETIME_TESTIT(TYPE,X,OP,Y,RES) do { \
17 if ((_Complex TYPE)(X) OP (_Complex TYPE)(Y) != (_Complex TYPE)(RES)) \
18 link_error(__LINE__); \
19 } while (0)
21 /* Use this error function for cases which only evaluate at
22 compile-time when optimizing. */
23 #ifdef __OPTIMIZE__
24 # define ERROR_FUNC(X) link_error(X)
25 #else
26 # define ERROR_FUNC(X) __builtin_abort()
27 #endif
29 /* Evaluate this expression at compile-time using static initializers. */
30 #define STATICINIT_TESTIT(TYPE,X,OP,Y,RES) do { \
31 static const _Complex TYPE foo = (_Complex TYPE)(X) OP (_Complex TYPE)(Y); \
32 if (foo != (_Complex TYPE)(RES)) \
33 ERROR_FUNC (__LINE__); \
34 } while (0)
36 /* Evaluate this expression at runtime. */
37 #define RUNTIME_TESTIT(TYPE,X,OP,Y,RES) do { \
38 volatile _Complex TYPE foo; \
39 foo = (_Complex TYPE)(X); \
40 foo OP##= (_Complex TYPE)(Y); \
41 if (foo != (_Complex TYPE)(RES)) \
42 __builtin_abort(); \
43 } while (0)
45 /* Evaluate this expression at compile-time and runtime. */
46 #define TESTIT(TYPE,X,OP,Y,RES) do { \
47 STATICINIT_TESTIT(TYPE,X,OP,Y,RES); \
48 COMPILETIME_TESTIT(TYPE,X,OP,Y,RES); \
49 RUNTIME_TESTIT(TYPE,X,OP,Y,RES); \
50 } while (0)
52 /* Either the real or imaginary parts should be infinity. */
53 #define TEST_ONE_PART_INF(VAL) do { \
54 static const _Complex double foo = (VAL); \
55 if (! __builtin_isinf(__real foo) && ! __builtin_isinf(__imag foo)) \
56 ERROR_FUNC (__LINE__); \
57 if (! __builtin_isinf(__real (VAL)) && ! __builtin_isinf(__imag (VAL))) \
58 __builtin_abort(); \
59 } while (0)
61 int main()
63 /* Test some regular finite values. */
64 TESTIT (double, 3.+4.i, *, 2, 6+8i);
65 TESTIT (double, 3.+4.i, /, 2, 1.5+2i);
66 TESTIT (int, 3+4i, *, 2, 6+8i);
67 TESTIT (int, 3+4i, /, 2, 1+2i);
69 TESTIT (double, 3.+4.i, *, 2+5i, -14+23i);
70 TESTIT (double, 3.+4.i, /, 5i, .8-.6i);
71 TESTIT (int, 3+4i, *, 2+5i, -14+23i);
72 TESTIT (int, 30+40i, /, 5i, 8-6i);
73 TESTIT (int, 14+6i, /, 7+3i, 2);
74 TESTIT (int, 8+24i, /, 4+12i, 2);
76 /* Test that we don't overflow. */
77 TESTIT (double,
78 (__DBL_MAX__ * 0.5 + __DBL_MAX__ * 0.5i),
80 (__DBL_MAX__ * 0.25 + __DBL_MAX__ * 0.25i),
81 2);
83 /* Test for accuracy. */
84 COMPILETIME_TESTIT (double,
85 (1 + __DBL_EPSILON__ + 1i),
87 (1 - __DBL_EPSILON__ + 1i),
88 -4.93038065763132378382330353301741393545754021943139377981e-32+2i);
90 /* This becomes (NaN + iInf). */
91 #define VAL1 ((_Complex double)__builtin_inf() * 1i)
93 /* Test some C99 Annex G special cases. */
94 TEST_ONE_PART_INF ((VAL1) * (VAL1));
95 TEST_ONE_PART_INF ((_Complex double)1 / (_Complex double)0);
96 TEST_ONE_PART_INF ((VAL1) / (_Complex double)1);
98 RUNTIME_TESTIT (double, 1, /, VAL1, 0);
99 STATICINIT_TESTIT (double, 1, /, VAL1, 0);
101 return 0;