Merge from the pain train
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-power-1.c
blob7cdc00c23fb0eb40db2dad89f7073037822013cc
1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that built-in folding of various math "power" functions is
4 correctly performed by the compiler.
6 Written by Kaveh Ghazi, 2004-03-11. */
8 /* { dg-do link } */
9 /* { dg-options "-ffast-math" } */
11 #include "../builtins-config.h"
13 #ifdef HAVE_C99_RUNTIME
14 #define C99CODE(CODE) CODE
15 #else
16 #define C99CODE(CODE) 0
17 #endif
19 #define PROTOTYPE(FN) extern double FN(double); extern float FN##f(float); \
20 extern long double FN##l(long double);
21 #define PROTOTYPE2(FN) extern double FN(double, double); \
22 extern float FN##f(float, float); \
23 extern long double FN##l(long double, long double);
25 PROTOTYPE(sqrt)
26 PROTOTYPE(cbrt)
27 PROTOTYPE2(pow)
29 void test(double d1, double d2, double d3,
30 float f1, float f2, float f3,
31 long double ld1, long double ld2, long double ld3)
33 /* Test N1root(N2root(x)) -> pow(x,1/(N1*N2)). */
34 /* E.g. sqrt(cbrt(x)) -> pow(x,1/6). */
35 #define ROOT_ROOT(FN1,N1,FN2,N2) \
36 extern void link_failure_##FN1##_##FN2(void); \
37 if (FN1(FN2(d1)) != pow(d1,1.0/(N1*N2)) \
38 || C99CODE (FN1##f(FN2##f(f1)) != powf(f1,1.0F/(N1*N2))) \
39 || C99CODE (FN1##l(FN2##l(ld1)) != powl(ld1,1.0L/(N1*N2)))) \
40 link_failure_##FN1##_##FN2()
42 ROOT_ROOT(sqrt,2,sqrt,2);
43 ROOT_ROOT(sqrt,2,cbrt,3);
44 ROOT_ROOT(cbrt,3,sqrt,2);
45 /*ROOT_ROOT(cbrt,3,cbrt,3); Intentionally not implemented. */
47 /* Test pow(Nroot(x),y) -> pow(x,y/N). */
48 #define POW_ROOT(FN,N) \
49 extern void link_failure_pow_##FN(void); \
50 if (pow(FN(d1), d2) != pow(d1,d2/N) \
51 || powf(FN##f(f1),f2) != powf(f1,f2/N) \
52 || powl(FN##l(ld1),ld2) != powl(ld1,ld2/N)) \
53 link_failure_pow_##FN()
55 POW_ROOT(sqrt,2);
56 /*POW_ROOT(cbrt,3); Intentionally not implemented. */
58 /* Test Nroot(pow(x,y)) -> pow(x,y/N). */
59 #define ROOT_POW(FN,N) \
60 extern void link_failure_##FN##_pow(void); \
61 if (FN(pow(d1, d2)) != pow(d1,d2/N) \
62 || FN##f(powf(f1,f2)) != powf(f1,f2/N) \
63 || FN##l(powl(ld1,ld2)) != powl(ld1,ld2/N)) \
64 link_failure_##FN##_pow()
66 /*ROOT_POW(sqrt,2); Invalid. */
67 /*ROOT_POW(cbrt,3); Intentionally not implemented. */
69 /* Test pow(pow(x,y),z) -> pow(x,y*z). */
70 #define POW_POW \
71 extern void link_failure_pow_pow(void); \
72 if (pow(pow(d1, d2), d3) != pow(d1,d2*d3) \
73 || powf(powf(f1,f2),f3) != powf(f1,f2*f3) \
74 || powl(powl(ld1,ld2),ld3) != powl(ld1,ld2*ld3)) \
75 link_failure_pow_pow()
77 POW_POW;
79 /* Test Nroot(x)*Nroot(y) -> Nroot(x*y). */
80 #define ROOT_X_ROOT(FN) \
81 extern void link_failure_root_x_root(void); \
82 if (FN(d1)*FN(d2) != FN(d1*d2) \
83 || FN##f(f1)*FN##f(f2) != FN##f(f1*f2) \
84 || FN##l(ld1)*FN##l(ld2) != FN##l(ld1*ld2)) \
85 link_failure_root_x_root()
87 ROOT_X_ROOT(sqrt);
88 ROOT_X_ROOT(cbrt);
90 /* Test pow(x,y)*pow(x,z) -> pow(x,y+z). */
91 #define POW_X_POW \
92 extern void link_failure_pow_x_pow(void); \
93 if (pow(d1,d2)*pow(d1,d3) != pow(d1,d2+d3) \
94 || powf(f1,f2)*powf(f1,f3) != powf(f1,f2+f3) \
95 || powl(ld1,ld2)*powl(ld1,ld3) != powl(ld1,ld2+ld3)) \
96 link_failure_pow_x_pow()
98 POW_X_POW;
102 int main (void)
104 return 0;