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