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