1 /* Copyright (C) 2006 Free Software Foundation.
3 Verify that built-in math function folding of symmetric even and
4 odd functions is correctly performed by the compiler.
6 Origin: Kaveh R. Ghazi, November 09, 2006. */
9 /* { dg-options "-ffast-math" } */
10 /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
12 /* All references to link_error should go away at compile-time. */
13 extern void link_error(int);
15 /* Test that FUNC(-ARG) == FUNC(ARG). */
16 #define TESTIT_EVEN(FUNC) do { \
17 if (__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
18 link_error(__LINE__); \
19 if (__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
20 link_error(__LINE__); \
21 if (__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
22 link_error(__LINE__); \
25 /* Test that FUNC(-ARG) == FUNC(ARG), where ARG has a complex type. */
26 #define TESTIT_EVEN_C(FUNC) do { \
27 if (__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
28 link_error(__LINE__); \
29 if (__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
30 link_error(__LINE__); \
31 if (__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
32 link_error(__LINE__); \
35 /* Test that FUNC(-VAR) == FUNC(VAR), where VAR has an int type. */
36 #define TESTIT_EVEN_I(FUNC,VAR) do { \
37 if (__builtin_##FUNC(-VAR) != __builtin_##FUNC(VAR)) \
38 link_error(__LINE__); \
41 /* Test that -FUNC(ARG) == FUNC(-ARG). */
42 #define TESTIT_ODD(FUNC) do { \
43 if (-__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
44 link_error(__LINE__); \
45 if (-__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
46 link_error(__LINE__); \
47 if (-__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
48 link_error(__LINE__); \
51 /* Test that -FUNC(ARG) == FUNC(-ARG), where ARG has a complex type. */
52 #define TESTIT_ODD_C(FUNC) do { \
53 if (-__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
54 link_error(__LINE__); \
55 if (-__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
56 link_error(__LINE__); \
57 if (-__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
58 link_error(__LINE__); \
61 void foo (float xf
, double x
, long double xl
,
62 __complex__
float cxf
, __complex__
double cx
, __complex__
long double cxl
,
63 int i
, long l
, long long ll
, __INTMAX_TYPE__ im
)
73 TESTIT_EVEN_I(abs
, i
);
74 TESTIT_EVEN_I(imaxabs
, im
);
75 TESTIT_EVEN_I(labs
, l
);
76 TESTIT_EVEN_I(llabs
, ll
);
88 TESTIT_ODD(nearbyint
);
100 TESTIT_ODD_C(catanh
);
110 foo (1,1,1,1,1,1,1,1,1,1);