1 /* Copyright (C) 2010 Free Software Foundation.
3 Verify that folding of built-in cproj is correctly performed by the
6 Origin: Kaveh R. Ghazi, April 9, 2010. */
10 /* All references to link_error should go away at compile-time. The
11 argument is the __LINE__ number. It appears in the tree dump file
12 and aids in debugging should any of the tests fail. */
13 extern void link_error(int);
15 #define CPROJ(X) __builtin_cproj(X)
16 #define CPROJF(X) __builtin_cprojf(X)
17 #define CPROJL(X) __builtin_cprojl(X)
18 #define INF __builtin_inff()
20 #define CPSGN(X,Y) __builtin_copysignf((X),(Y))
21 #define CIMAG(X) __builtin_cimagf(X)
22 #define CREAL(X) __builtin_crealf(X)
24 /* Check that the signs of the real and/or imaginary parts of two
25 complex numbers match. */
26 #define CKSGN(X,Y) (CKSGN_R(X,Y) || CKSGN_I(X,Y))
27 #define CKSGN_R(X,Y) (CPSGN(1,CREAL(X)) != CPSGN(1,CREAL(Y)))
28 #define CKSGN_I(X,Y) (CPSGN(1,CIMAG(X)) != CPSGN(1,CIMAG(Y)))
30 /* Test that (cproj(X) == ZERO+Inf) and that the signs of the
31 imaginary parts match. ZERO is +/- 0i. */
32 #define TEST_CST_INF(X,ZERO) do { \
33 if (CPROJF(X) != ZERO+INF || CKSGN_I(CPROJF(X),ZERO+INF)) \
34 link_error(__LINE__); \
35 if (CPROJ(X) != ZERO+INF || CKSGN_I(CPROJ(X),ZERO+INF)) \
36 link_error(__LINE__); \
37 if (CPROJL(X) != ZERO+INF || CKSGN_I(CPROJL(X),ZERO+INF)) \
38 link_error(__LINE__); \
41 /* Test that (cproj(X) == X) for all finite (X). */
42 #define TEST_CST(X) do { \
43 if (CPROJF(X) != (X) || CKSGN(CPROJF(X),(X))) \
44 link_error(__LINE__); \
49 TEST_CST_INF (INF+0I, 0);
50 TEST_CST_INF (INF-0I, -0.FI);
51 TEST_CST_INF (INF+4I, 0);
52 TEST_CST_INF (INF-4I, -0.FI);
53 TEST_CST_INF (-INF+0I, 0);
54 TEST_CST_INF (-INF-0I, -0.FI);
55 TEST_CST_INF (-INF+4I, 0);
56 TEST_CST_INF (-INF-4I, -0.FI);
58 TEST_CST_INF (0+I*INF, 0);
59 TEST_CST_INF (0-I*INF, -0.FI);
60 TEST_CST_INF (23+I*INF, 0);
61 TEST_CST_INF (23-I*INF, -0.FI);
62 TEST_CST_INF (-0.F+I*INF, 0);
63 TEST_CST_INF (-0.F-I*INF, -0.FI);
64 TEST_CST_INF (-23+I*INF, 0);
65 TEST_CST_INF (-23-I*INF, -0.FI);
67 TEST_CST_INF (INF+I*INF, 0);
68 TEST_CST_INF (INF-I*INF, -0.FI);
69 TEST_CST_INF (-INF+I*INF, 0);
70 TEST_CST_INF (-INF-I*INF, -0.FI);