2151259983a3496e4268120e800317f1f6265497
[libc-test] / src / math / gen / mplibm.c
1 #include "gen.h"
2
3 static int mpf1(struct t *s, float (*f)(float))
4 {
5         s->dy = 0;
6         setupfenv(s->r);
7         s->y = f(s->x);
8         s->e = getexcept();
9         return 0;
10 }
11
12 static int mpf2(struct t *s, float (*f)(float,float))
13 {
14         s->dy = 0;
15         setupfenv(s->r);
16         s->y = f(s->x, s->x2);
17         s->e = getexcept();
18         return 0;
19 }
20
21 static int mpd1(struct t *s, double (*f)(double))
22 {
23         s->dy = 0;
24         setupfenv(s->r);
25         s->y = f(s->x);
26         s->e = getexcept();
27         return 0;
28 }
29
30 static int mpd2(struct t *s, double (*f)(double, double))
31 {
32         s->dy = 0;
33         setupfenv(s->r);
34         s->y = f(s->x, s->x2);
35         s->e = getexcept();
36         return 0;
37 }
38
39 static int mpl1(struct t *s, long double (*f)(long double))
40 {
41         s->dy = 0;
42         setupfenv(s->r);
43         s->y = f(s->x);
44         s->e = getexcept();
45         return 0;
46 }
47
48 static int mpl2(struct t *s, long double (*f)(long double, long double))
49 {
50         setupfenv(s->r);
51         s->y = f(s->x, s->x2);
52         s->dy = 0;
53         s->e = getexcept();
54         return 0;
55 }
56
57 static double sinpi(double x) { return sin(3.141592653589793238*x); }
58 int mpsinpi(struct t *t) { return mpd1(t, sinpi); }
59
60 static double add(double x, double y) { double z = x + y; return z; }
61 int mpadd(struct t *t) { return mpd2(t, add); }
62 static double mul(double x, double y) { double z = x * y; return z; }
63 int mpmul(struct t *t) { return mpd2(t, mul); }
64 static double div(double x, double y) { double z = x / y; return z; }
65 int mpdiv(struct t *t) { return mpd2(t, div); }
66
67 int mpacos(struct t *t) { return mpd1(t, acos); }
68 int mpacosf(struct t *t) { return mpf1(t, acosf); }
69 int mpacosl(struct t *t) { return mpl1(t, acosl); }
70 int mpacosh(struct t *t) { return mpd1(t, acosh); }
71 int mpacoshf(struct t *t) { return mpf1(t, acoshf); }
72 int mpacoshl(struct t *t) { return mpl1(t, acoshl); }
73 int mpasin(struct t *t) { return mpd1(t, asin); }
74 int mpasinf(struct t *t) { return mpf1(t, asinf); }
75 int mpasinl(struct t *t) { return mpl1(t, asinl); }
76 int mpasinh(struct t *t) { return mpd1(t, asinh); }
77 int mpasinhf(struct t *t) { return mpf1(t, asinhf); }
78 int mpasinhl(struct t *t) { return mpl1(t, asinhl); }
79 int mpatan(struct t *t) { return mpd1(t, atan); }
80 int mpatanf(struct t *t) { return mpf1(t, atanf); }
81 int mpatanl(struct t *t) { return mpl1(t, atanl); }
82 int mpatan2(struct t *t) { return mpd2(t, atan2); }
83 int mpatan2f(struct t *t) { return mpf2(t, atan2f); }
84 int mpatan2l(struct t *t) { return mpl2(t, atan2l); }
85 int mpatanh(struct t *t) { return mpd1(t, atanh); }
86 int mpatanhf(struct t *t) { return mpf1(t, atanhf); }
87 int mpatanhl(struct t *t) { return mpl1(t, atanhl); }
88 int mpcbrt(struct t *t) { return mpd1(t, cbrt); }
89 int mpcbrtf(struct t *t) { return mpf1(t, cbrtf); }
90 int mpcbrtl(struct t *t) { return mpl1(t, cbrtl); }
91 int mpceil(struct t *t) { return mpd1(t, ceil); }
92 int mpceilf(struct t *t) { return mpf1(t, ceilf); }
93 int mpceill(struct t *t) { return mpl1(t, ceill); }
94 int mpcopysign(struct t *t) { return mpd2(t, copysign); }
95 int mpcopysignf(struct t *t) { return mpf2(t, copysignf); }
96 int mpcopysignl(struct t *t) { return mpl2(t, copysignl); }
97 int mpcos(struct t *t) { return mpd1(t, cos); }
98 int mpcosf(struct t *t) { return mpf1(t, cosf); }
99 int mpcosl(struct t *t) { return mpl1(t, cosl); }
100 int mpcosh(struct t *t) { return mpd1(t, cosh); }
101 int mpcoshf(struct t *t) { return mpf1(t, coshf); }
102 int mpcoshl(struct t *t) { return mpl1(t, coshl); }
103 int mperf(struct t *t) { return mpd1(t, erf); }
104 int mperff(struct t *t) { return mpf1(t, erff); }
105 int mperfl(struct t *t) { return mpl1(t, erfl); }
106 int mperfc(struct t *t) { return mpd1(t, erfc); }
107 int mperfcf(struct t *t) { return mpf1(t, erfcf); }
108 int mperfcl(struct t *t) { return mpl1(t, erfcl); }
109 int mpexp(struct t *t) { return mpd1(t, exp); }
110 int mpexpf(struct t *t) { return mpf1(t, expf); }
111 int mpexpl(struct t *t) { return mpl1(t, expl); }
112 int mpexp2(struct t *t) { return mpd1(t, exp2); }
113 int mpexp2f(struct t *t) { return mpf1(t, exp2f); }
114 int mpexp2l(struct t *t) { return mpl1(t, exp2l); }
115 int mpexpm1(struct t *t) { return mpd1(t, expm1); }
116 int mpexpm1f(struct t *t) { return mpf1(t, expm1f); }
117 int mpexpm1l(struct t *t) { return mpl1(t, expm1l); }
118 int mpfabs(struct t *t) { return mpd1(t, fabs); }
119 int mpfabsf(struct t *t) { return mpf1(t, fabsf); }
120 int mpfabsl(struct t *t) { return mpl1(t, fabsl); }
121 int mpfdim(struct t *t) { return mpd2(t, fdim); }
122 int mpfdimf(struct t *t) { return mpf2(t, fdimf); }
123 int mpfdiml(struct t *t) { return mpl2(t, fdiml); }
124 int mpfloor(struct t *t) { return mpd1(t, floor); }
125 int mpfloorf(struct t *t) { return mpf1(t, floorf); }
126 int mpfloorl(struct t *t) { return mpl1(t, floorl); }
127 int mpfmax(struct t *t) { return mpd2(t, fmax); }
128 int mpfmaxf(struct t *t) { return mpf2(t, fmaxf); }
129 int mpfmaxl(struct t *t) { return mpl2(t, fmaxl); }
130 int mpfmin(struct t *t) { return mpd2(t, fmin); }
131 int mpfminf(struct t *t) { return mpf2(t, fminf); }
132 int mpfminl(struct t *t) { return mpl2(t, fminl); }
133 int mpfmod(struct t *t) { return mpd2(t, fmod); }
134 int mpfmodf(struct t *t) { return mpf2(t, fmodf); }
135 int mpfmodl(struct t *t) { return mpl2(t, fmodl); }
136 int mphypot(struct t *t) { return mpd2(t, hypot); }
137 int mphypotf(struct t *t) { return mpf2(t, hypotf); }
138 int mphypotl(struct t *t) { return mpl2(t, hypotl); }
139 int mplog(struct t *t) { return mpd1(t, log); }
140 int mplogf(struct t *t) { return mpf1(t, logf); }
141 int mplogl(struct t *t) { return mpl1(t, logl); }
142 int mplog10(struct t *t) { return mpd1(t, log10); }
143 int mplog10f(struct t *t) { return mpf1(t, log10f); }
144 int mplog10l(struct t *t) { return mpl1(t, log10l); }
145 int mplog1p(struct t *t) { return mpd1(t, log1p); }
146 int mplog1pf(struct t *t) { return mpf1(t, log1pf); }
147 int mplog1pl(struct t *t) { return mpl1(t, log1pl); }
148 int mplog2(struct t *t) { return mpd1(t, log2); }
149 int mplog2f(struct t *t) { return mpf1(t, log2f); }
150 int mplog2l(struct t *t) { return mpl1(t, log2l); }
151 int mplogb(struct t *t) { return mpd1(t, logb); }
152 int mplogbf(struct t *t) { return mpf1(t, logbf); }
153 int mplogbl(struct t *t) { return mpl1(t, logbl); }
154 int mpnearbyint(struct t *t) { return mpd1(t, nearbyint); }
155 int mpnearbyintf(struct t *t) { return mpf1(t, nearbyintf); }
156 int mpnearbyintl(struct t *t) { return mpl1(t, nearbyintl); }
157 int mpnextafter(struct t *t) { return mpd2(t, nextafter); }
158 int mpnextafterf(struct t *t) { return mpf2(t, nextafterf); }
159 int mpnextafterl(struct t *t) { return mpl2(t, nextafterl); }
160 int mpnexttoward(struct t *t)
161 {
162         feclearexcept(FE_ALL_EXCEPT);
163         t->y = nexttoward(t->x, t->x2);
164         t->e = getexcept();
165         t->dy = 0;
166         return 0;
167 }
168 int mpnexttowardf(struct t *t)
169 {
170         feclearexcept(FE_ALL_EXCEPT);
171         t->y = nexttowardf(t->x, t->x2);
172         t->e = getexcept();
173         t->dy = 0;
174         return 0;
175 }
176 int mpnexttowardl(struct t *t) { return mpl2(t, nexttowardl); }
177 int mppow(struct t *t) { return mpd2(t, pow); }
178 int mppowf(struct t *t) { return mpf2(t, powf); }
179 int mppowl(struct t *t) { return mpl2(t, powl); }
180 int mpremainder(struct t *t) { return mpd2(t, remainder); }
181 int mpremainderf(struct t *t) { return mpf2(t, remainderf); }
182 int mpremainderl(struct t *t) { return mpl2(t, remainderl); }
183 int mprint(struct t *t) { return mpd1(t, rint); }
184 int mprintf(struct t *t) { return mpf1(t, rintf); }
185 int mprintl(struct t *t) { return mpl1(t, rintl); }
186 int mpround(struct t *t) { return mpd1(t, round); }
187 int mproundf(struct t *t) { return mpf1(t, roundf); }
188 int mproundl(struct t *t) { return mpl1(t, roundl); }
189 int mpsin(struct t *t) { return mpd1(t, sin); }
190 int mpsinf(struct t *t) { return mpf1(t, sinf); }
191 int mpsinl(struct t *t) { return mpl1(t, sinl); }
192 int mpsinh(struct t *t) { return mpd1(t, sinh); }
193 int mpsinhf(struct t *t) { return mpf1(t, sinhf); }
194 int mpsinhl(struct t *t) { return mpl1(t, sinhl); }
195 int mpsqrt(struct t *t) { return mpd1(t, sqrt); }
196 int mpsqrtf(struct t *t) { return mpf1(t, sqrtf); }
197 int mpsqrtl(struct t *t) { return mpl1(t, sqrtl); }
198 int mptan(struct t *t) { return mpd1(t, tan); }
199 int mptanf(struct t *t) { return mpf1(t, tanf); }
200 int mptanl(struct t *t) { return mpl1(t, tanl); }
201 int mptanh(struct t *t) { return mpd1(t, tanh); }
202 int mptanhf(struct t *t) { return mpf1(t, tanhf); }
203 int mptanhl(struct t *t) { return mpl1(t, tanhl); }
204 int mptgamma(struct t *t) { return mpd1(t, tgamma); }
205 int mptgammaf(struct t *t) { return mpf1(t, tgammaf); }
206 int mptgammal(struct t *t) { return mpl1(t, tgammal); }
207 int mptrunc(struct t *t) { return mpd1(t, trunc); }
208 int mptruncf(struct t *t) { return mpf1(t, truncf); }
209 int mptruncl(struct t *t) { return mpl1(t, truncl); }
210 int mpj0(struct t *t) { return mpd1(t, j0); }
211 int mpj1(struct t *t) { return mpd1(t, j1); }
212 int mpy0(struct t *t) { return mpd1(t, y0); }
213 int mpy1(struct t *t) { return mpd1(t, y1); }
214 int mpscalb(struct t *t) { return mpd2(t, scalb); }
215 int mpscalbf(struct t *t) { return mpf2(t, scalbf); }
216 int mpj0f(struct t *t) { return mpf1(t, j0f); }
217 int mpj0l(struct t *t) { return -1;}//mpl1(t, j0l); }
218 int mpj1f(struct t *t) { return mpf1(t, j1f); }
219 int mpj1l(struct t *t) { return -1;}//mpl1(t, j1l); }
220 int mpy0f(struct t *t) { return mpf1(t, y0f); }
221 int mpy0l(struct t *t) { return -1;}//mpl1(t, y0l); }
222 int mpy1f(struct t *t) { return mpf1(t, y1f); }
223 int mpy1l(struct t *t) { return -1;}//mpl1(t, y1l); }
224 int mpexp10(struct t *t) { return mpd1(t, exp10); }
225 int mpexp10f(struct t *t) { return mpf1(t, exp10f); }
226 int mpexp10l(struct t *t) { return mpl1(t, exp10l); }
227 int mppow10(struct t *t) { return mpd1(t, pow10); }
228 int mppow10f(struct t *t) { return mpf1(t, pow10f); }
229 int mppow10l(struct t *t) { return mpl1(t, pow10l); }
230
231 #define mp_fi_f(n) \
232 int mp##n(struct t *t) \
233 { \
234         t->dy = 0; \
235         setupfenv(t->r); \
236         t->y = n(t->x, t->i); \
237         t->e = getexcept(); \
238         return 0; \
239 }
240
241 mp_fi_f(ldexp)
242 mp_fi_f(ldexpf)
243 mp_fi_f(ldexpl)
244 mp_fi_f(scalbn)
245 mp_fi_f(scalbnf)
246 mp_fi_f(scalbnl)
247 mp_fi_f(scalbln)
248 mp_fi_f(scalblnf)
249 mp_fi_f(scalblnl)
250
251 #define mp_f_fi(n) \
252 int mp##n(struct t *t) \
253 { \
254         int i; \
255         t->dy = 0; \
256         setupfenv(t->r); \
257         t->y = n(t->x, &i); \
258         t->e = getexcept(); \
259         t->i = i; \
260         return 0; \
261 }
262
263 mp_f_fi(frexp)
264 mp_f_fi(frexpf)
265 mp_f_fi(frexpl)
266 mp_f_fi(lgamma_r)
267 mp_f_fi(lgammaf_r)
268 mp_f_fi(lgammal_r)
269
270 int mplgamma(struct t *t)
271 {
272         t->dy = 0;
273         setupfenv(t->r);
274         t->y = lgamma(t->x);
275         t->e = getexcept();
276         t->i = signgam;
277         return 0;
278 }
279
280 int mplgammaf(struct t *t)
281 {
282         t->dy = 0;
283         setupfenv(t->r);
284         t->y = lgammaf(t->x);
285         t->e = getexcept();
286         t->i = signgam;
287         return 0;
288 }
289
290 int mplgammal(struct t *t)
291 {
292         t->dy = 0;
293         setupfenv(t->r);
294         t->y = lgammal(t->x);
295         t->e = getexcept();
296         t->i = signgam;
297         return 0;
298 }
299
300 #define mp_f_i(n) \
301 int mp##n(struct t *t) \
302 { \
303         setupfenv(t->r); \
304         t->i = n(t->x); \
305         t->e = getexcept(); \
306         return 0; \
307 }
308
309 mp_f_i(ilogb)
310 mp_f_i(ilogbf)
311 mp_f_i(ilogbl)
312 mp_f_i(llrint)
313 mp_f_i(llrintf)
314 mp_f_i(llrintl)
315 mp_f_i(lrint)
316 mp_f_i(lrintf)
317 mp_f_i(lrintl)
318 mp_f_i(llround)
319 mp_f_i(llroundf)
320 mp_f_i(llroundl)
321 mp_f_i(lround)
322 mp_f_i(lroundf)
323 mp_f_i(lroundl)
324
325 int mpmodf(struct t *t)
326 {
327         double y2;
328
329         t->dy = t->dy2 = 0;
330         setupfenv(t->r);
331         t->y = modf(t->x, &y2);
332         t->y2 = y2;
333         t->e = getexcept();
334         return 0;
335 }
336
337 int mpmodff(struct t *t)
338 {
339         float y2;
340
341         t->dy = t->dy2 = 0;
342         setupfenv(t->r);
343         t->y = modff(t->x, &y2);
344         t->y2 = y2;
345         t->e = getexcept();
346         return 0;
347 }
348
349 int mpmodfl(struct t *t)
350 {
351         t->dy = t->dy2 = 0;
352         setupfenv(t->r);
353         t->y = modfl(t->x, &t->y2);
354         t->e = getexcept();
355         return 0;
356 }
357
358 int mpsincos(struct t *t)
359 {
360         double y, y2;
361
362         t->dy = t->dy2 = 0;
363         setupfenv(t->r);
364         sincos(t->x, &y, &y2);
365         t->y = y;
366         t->y2 = y2;
367         t->e = getexcept();
368         return 0;
369 }
370
371 int mpsincosf(struct t *t)
372 {
373         float y, y2;
374
375         t->dy = t->dy2 = 0;
376         setupfenv(t->r);
377         sincosf(t->x, &y, &y2);
378         t->y = y;
379         t->y2 = y2;
380         t->e = getexcept();
381         return 0;
382 }
383
384 int mpsincosl(struct t *t)
385 {
386         t->dy = t->dy2 = 0;
387         setupfenv(t->r);
388         sincosl(t->x, &t->y, &t->y2);
389         t->e = getexcept();
390         return 0;
391 }
392
393 #define mp_ff_fi(n) \
394 int mp##n(struct t *t) \
395 { \
396         int i; \
397         t->dy = 0; \
398         setupfenv(t->r); \
399         t->y = n(t->x, t->x2, &i); \
400         t->e = getexcept(); \
401         t->i = i; \
402         return 0; \
403 }
404
405 mp_ff_fi(remquo)
406 mp_ff_fi(remquof)
407 mp_ff_fi(remquol)
408
409 #define mp_fff_f(n) \
410 int mp##n(struct t *t) \
411 { \
412         t->dy = 0; \
413         setupfenv(t->r); \
414         t->y = n(t->x, t->x2, t->x3); \
415         t->e = getexcept(); \
416         return 0; \
417 }
418
419 mp_fff_f(fma)
420 mp_fff_f(fmaf)
421 mp_fff_f(fmal)
422
423 #define mp_if_f(n) \
424 int mp##n(struct t *t) \
425 { \
426         t->dy = 0; \
427         setupfenv(t->r); \
428         t->y = n(t->i, t->x); \
429         t->e = getexcept(); \
430         return 0; \
431 }
432
433 mp_if_f(jn)
434 mp_if_f(jnf)
435 //mp_if_f(jnl)
436 mp_if_f(yn)
437 mp_if_f(ynf)
438 //mp_if_f(ynl)
439