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