1 |
12 |
jlechner |
/* Copyright (C) 2004 Free Software Foundation.
|
2 |
|
|
|
3 |
|
|
Verify that built-in folding of various math "power" functions is
|
4 |
|
|
correctly performed by the compiler.
|
5 |
|
|
|
6 |
|
|
Written by Kaveh Ghazi, 2004-03-11. */
|
7 |
|
|
|
8 |
|
|
/* { dg-do link } */
|
9 |
|
|
/* { dg-options "-ffast-math" } */
|
10 |
|
|
/* { dg-options "-ffast-math -mmacosx-version-min=10.3" { target powerpc-*-darwin* } } */
|
11 |
|
|
|
12 |
|
|
#include "../builtins-config.h"
|
13 |
|
|
|
14 |
|
|
#ifdef HAVE_C99_RUNTIME
|
15 |
|
|
#define C99CODE(CODE) CODE
|
16 |
|
|
#else
|
17 |
|
|
#define C99CODE(CODE) 0
|
18 |
|
|
#endif
|
19 |
|
|
|
20 |
|
|
#define PROTOTYPE(FN) extern double FN(double); extern float FN##f(float); \
|
21 |
|
|
extern long double FN##l(long double);
|
22 |
|
|
#define PROTOTYPE2(FN) extern double FN(double, double); \
|
23 |
|
|
extern float FN##f(float, float); \
|
24 |
|
|
extern long double FN##l(long double, long double);
|
25 |
|
|
|
26 |
|
|
PROTOTYPE(fabs)
|
27 |
|
|
PROTOTYPE(sqrt)
|
28 |
|
|
PROTOTYPE(cbrt)
|
29 |
|
|
PROTOTYPE2(pow)
|
30 |
|
|
|
31 |
|
|
void test(double d1, double d2, double d3,
|
32 |
|
|
float f1, float f2, float f3,
|
33 |
|
|
long double ld1, long double ld2, long double ld3)
|
34 |
|
|
{
|
35 |
|
|
/* Test N1root(N2root(x)) -> pow(x,1/(N1*N2)). */
|
36 |
|
|
/* E.g. sqrt(cbrt(x)) -> pow(x,1/6). */
|
37 |
|
|
/* The `ABS' argument is `fabs' when the transformation only works
|
38 |
|
|
for nonnegative arguments. Otherwise it's blank. */
|
39 |
|
|
#define ROOT_ROOT(FN1,N1,FN2,N2,ABS) \
|
40 |
|
|
extern void link_failure_##FN1##_##FN2(void); \
|
41 |
|
|
if (FN1(FN2(ABS(d1))) != pow(ABS(d1),1.0/(N1*N2)) \
|
42 |
|
|
|| C99CODE (FN1##f(FN2##f(ABS(f1))) != powf(ABS(f1),1.0F/(N1*N2))) \
|
43 |
|
|
|| C99CODE (FN1##l(FN2##l(ABS(ld1))) != powl(ABS(ld1),1.0L/(N1*N2)))) \
|
44 |
|
|
link_failure_##FN1##_##FN2()
|
45 |
|
|
|
46 |
|
|
ROOT_ROOT(sqrt,2,sqrt,2,);
|
47 |
|
|
ROOT_ROOT(sqrt,2,cbrt,3,);
|
48 |
|
|
ROOT_ROOT(cbrt,3,sqrt,2,);
|
49 |
|
|
ROOT_ROOT(cbrt,3,cbrt,3,fabs);
|
50 |
|
|
|
51 |
|
|
/* Test pow(Nroot(x),y) -> pow(x,y/N). */
|
52 |
|
|
/* The `ABS' argument is `fabs' when the transformation only works
|
53 |
|
|
for nonnegative arguments. Otherwise it's blank. */
|
54 |
|
|
#define POW_ROOT(FN,N,ABS) \
|
55 |
|
|
extern void link_failure_pow_##FN(void); \
|
56 |
|
|
if (pow(FN(ABS(d1)), d2) != pow(ABS(d1),d2/N) \
|
57 |
|
|
|| powf(FN##f(ABS(f1)),f2) != powf(ABS(f1),f2/N) \
|
58 |
|
|
|| powl(FN##l(ABS(ld1)),ld2) != powl(ABS(ld1),ld2/N)) \
|
59 |
|
|
link_failure_pow_##FN()
|
60 |
|
|
|
61 |
|
|
POW_ROOT(sqrt,2,);
|
62 |
|
|
POW_ROOT(cbrt,3,fabs);
|
63 |
|
|
|
64 |
|
|
/* Test Nroot(pow(x,y)) -> pow(x,y/N). */
|
65 |
|
|
/* The `ABS' argument is `fabs' when the transformation only works
|
66 |
|
|
for nonnegative arguments. Otherwise it's blank. */
|
67 |
|
|
#define ROOT_POW(FN,N,ABS) \
|
68 |
|
|
extern void link_failure_##FN##_pow(void); \
|
69 |
|
|
if (FN(pow(ABS(d1), d2)) != pow(ABS(d1),d2/N) \
|
70 |
|
|
|| FN##f(powf(ABS(f1),f2)) != powf(ABS(f1),f2/N) \
|
71 |
|
|
|| FN##l(powl(ABS(ld1),ld2)) != powl(ABS(ld1),ld2/N)) \
|
72 |
|
|
link_failure_##FN##_pow()
|
73 |
|
|
|
74 |
|
|
ROOT_POW(sqrt,2,fabs);
|
75 |
|
|
ROOT_POW(cbrt,3,fabs);
|
76 |
|
|
|
77 |
|
|
/* Test pow(pow(x,y),z) -> pow(x,y*z). */
|
78 |
|
|
#define POW_POW \
|
79 |
|
|
extern void link_failure_pow_pow(void); \
|
80 |
|
|
if (pow(pow(d1, d2), d3) != pow(d1,d2*d3) \
|
81 |
|
|
|| powf(powf(f1,f2),f3) != powf(f1,f2*f3) \
|
82 |
|
|
|| powl(powl(ld1,ld2),ld3) != powl(ld1,ld2*ld3)) \
|
83 |
|
|
link_failure_pow_pow()
|
84 |
|
|
|
85 |
|
|
POW_POW;
|
86 |
|
|
|
87 |
|
|
/* Test Nroot(x)*Nroot(y) -> Nroot(x*y). */
|
88 |
|
|
#define ROOT_X_ROOT(FN) \
|
89 |
|
|
extern void link_failure_root_x_root(void); \
|
90 |
|
|
if (FN(d1)*FN(d2) != FN(d1*d2) \
|
91 |
|
|
|| FN##f(f1)*FN##f(f2) != FN##f(f1*f2) \
|
92 |
|
|
|| FN##l(ld1)*FN##l(ld2) != FN##l(ld1*ld2)) \
|
93 |
|
|
link_failure_root_x_root()
|
94 |
|
|
|
95 |
|
|
ROOT_X_ROOT(sqrt);
|
96 |
|
|
ROOT_X_ROOT(cbrt);
|
97 |
|
|
|
98 |
|
|
/* Test pow(x,y)*pow(x,z) -> pow(x,y+z). */
|
99 |
|
|
#define POW_X_POW \
|
100 |
|
|
extern void link_failure_pow_x_pow(void); \
|
101 |
|
|
if (pow(d1,d2)*pow(d1,d3) != pow(d1,d2+d3) \
|
102 |
|
|
|| powf(f1,f2)*powf(f1,f3) != powf(f1,f2+f3) \
|
103 |
|
|
|| powl(ld1,ld2)*powl(ld1,ld3) != powl(ld1,ld2+ld3)) \
|
104 |
|
|
link_failure_pow_x_pow()
|
105 |
|
|
|
106 |
|
|
POW_X_POW;
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
int main (void)
|
111 |
|
|
{
|
112 |
|
|
return 0;
|
113 |
|
|
}
|