OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.dg/] [torture/] [builtin-explog-1.c] - Blame information for rev 149

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
/* Copyright (C) 2003, 2004  Free Software Foundation.
2
 
3
   Verify that built-in math function constant folding of log & exp is
4
   correctly performed by the compiler.
5
 
6
   Written by Kaveh Ghazi, 2003-09-05.  */
7
 
8
/* { dg-do link } */
9
/* { dg-options "-ffast-math" } */
10
 
11
/* Define "e" with as many bits as found in builtins.c:dconste.  */
12
#define M_E  2.7182818284590452353602874713526624977572470936999595749669676277241
13
#define M_EF 2.7182818284590452353602874713526624977572470936999595749669676277241F
14
#define M_EL 2.7182818284590452353602874713526624977572470936999595749669676277241L
15
/* Precision for comparison tests.  */
16
#define PREC  (sizeof (float) < sizeof (double) ? 0.0000001 : PRECF)
17
#define PRECF 0.0001F
18
#define PRECL (sizeof (float) < sizeof (long double)    \
19
               ? 0.0000000000001L : PRECF)
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(exp)
27
PROTOTYPE(exp2)
28
PROTOTYPE(exp10)
29
PROTOTYPE(log)
30
PROTOTYPE(log2)
31
PROTOTYPE(log10)
32
PROTOTYPE(pow10)
33
PROTOTYPE(sqrt)
34
PROTOTYPE(cbrt)
35
PROTOTYPE2(pow)
36
 
37
void test(double d1, double d2, float f1, float f2,
38
          long double ld1, long double ld2)
39
{
40
  /* Test logN(1) -> 0.  */
41
#define LOG_1(LOG) \
42
 extern void link_failure_##LOG##_1(void); \
43
 if (LOG(1.0) != 0.0 || LOG##f(1.0F) != 0.0F || LOG##l(1.0L) != 0.0L) \
44
    link_failure_##LOG##_1()
45
 
46
  LOG_1(log);
47
  LOG_1(log2);
48
  LOG_1(log10);
49
 
50
  /* Test logN(N) -> 1.  */
51
#define LOG_N(LOG, BASE) \
52
 extern void link_failure_##LOG##_N(void); \
53
 if (LOG(BASE) != 1.0 || LOG##f(BASE##F) != 1.0F || LOG##l(BASE##L) != 1.0L) \
54
    link_failure_##LOG##_N()
55
 
56
  LOG_N(log, M_E);
57
  LOG_N(log2, 2.0);
58
  LOG_N(log10, 10.0);
59
 
60
  /* Test logN(expN(x)) -> x.  */
61
#define LOGEXP_SAME(LOG, EXP) \
62
 extern void link_failure_##LOG##_##EXP##_same(void); \
63
 if (LOG(EXP(d1)) != d1 || LOG##f(EXP##f(f1)) != f1 \
64
  || LOG##l(EXP##l(ld1)) != ld1) link_failure_##LOG##_##EXP##_same()
65
 
66
  LOGEXP_SAME(log,exp);
67
  LOGEXP_SAME(log2,exp2);
68
  LOGEXP_SAME(log10,exp10);
69
  LOGEXP_SAME(log10,pow10);
70
 
71
  /* Test logN(expM(x)) -> x*logN(M).  */
72
#define LOGEXP(LOG, EXP, BASE) \
73
 extern void link_failure_##LOG##_##EXP(void); \
74
 if (LOG(EXP(d1)) != d1*LOG(BASE) || LOG##f(EXP##f(f1)) != f1*LOG##f(BASE##F) \
75
  || LOG##l(EXP##l(ld1)) != ld1*LOG##l(BASE##L)) link_failure_##LOG##_##EXP()
76
 
77
  LOGEXP(log,exp,M_E);
78
  LOGEXP(log,exp2,2.0);
79
  LOGEXP(log,exp10,10.0);
80
  LOGEXP(log,pow10,10.0);
81
  LOGEXP(log2,exp,M_E);
82
  LOGEXP(log2,exp2,2.0);
83
  LOGEXP(log2,exp10,10.0);
84
  LOGEXP(log2,pow10,10.0);
85
  LOGEXP(log10,exp,M_E);
86
  LOGEXP(log10,exp2,2.0);
87
  LOGEXP(log10,exp10,10.0);
88
  LOGEXP(log10,pow10,10.0);
89
 
90
  /* Test logN(sqrt(x)) -> 0.5*logN(x).  */
91
#define LOG_SQRT(LOG) \
92
 extern void link_failure_##LOG##_sqrt(void); \
93
 if (LOG(sqrt(d1)) != 0.5*LOG(d1) || LOG##f(sqrtf(f1)) != 0.5F*LOG##f(f1) \
94
  || LOG##l(sqrtl(ld1)) != 0.5L*LOG##l(ld1)) link_failure_##LOG##_sqrt()
95
 
96
  LOG_SQRT(log);
97
  LOG_SQRT(log2);
98
  LOG_SQRT(log10);
99
 
100
  /* Test sqrt(expN(x)) -> expN(x*0.5).  */
101
#define SQRT_EXP(EXP) \
102
 extern void link_failure_sqrt_##EXP(void); \
103
 if (sqrt(EXP(d1)) != EXP(d1*0.5) || sqrtf(EXP##f(f1)) != EXP##f(f1*0.5F) \
104
  || sqrtl(EXP##l(ld1)) != EXP##l(ld1*0.5L)) link_failure_sqrt_##EXP()
105
 
106
  SQRT_EXP(exp);
107
  SQRT_EXP(exp2);
108
  SQRT_EXP(exp10);
109
  SQRT_EXP(pow10);
110
 
111
  /* Test logN(cbrt(x)) -> (1/3)*logN(x).  */
112
#define LOG_CBRT(LOG) \
113
 extern void link_failure_##LOG##_cbrt(void); \
114
 if (LOG(cbrt(d1)) != (1.0/3)*LOG(d1) \
115
  || LOG##f(cbrtf(f1)) != (1.0F/3)*LOG##f(f1) \
116
  || LOG##l(cbrtl(ld1)) != (1.0L/3)*LOG##l(ld1)) link_failure_##LOG##_cbrt()
117
 
118
  LOG_CBRT(log);
119
  LOG_CBRT(log2);
120
  LOG_CBRT(log10);
121
 
122
  /* Test cbrt(expN(x)) -> expN(x/3).  */
123
#define CBRT_EXP(EXP) \
124
 extern void link_failure_cbrt_##EXP(void); \
125
 if (cbrt(EXP(d1)) != EXP(d1/3.0) || cbrtf(EXP##f(f1)) != EXP##f(f1/3.0F) \
126
  || cbrtl(EXP##l(ld1)) != EXP##l(ld1/3.0L)) link_failure_cbrt_##EXP()
127
 
128
  CBRT_EXP(exp);
129
  CBRT_EXP(exp2);
130
  CBRT_EXP(exp10);
131
  CBRT_EXP(pow10);
132
 
133
  /* Test logN(pow(x,y)) -> y*logN(x).  */
134
#define LOG_POW(LOG, POW) \
135
 extern void link_failure_##LOG##_##POW(void); \
136
 if (LOG(POW(d1,d2)) != d2*LOG(d1) || LOG##f(POW##f(f1,f2)) != f2*LOG##f(f1) \
137
  || LOG##l(POW##l(ld1,ld2)) != ld2*LOG##l(ld1)) link_failure_##LOG##_##POW()
138
 
139
  LOG_POW(log,pow);
140
  LOG_POW(log2,pow);
141
  LOG_POW(log10,pow);
142
 
143
  /* Test pow(expN(x),y)) -> expN(x*y).  */
144
#define POW_EXP(POW, EXP) \
145
 extern void link_failure_##POW##_##EXP(void); \
146
 if (POW(EXP(d1),d2) != EXP(d1*d2) || POW##f(EXP##f(f1),f2) != EXP##f(f1*f2) \
147
  || POW##l(EXP##l(ld1),ld2) != EXP##l(ld1*ld2)) link_failure_##POW##_##EXP()
148
 
149
  POW_EXP(pow, exp);
150
  POW_EXP(pow, exp2);
151
  POW_EXP(pow, exp10);
152
  POW_EXP(pow, pow10);
153
 
154
  /* Test expN(0) -> 1.  */
155
#define EXP_0(EXP) \
156
 extern void link_failure_##EXP##_0(void); \
157
 if (EXP(0.0) != 1.0 || EXP##f(0.0F) != 1.0F || EXP##l(0.0L) != 1.0L) \
158
  link_failure_##EXP##_0()
159
 
160
  EXP_0(exp);
161
  EXP_0(exp2);
162
  EXP_0(exp10);
163
  EXP_0(pow10);
164
 
165
  /* Test expN(1) -> N.  */
166
#define EXP_N(EXP, BASE) \
167
 extern void link_failure_##EXP##_N(void); \
168
 if (EXP(1.0) != BASE || EXP##f(1.0F) != BASE##F || EXP##l(1.0L) != BASE##L) \
169
  link_failure_##EXP##_N()
170
 
171
  EXP_N(exp, M_E);
172
  EXP_N(exp2, 2.0);
173
  EXP_N(exp10, 10.0);
174
  EXP_N(pow10, 10.0);
175
 
176
  /* Test expN(integer) -> N*N*N*...  */
177
#define EXP_INT(EXP, BASE) \
178
 extern void link_failure_##EXP##_INT(void); \
179
 if (EXP(5.0) < (BASE)*(BASE)*(BASE)*(BASE)*(BASE) - PREC \
180
  || EXP(5.0) > (BASE)*(BASE)*(BASE)*(BASE)*(BASE) + PREC \
181
  || EXP##f(5.0F) < (BASE##F)*(BASE##F)*(BASE##F)*(BASE##F)*(BASE##F) -PRECF \
182
  || EXP##f(5.0F) > (BASE##F)*(BASE##F)*(BASE##F)*(BASE##F)*(BASE##F) +PRECF \
183
  || EXP##l(5.0L) < (BASE##L)*(BASE##L)*(BASE##L)*(BASE##L)*(BASE##L) -PRECL \
184
  || EXP##l(5.0L) > (BASE##L)*(BASE##L)*(BASE##L)*(BASE##L)*(BASE##L) +PRECL) \
185
   link_failure_##EXP##_INT()
186
 
187
  EXP_INT(exp, M_E);
188
  EXP_INT(exp2, 2.0);
189
  EXP_INT(exp10, 10.0);
190
  EXP_INT(pow10, 10.0);
191
 
192
  /* Test expN(logN(x)) -> x.  */
193
#define EXPLOG_SAME(EXP, LOG) \
194
 extern void link_failure_##EXP##_##LOG##_same(void); \
195
 if (EXP(LOG(d1)) != d1 || EXP##f(LOG##f(f1)) != f1 \
196
  || EXP##l(LOG##l(ld1)) != ld1) link_failure_##EXP##_##LOG##_same()
197
 
198
  EXPLOG_SAME(exp, log);
199
  EXPLOG_SAME(exp2, log2);
200
  EXPLOG_SAME(exp10, log10);
201
  EXPLOG_SAME(pow10, log10);
202
 
203
  /* Test expN(x)*expN(y)) -> expN(x+y).  */
204
#define EXPXEXP(EXP) \
205
 extern void link_failure_##EXP##X##EXP(void); \
206
 if (EXP(d1)*EXP(d2) != EXP(d1+d2) || EXP##f(f1)*EXP##f(f2) != EXP##f(f1+f2) \
207
  || EXP##l(ld1)*EXP##l(ld2) != EXP##l(ld1+ld2)) link_failure_##EXP##X##EXP()
208
 
209
  EXPXEXP(exp);
210
  EXPXEXP(exp2);
211
  EXPXEXP(exp10);
212
  EXPXEXP(pow10);
213
 
214
  /* Test x/expN(y) -> x*expN(-y).  */
215
  /* Test expN(x)/expN(y) -> expN(x-y).  */
216
#define DIVEXP(EXP) \
217
 extern void link_failure_div1_##EXP(void); \
218
 if (d1/EXP(d2) != d1*EXP(-d2) || f1/EXP##f(f2) != f1*EXP##f(-f2) \
219
  || ld1/EXP##l(ld2) != ld1*EXP##l(-ld2)) link_failure_div1_##EXP(); \
220
 extern void link_failure_div2_##EXP(void); \
221
 if (EXP(d1)/EXP(d2) != EXP(d1-d2) || EXP##f(f1)/EXP##f(f2) != EXP##f(f1-f2) \
222
  || EXP##l(ld1)/EXP##l(ld2) != EXP##l(ld1-ld2)) link_failure_div2_##EXP()
223
 
224
  DIVEXP(exp);
225
  DIVEXP(exp2);
226
  DIVEXP(exp10);
227
  DIVEXP(pow10);
228
}
229
 
230
int main (void)
231
{
232
  return 0;
233
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.