1 /*===---- tgmath.h - Standard header for type generic math ----------------===*\ 2 * 3 * Copyright (c) 2009 Howard Hinnant 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * THE SOFTWARE. 22 * 23 \*===----------------------------------------------------------------------===*/ 24 25 #ifndef __TGMATH_H 26 #define __TGMATH_H 27 28 /* C99 7.22 Type-generic math <tgmath.h>. */ 29 #include <math.h> 30 31 /* C++ handles type genericity with overloading in math.h. */ 32 #ifndef __cplusplus 33 #include <complex.h> 34 35 #define _TG_ATTRSp __attribute__((__overloadable__)) 36 #define _TG_ATTRS __attribute__((__overloadable__, __always_inline__)) 37 38 // promotion 39 40 typedef void _Argument_type_is_not_arithmetic; 41 static _Argument_type_is_not_arithmetic __tg_promote(...) 42 __attribute__((__unavailable__,__overloadable__)); 43 static double _TG_ATTRSp __tg_promote(int); 44 static double _TG_ATTRSp __tg_promote(unsigned int); 45 static double _TG_ATTRSp __tg_promote(long); 46 static double _TG_ATTRSp __tg_promote(unsigned long); 47 static double _TG_ATTRSp __tg_promote(long long); 48 static double _TG_ATTRSp __tg_promote(unsigned long long); 49 static float _TG_ATTRSp __tg_promote(float); 50 static double _TG_ATTRSp __tg_promote(double); 51 static long double _TG_ATTRSp __tg_promote(long double); 52 static float _Complex _TG_ATTRSp __tg_promote(float _Complex); 53 static double _Complex _TG_ATTRSp __tg_promote(double _Complex); 54 static long double _Complex _TG_ATTRSp __tg_promote(long double _Complex); 55 56 #define __tg_promote1(__x) (__typeof__(__tg_promote(__x))) 57 #define __tg_promote2(__x, __y) (__typeof__(__tg_promote(__x) + \ 58 __tg_promote(__y))) 59 #define __tg_promote3(__x, __y, __z) (__typeof__(__tg_promote(__x) + \ 60 __tg_promote(__y) + \ 61 __tg_promote(__z))) 62 63 // acos 64 65 static float 66 _TG_ATTRS 67 __tg_acos(float __x) {return acosf(__x);} 68 69 static double 70 _TG_ATTRS 71 __tg_acos(double __x) {return acos(__x);} 72 73 static long double 74 _TG_ATTRS 75 __tg_acos(long double __x) {return acosl(__x);} 76 77 static float _Complex 78 _TG_ATTRS 79 __tg_acos(float _Complex __x) {return cacosf(__x);} 80 81 static double _Complex 82 _TG_ATTRS 83 __tg_acos(double _Complex __x) {return cacos(__x);} 84 85 static long double _Complex 86 _TG_ATTRS 87 __tg_acos(long double _Complex __x) {return cacosl(__x);} 88 89 #undef acos 90 #define acos(__x) __tg_acos(__tg_promote1((__x))(__x)) 91 92 // asin 93 94 static float 95 _TG_ATTRS 96 __tg_asin(float __x) {return asinf(__x);} 97 98 static double 99 _TG_ATTRS 100 __tg_asin(double __x) {return asin(__x);} 101 102 static long double 103 _TG_ATTRS 104 __tg_asin(long double __x) {return asinl(__x);} 105 106 static float _Complex 107 _TG_ATTRS 108 __tg_asin(float _Complex __x) {return casinf(__x);} 109 110 static double _Complex 111 _TG_ATTRS 112 __tg_asin(double _Complex __x) {return casin(__x);} 113 114 static long double _Complex 115 _TG_ATTRS 116 __tg_asin(long double _Complex __x) {return casinl(__x);} 117 118 #undef asin 119 #define asin(__x) __tg_asin(__tg_promote1((__x))(__x)) 120 121 // atan 122 123 static float 124 _TG_ATTRS 125 __tg_atan(float __x) {return atanf(__x);} 126 127 static double 128 _TG_ATTRS 129 __tg_atan(double __x) {return atan(__x);} 130 131 static long double 132 _TG_ATTRS 133 __tg_atan(long double __x) {return atanl(__x);} 134 135 static float _Complex 136 _TG_ATTRS 137 __tg_atan(float _Complex __x) {return catanf(__x);} 138 139 static double _Complex 140 _TG_ATTRS 141 __tg_atan(double _Complex __x) {return catan(__x);} 142 143 static long double _Complex 144 _TG_ATTRS 145 __tg_atan(long double _Complex __x) {return catanl(__x);} 146 147 #undef atan 148 #define atan(__x) __tg_atan(__tg_promote1((__x))(__x)) 149 150 // acosh 151 152 static float 153 _TG_ATTRS 154 __tg_acosh(float __x) {return acoshf(__x);} 155 156 static double 157 _TG_ATTRS 158 __tg_acosh(double __x) {return acosh(__x);} 159 160 static long double 161 _TG_ATTRS 162 __tg_acosh(long double __x) {return acoshl(__x);} 163 164 static float _Complex 165 _TG_ATTRS 166 __tg_acosh(float _Complex __x) {return cacoshf(__x);} 167 168 static double _Complex 169 _TG_ATTRS 170 __tg_acosh(double _Complex __x) {return cacosh(__x);} 171 172 static long double _Complex 173 _TG_ATTRS 174 __tg_acosh(long double _Complex __x) {return cacoshl(__x);} 175 176 #undef acosh 177 #define acosh(__x) __tg_acosh(__tg_promote1((__x))(__x)) 178 179 // asinh 180 181 static float 182 _TG_ATTRS 183 __tg_asinh(float __x) {return asinhf(__x);} 184 185 static double 186 _TG_ATTRS 187 __tg_asinh(double __x) {return asinh(__x);} 188 189 static long double 190 _TG_ATTRS 191 __tg_asinh(long double __x) {return asinhl(__x);} 192 193 static float _Complex 194 _TG_ATTRS 195 __tg_asinh(float _Complex __x) {return casinhf(__x);} 196 197 static double _Complex 198 _TG_ATTRS 199 __tg_asinh(double _Complex __x) {return casinh(__x);} 200 201 static long double _Complex 202 _TG_ATTRS 203 __tg_asinh(long double _Complex __x) {return casinhl(__x);} 204 205 #undef asinh 206 #define asinh(__x) __tg_asinh(__tg_promote1((__x))(__x)) 207 208 // atanh 209 210 static float 211 _TG_ATTRS 212 __tg_atanh(float __x) {return atanhf(__x);} 213 214 static double 215 _TG_ATTRS 216 __tg_atanh(double __x) {return atanh(__x);} 217 218 static long double 219 _TG_ATTRS 220 __tg_atanh(long double __x) {return atanhl(__x);} 221 222 static float _Complex 223 _TG_ATTRS 224 __tg_atanh(float _Complex __x) {return catanhf(__x);} 225 226 static double _Complex 227 _TG_ATTRS 228 __tg_atanh(double _Complex __x) {return catanh(__x);} 229 230 static long double _Complex 231 _TG_ATTRS 232 __tg_atanh(long double _Complex __x) {return catanhl(__x);} 233 234 #undef atanh 235 #define atanh(__x) __tg_atanh(__tg_promote1((__x))(__x)) 236 237 // cos 238 239 static float 240 _TG_ATTRS 241 __tg_cos(float __x) {return cosf(__x);} 242 243 static double 244 _TG_ATTRS 245 __tg_cos(double __x) {return cos(__x);} 246 247 static long double 248 _TG_ATTRS 249 __tg_cos(long double __x) {return cosl(__x);} 250 251 static float _Complex 252 _TG_ATTRS 253 __tg_cos(float _Complex __x) {return ccosf(__x);} 254 255 static double _Complex 256 _TG_ATTRS 257 __tg_cos(double _Complex __x) {return ccos(__x);} 258 259 static long double _Complex 260 _TG_ATTRS 261 __tg_cos(long double _Complex __x) {return ccosl(__x);} 262 263 #undef cos 264 #define cos(__x) __tg_cos(__tg_promote1((__x))(__x)) 265 266 // sin 267 268 static float 269 _TG_ATTRS 270 __tg_sin(float __x) {return sinf(__x);} 271 272 static double 273 _TG_ATTRS 274 __tg_sin(double __x) {return sin(__x);} 275 276 static long double 277 _TG_ATTRS 278 __tg_sin(long double __x) {return sinl(__x);} 279 280 static float _Complex 281 _TG_ATTRS 282 __tg_sin(float _Complex __x) {return csinf(__x);} 283 284 static double _Complex 285 _TG_ATTRS 286 __tg_sin(double _Complex __x) {return csin(__x);} 287 288 static long double _Complex 289 _TG_ATTRS 290 __tg_sin(long double _Complex __x) {return csinl(__x);} 291 292 #undef sin 293 #define sin(__x) __tg_sin(__tg_promote1((__x))(__x)) 294 295 // tan 296 297 static float 298 _TG_ATTRS 299 __tg_tan(float __x) {return tanf(__x);} 300 301 static double 302 _TG_ATTRS 303 __tg_tan(double __x) {return tan(__x);} 304 305 static long double 306 _TG_ATTRS 307 __tg_tan(long double __x) {return tanl(__x);} 308 309 static float _Complex 310 _TG_ATTRS 311 __tg_tan(float _Complex __x) {return ctanf(__x);} 312 313 static double _Complex 314 _TG_ATTRS 315 __tg_tan(double _Complex __x) {return ctan(__x);} 316 317 static long double _Complex 318 _TG_ATTRS 319 __tg_tan(long double _Complex __x) {return ctanl(__x);} 320 321 #undef tan 322 #define tan(__x) __tg_tan(__tg_promote1((__x))(__x)) 323 324 // cosh 325 326 static float 327 _TG_ATTRS 328 __tg_cosh(float __x) {return coshf(__x);} 329 330 static double 331 _TG_ATTRS 332 __tg_cosh(double __x) {return cosh(__x);} 333 334 static long double 335 _TG_ATTRS 336 __tg_cosh(long double __x) {return coshl(__x);} 337 338 static float _Complex 339 _TG_ATTRS 340 __tg_cosh(float _Complex __x) {return ccoshf(__x);} 341 342 static double _Complex 343 _TG_ATTRS 344 __tg_cosh(double _Complex __x) {return ccosh(__x);} 345 346 static long double _Complex 347 _TG_ATTRS 348 __tg_cosh(long double _Complex __x) {return ccoshl(__x);} 349 350 #undef cosh 351 #define cosh(__x) __tg_cosh(__tg_promote1((__x))(__x)) 352 353 // sinh 354 355 static float 356 _TG_ATTRS 357 __tg_sinh(float __x) {return sinhf(__x);} 358 359 static double 360 _TG_ATTRS 361 __tg_sinh(double __x) {return sinh(__x);} 362 363 static long double 364 _TG_ATTRS 365 __tg_sinh(long double __x) {return sinhl(__x);} 366 367 static float _Complex 368 _TG_ATTRS 369 __tg_sinh(float _Complex __x) {return csinhf(__x);} 370 371 static double _Complex 372 _TG_ATTRS 373 __tg_sinh(double _Complex __x) {return csinh(__x);} 374 375 static long double _Complex 376 _TG_ATTRS 377 __tg_sinh(long double _Complex __x) {return csinhl(__x);} 378 379 #undef sinh 380 #define sinh(__x) __tg_sinh(__tg_promote1((__x))(__x)) 381 382 // tanh 383 384 static float 385 _TG_ATTRS 386 __tg_tanh(float __x) {return tanhf(__x);} 387 388 static double 389 _TG_ATTRS 390 __tg_tanh(double __x) {return tanh(__x);} 391 392 static long double 393 _TG_ATTRS 394 __tg_tanh(long double __x) {return tanhl(__x);} 395 396 static float _Complex 397 _TG_ATTRS 398 __tg_tanh(float _Complex __x) {return ctanhf(__x);} 399 400 static double _Complex 401 _TG_ATTRS 402 __tg_tanh(double _Complex __x) {return ctanh(__x);} 403 404 static long double _Complex 405 _TG_ATTRS 406 __tg_tanh(long double _Complex __x) {return ctanhl(__x);} 407 408 #undef tanh 409 #define tanh(__x) __tg_tanh(__tg_promote1((__x))(__x)) 410 411 // exp 412 413 static float 414 _TG_ATTRS 415 __tg_exp(float __x) {return expf(__x);} 416 417 static double 418 _TG_ATTRS 419 __tg_exp(double __x) {return exp(__x);} 420 421 static long double 422 _TG_ATTRS 423 __tg_exp(long double __x) {return expl(__x);} 424 425 static float _Complex 426 _TG_ATTRS 427 __tg_exp(float _Complex __x) {return cexpf(__x);} 428 429 static double _Complex 430 _TG_ATTRS 431 __tg_exp(double _Complex __x) {return cexp(__x);} 432 433 static long double _Complex 434 _TG_ATTRS 435 __tg_exp(long double _Complex __x) {return cexpl(__x);} 436 437 #undef exp 438 #define exp(__x) __tg_exp(__tg_promote1((__x))(__x)) 439 440 // log 441 442 static float 443 _TG_ATTRS 444 __tg_log(float __x) {return logf(__x);} 445 446 static double 447 _TG_ATTRS 448 __tg_log(double __x) {return log(__x);} 449 450 static long double 451 _TG_ATTRS 452 __tg_log(long double __x) {return logl(__x);} 453 454 static float _Complex 455 _TG_ATTRS 456 __tg_log(float _Complex __x) {return clogf(__x);} 457 458 static double _Complex 459 _TG_ATTRS 460 __tg_log(double _Complex __x) {return clog(__x);} 461 462 static long double _Complex 463 _TG_ATTRS 464 __tg_log(long double _Complex __x) {return clogl(__x);} 465 466 #undef log 467 #define log(__x) __tg_log(__tg_promote1((__x))(__x)) 468 469 // pow 470 471 static float 472 _TG_ATTRS 473 __tg_pow(float __x, float __y) {return powf(__x, __y);} 474 475 static double 476 _TG_ATTRS 477 __tg_pow(double __x, double __y) {return pow(__x, __y);} 478 479 static long double 480 _TG_ATTRS 481 __tg_pow(long double __x, long double __y) {return powl(__x, __y);} 482 483 static float _Complex 484 _TG_ATTRS 485 __tg_pow(float _Complex __x, float _Complex __y) {return cpowf(__x, __y);} 486 487 static double _Complex 488 _TG_ATTRS 489 __tg_pow(double _Complex __x, double _Complex __y) {return cpow(__x, __y);} 490 491 static long double _Complex 492 _TG_ATTRS 493 __tg_pow(long double _Complex __x, long double _Complex __y) 494 {return cpowl(__x, __y);} 495 496 #undef pow 497 #define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \ 498 __tg_promote2((__x), (__y))(__y)) 499 500 // sqrt 501 502 static float 503 _TG_ATTRS 504 __tg_sqrt(float __x) {return sqrtf(__x);} 505 506 static double 507 _TG_ATTRS 508 __tg_sqrt(double __x) {return sqrt(__x);} 509 510 static long double 511 _TG_ATTRS 512 __tg_sqrt(long double __x) {return sqrtl(__x);} 513 514 static float _Complex 515 _TG_ATTRS 516 __tg_sqrt(float _Complex __x) {return csqrtf(__x);} 517 518 static double _Complex 519 _TG_ATTRS 520 __tg_sqrt(double _Complex __x) {return csqrt(__x);} 521 522 static long double _Complex 523 _TG_ATTRS 524 __tg_sqrt(long double _Complex __x) {return csqrtl(__x);} 525 526 #undef sqrt 527 #define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x)) 528 529 // fabs 530 531 static float 532 _TG_ATTRS 533 __tg_fabs(float __x) {return fabsf(__x);} 534 535 static double 536 _TG_ATTRS 537 __tg_fabs(double __x) {return fabs(__x);} 538 539 static long double 540 _TG_ATTRS 541 __tg_fabs(long double __x) {return fabsl(__x);} 542 543 static float 544 _TG_ATTRS 545 __tg_fabs(float _Complex __x) {return cabsf(__x);} 546 547 static double 548 _TG_ATTRS 549 __tg_fabs(double _Complex __x) {return cabs(__x);} 550 551 static long double 552 _TG_ATTRS 553 __tg_fabs(long double _Complex __x) {return cabsl(__x);} 554 555 #undef fabs 556 #define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x)) 557 558 // atan2 559 560 static float 561 _TG_ATTRS 562 __tg_atan2(float __x, float __y) {return atan2f(__x, __y);} 563 564 static double 565 _TG_ATTRS 566 __tg_atan2(double __x, double __y) {return atan2(__x, __y);} 567 568 static long double 569 _TG_ATTRS 570 __tg_atan2(long double __x, long double __y) {return atan2l(__x, __y);} 571 572 #undef atan2 573 #define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \ 574 __tg_promote2((__x), (__y))(__y)) 575 576 // cbrt 577 578 static float 579 _TG_ATTRS 580 __tg_cbrt(float __x) {return cbrtf(__x);} 581 582 static double 583 _TG_ATTRS 584 __tg_cbrt(double __x) {return cbrt(__x);} 585 586 static long double 587 _TG_ATTRS 588 __tg_cbrt(long double __x) {return cbrtl(__x);} 589 590 #undef cbrt 591 #define cbrt(__x) __tg_cbrt(__tg_promote1((__x))(__x)) 592 593 // ceil 594 595 static float 596 _TG_ATTRS 597 __tg_ceil(float __x) {return ceilf(__x);} 598 599 static double 600 _TG_ATTRS 601 __tg_ceil(double __x) {return ceil(__x);} 602 603 static long double 604 _TG_ATTRS 605 __tg_ceil(long double __x) {return ceill(__x);} 606 607 #undef ceil 608 #define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x)) 609 610 // copysign 611 612 static float 613 _TG_ATTRS 614 __tg_copysign(float __x, float __y) {return copysignf(__x, __y);} 615 616 static double 617 _TG_ATTRS 618 __tg_copysign(double __x, double __y) {return copysign(__x, __y);} 619 620 static long double 621 _TG_ATTRS 622 __tg_copysign(long double __x, long double __y) {return copysignl(__x, __y);} 623 624 #undef copysign 625 #define copysign(__x, __y) __tg_copysign(__tg_promote2((__x), (__y))(__x), \ 626 __tg_promote2((__x), (__y))(__y)) 627 628 // erf 629 630 static float 631 _TG_ATTRS 632 __tg_erf(float __x) {return erff(__x);} 633 634 static double 635 _TG_ATTRS 636 __tg_erf(double __x) {return erf(__x);} 637 638 static long double 639 _TG_ATTRS 640 __tg_erf(long double __x) {return erfl(__x);} 641 642 #undef erf 643 #define erf(__x) __tg_erf(__tg_promote1((__x))(__x)) 644 645 // erfc 646 647 static float 648 _TG_ATTRS 649 __tg_erfc(float __x) {return erfcf(__x);} 650 651 static double 652 _TG_ATTRS 653 __tg_erfc(double __x) {return erfc(__x);} 654 655 static long double 656 _TG_ATTRS 657 __tg_erfc(long double __x) {return erfcl(__x);} 658 659 #undef erfc 660 #define erfc(__x) __tg_erfc(__tg_promote1((__x))(__x)) 661 662 // exp2 663 664 static float 665 _TG_ATTRS 666 __tg_exp2(float __x) {return exp2f(__x);} 667 668 static double 669 _TG_ATTRS 670 __tg_exp2(double __x) {return exp2(__x);} 671 672 static long double 673 _TG_ATTRS 674 __tg_exp2(long double __x) {return exp2l(__x);} 675 676 #undef exp2 677 #define exp2(__x) __tg_exp2(__tg_promote1((__x))(__x)) 678 679 // expm1 680 681 static float 682 _TG_ATTRS 683 __tg_expm1(float __x) {return expm1f(__x);} 684 685 static double 686 _TG_ATTRS 687 __tg_expm1(double __x) {return expm1(__x);} 688 689 static long double 690 _TG_ATTRS 691 __tg_expm1(long double __x) {return expm1l(__x);} 692 693 #undef expm1 694 #define expm1(__x) __tg_expm1(__tg_promote1((__x))(__x)) 695 696 // fdim 697 698 static float 699 _TG_ATTRS 700 __tg_fdim(float __x, float __y) {return fdimf(__x, __y);} 701 702 static double 703 _TG_ATTRS 704 __tg_fdim(double __x, double __y) {return fdim(__x, __y);} 705 706 static long double 707 _TG_ATTRS 708 __tg_fdim(long double __x, long double __y) {return fdiml(__x, __y);} 709 710 #undef fdim 711 #define fdim(__x, __y) __tg_fdim(__tg_promote2((__x), (__y))(__x), \ 712 __tg_promote2((__x), (__y))(__y)) 713 714 // floor 715 716 static float 717 _TG_ATTRS 718 __tg_floor(float __x) {return floorf(__x);} 719 720 static double 721 _TG_ATTRS 722 __tg_floor(double __x) {return floor(__x);} 723 724 static long double 725 _TG_ATTRS 726 __tg_floor(long double __x) {return floorl(__x);} 727 728 #undef floor 729 #define floor(__x) __tg_floor(__tg_promote1((__x))(__x)) 730 731 // fma 732 733 static float 734 _TG_ATTRS 735 __tg_fma(float __x, float __y, float __z) 736 {return fmaf(__x, __y, __z);} 737 738 static double 739 _TG_ATTRS 740 __tg_fma(double __x, double __y, double __z) 741 {return fma(__x, __y, __z);} 742 743 static long double 744 _TG_ATTRS 745 __tg_fma(long double __x,long double __y, long double __z) 746 {return fmal(__x, __y, __z);} 747 748 #undef fma 749 #define fma(__x, __y, __z) \ 750 __tg_fma(__tg_promote3((__x), (__y), (__z))(__x), \ 751 __tg_promote3((__x), (__y), (__z))(__y), \ 752 __tg_promote3((__x), (__y), (__z))(__z)) 753 754 // fmax 755 756 static float 757 _TG_ATTRS 758 __tg_fmax(float __x, float __y) {return fmaxf(__x, __y);} 759 760 static double 761 _TG_ATTRS 762 __tg_fmax(double __x, double __y) {return fmax(__x, __y);} 763 764 static long double 765 _TG_ATTRS 766 __tg_fmax(long double __x, long double __y) {return fmaxl(__x, __y);} 767 768 #undef fmax 769 #define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \ 770 __tg_promote2((__x), (__y))(__y)) 771 772 // fmin 773 774 static float 775 _TG_ATTRS 776 __tg_fmin(float __x, float __y) {return fminf(__x, __y);} 777 778 static double 779 _TG_ATTRS 780 __tg_fmin(double __x, double __y) {return fmin(__x, __y);} 781 782 static long double 783 _TG_ATTRS 784 __tg_fmin(long double __x, long double __y) {return fminl(__x, __y);} 785 786 #undef fmin 787 #define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \ 788 __tg_promote2((__x), (__y))(__y)) 789 790 // fmod 791 792 static float 793 _TG_ATTRS 794 __tg_fmod(float __x, float __y) {return fmodf(__x, __y);} 795 796 static double 797 _TG_ATTRS 798 __tg_fmod(double __x, double __y) {return fmod(__x, __y);} 799 800 static long double 801 _TG_ATTRS 802 __tg_fmod(long double __x, long double __y) {return fmodl(__x, __y);} 803 804 #undef fmod 805 #define fmod(__x, __y) __tg_fmod(__tg_promote2((__x), (__y))(__x), \ 806 __tg_promote2((__x), (__y))(__y)) 807 808 // frexp 809 810 static float 811 _TG_ATTRS 812 __tg_frexp(float __x, int* __y) {return frexpf(__x, __y);} 813 814 static double 815 _TG_ATTRS 816 __tg_frexp(double __x, int* __y) {return frexp(__x, __y);} 817 818 static long double 819 _TG_ATTRS 820 __tg_frexp(long double __x, int* __y) {return frexpl(__x, __y);} 821 822 #undef frexp 823 #define frexp(__x, __y) __tg_frexp(__tg_promote1((__x))(__x), __y) 824 825 // hypot 826 827 static float 828 _TG_ATTRS 829 __tg_hypot(float __x, float __y) {return hypotf(__x, __y);} 830 831 static double 832 _TG_ATTRS 833 __tg_hypot(double __x, double __y) {return hypot(__x, __y);} 834 835 static long double 836 _TG_ATTRS 837 __tg_hypot(long double __x, long double __y) {return hypotl(__x, __y);} 838 839 #undef hypot 840 #define hypot(__x, __y) __tg_hypot(__tg_promote2((__x), (__y))(__x), \ 841 __tg_promote2((__x), (__y))(__y)) 842 843 // ilogb 844 845 static int 846 _TG_ATTRS 847 __tg_ilogb(float __x) {return ilogbf(__x);} 848 849 static int 850 _TG_ATTRS 851 __tg_ilogb(double __x) {return ilogb(__x);} 852 853 static int 854 _TG_ATTRS 855 __tg_ilogb(long double __x) {return ilogbl(__x);} 856 857 #undef ilogb 858 #define ilogb(__x) __tg_ilogb(__tg_promote1((__x))(__x)) 859 860 // ldexp 861 862 static float 863 _TG_ATTRS 864 __tg_ldexp(float __x, int __y) {return ldexpf(__x, __y);} 865 866 static double 867 _TG_ATTRS 868 __tg_ldexp(double __x, int __y) {return ldexp(__x, __y);} 869 870 static long double 871 _TG_ATTRS 872 __tg_ldexp(long double __x, int __y) {return ldexpl(__x, __y);} 873 874 #undef ldexp 875 #define ldexp(__x, __y) __tg_ldexp(__tg_promote1((__x))(__x), __y) 876 877 // lgamma 878 879 static float 880 _TG_ATTRS 881 __tg_lgamma(float __x) {return lgammaf(__x);} 882 883 static double 884 _TG_ATTRS 885 __tg_lgamma(double __x) {return lgamma(__x);} 886 887 static long double 888 _TG_ATTRS 889 __tg_lgamma(long double __x) {return lgammal(__x);} 890 891 #undef lgamma 892 #define lgamma(__x) __tg_lgamma(__tg_promote1((__x))(__x)) 893 894 // llrint 895 896 static long long 897 _TG_ATTRS 898 __tg_llrint(float __x) {return llrintf(__x);} 899 900 static long long 901 _TG_ATTRS 902 __tg_llrint(double __x) {return llrint(__x);} 903 904 static long long 905 _TG_ATTRS 906 __tg_llrint(long double __x) {return llrintl(__x);} 907 908 #undef llrint 909 #define llrint(__x) __tg_llrint(__tg_promote1((__x))(__x)) 910 911 // llround 912 913 static long long 914 _TG_ATTRS 915 __tg_llround(float __x) {return llroundf(__x);} 916 917 static long long 918 _TG_ATTRS 919 __tg_llround(double __x) {return llround(__x);} 920 921 static long long 922 _TG_ATTRS 923 __tg_llround(long double __x) {return llroundl(__x);} 924 925 #undef llround 926 #define llround(__x) __tg_llround(__tg_promote1((__x))(__x)) 927 928 // log10 929 930 static float 931 _TG_ATTRS 932 __tg_log10(float __x) {return log10f(__x);} 933 934 static double 935 _TG_ATTRS 936 __tg_log10(double __x) {return log10(__x);} 937 938 static long double 939 _TG_ATTRS 940 __tg_log10(long double __x) {return log10l(__x);} 941 942 #undef log10 943 #define log10(__x) __tg_log10(__tg_promote1((__x))(__x)) 944 945 // log1p 946 947 static float 948 _TG_ATTRS 949 __tg_log1p(float __x) {return log1pf(__x);} 950 951 static double 952 _TG_ATTRS 953 __tg_log1p(double __x) {return log1p(__x);} 954 955 static long double 956 _TG_ATTRS 957 __tg_log1p(long double __x) {return log1pl(__x);} 958 959 #undef log1p 960 #define log1p(__x) __tg_log1p(__tg_promote1((__x))(__x)) 961 962 // log2 963 964 static float 965 _TG_ATTRS 966 __tg_log2(float __x) {return log2f(__x);} 967 968 static double 969 _TG_ATTRS 970 __tg_log2(double __x) {return log2(__x);} 971 972 static long double 973 _TG_ATTRS 974 __tg_log2(long double __x) {return log2l(__x);} 975 976 #undef log2 977 #define log2(__x) __tg_log2(__tg_promote1((__x))(__x)) 978 979 // logb 980 981 static float 982 _TG_ATTRS 983 __tg_logb(float __x) {return logbf(__x);} 984 985 static double 986 _TG_ATTRS 987 __tg_logb(double __x) {return logb(__x);} 988 989 static long double 990 _TG_ATTRS 991 __tg_logb(long double __x) {return logbl(__x);} 992 993 #undef logb 994 #define logb(__x) __tg_logb(__tg_promote1((__x))(__x)) 995 996 // lrint 997 998 static long 999 _TG_ATTRS 1000 __tg_lrint(float __x) {return lrintf(__x);} 1001 1002 static long 1003 _TG_ATTRS 1004 __tg_lrint(double __x) {return lrint(__x);} 1005 1006 static long 1007 _TG_ATTRS 1008 __tg_lrint(long double __x) {return lrintl(__x);} 1009 1010 #undef lrint 1011 #define lrint(__x) __tg_lrint(__tg_promote1((__x))(__x)) 1012 1013 // lround 1014 1015 static long 1016 _TG_ATTRS 1017 __tg_lround(float __x) {return lroundf(__x);} 1018 1019 static long 1020 _TG_ATTRS 1021 __tg_lround(double __x) {return lround(__x);} 1022 1023 static long 1024 _TG_ATTRS 1025 __tg_lround(long double __x) {return lroundl(__x);} 1026 1027 #undef lround 1028 #define lround(__x) __tg_lround(__tg_promote1((__x))(__x)) 1029 1030 // nearbyint 1031 1032 static float 1033 _TG_ATTRS 1034 __tg_nearbyint(float __x) {return nearbyintf(__x);} 1035 1036 static double 1037 _TG_ATTRS 1038 __tg_nearbyint(double __x) {return nearbyint(__x);} 1039 1040 static long double 1041 _TG_ATTRS 1042 __tg_nearbyint(long double __x) {return nearbyintl(__x);} 1043 1044 #undef nearbyint 1045 #define nearbyint(__x) __tg_nearbyint(__tg_promote1((__x))(__x)) 1046 1047 // nextafter 1048 1049 static float 1050 _TG_ATTRS 1051 __tg_nextafter(float __x, float __y) {return nextafterf(__x, __y);} 1052 1053 static double 1054 _TG_ATTRS 1055 __tg_nextafter(double __x, double __y) {return nextafter(__x, __y);} 1056 1057 static long double 1058 _TG_ATTRS 1059 __tg_nextafter(long double __x, long double __y) {return nextafterl(__x, __y);} 1060 1061 #undef nextafter 1062 #define nextafter(__x, __y) __tg_nextafter(__tg_promote2((__x), (__y))(__x), \ 1063 __tg_promote2((__x), (__y))(__y)) 1064 1065 // nexttoward 1066 1067 static float 1068 _TG_ATTRS 1069 __tg_nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);} 1070 1071 static double 1072 _TG_ATTRS 1073 __tg_nexttoward(double __x, long double __y) {return nexttoward(__x, __y);} 1074 1075 static long double 1076 _TG_ATTRS 1077 __tg_nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);} 1078 1079 #undef nexttoward 1080 #define nexttoward(__x, __y) __tg_nexttoward(__tg_promote1((__x))(__x), (__y)) 1081 1082 // remainder 1083 1084 static float 1085 _TG_ATTRS 1086 __tg_remainder(float __x, float __y) {return remainderf(__x, __y);} 1087 1088 static double 1089 _TG_ATTRS 1090 __tg_remainder(double __x, double __y) {return remainder(__x, __y);} 1091 1092 static long double 1093 _TG_ATTRS 1094 __tg_remainder(long double __x, long double __y) {return remainderl(__x, __y);} 1095 1096 #undef remainder 1097 #define remainder(__x, __y) __tg_remainder(__tg_promote2((__x), (__y))(__x), \ 1098 __tg_promote2((__x), (__y))(__y)) 1099 1100 // remquo 1101 1102 static float 1103 _TG_ATTRS 1104 __tg_remquo(float __x, float __y, int* __z) 1105 {return remquof(__x, __y, __z);} 1106 1107 static double 1108 _TG_ATTRS 1109 __tg_remquo(double __x, double __y, int* __z) 1110 {return remquo(__x, __y, __z);} 1111 1112 static long double 1113 _TG_ATTRS 1114 __tg_remquo(long double __x,long double __y, int* __z) 1115 {return remquol(__x, __y, __z);} 1116 1117 #undef remquo 1118 #define remquo(__x, __y, __z) \ 1119 __tg_remquo(__tg_promote2((__x), (__y))(__x), \ 1120 __tg_promote2((__x), (__y))(__y), \ 1121 (__z)) 1122 1123 // rint 1124 1125 static float 1126 _TG_ATTRS 1127 __tg_rint(float __x) {return rintf(__x);} 1128 1129 static double 1130 _TG_ATTRS 1131 __tg_rint(double __x) {return rint(__x);} 1132 1133 static long double 1134 _TG_ATTRS 1135 __tg_rint(long double __x) {return rintl(__x);} 1136 1137 #undef rint 1138 #define rint(__x) __tg_rint(__tg_promote1((__x))(__x)) 1139 1140 // round 1141 1142 static float 1143 _TG_ATTRS 1144 __tg_round(float __x) {return roundf(__x);} 1145 1146 static double 1147 _TG_ATTRS 1148 __tg_round(double __x) {return round(__x);} 1149 1150 static long double 1151 _TG_ATTRS 1152 __tg_round(long double __x) {return roundl(__x);} 1153 1154 #undef round 1155 #define round(__x) __tg_round(__tg_promote1((__x))(__x)) 1156 1157 // scalbn 1158 1159 static float 1160 _TG_ATTRS 1161 __tg_scalbn(float __x, int __y) {return scalbnf(__x, __y);} 1162 1163 static double 1164 _TG_ATTRS 1165 __tg_scalbn(double __x, int __y) {return scalbn(__x, __y);} 1166 1167 static long double 1168 _TG_ATTRS 1169 __tg_scalbn(long double __x, int __y) {return scalbnl(__x, __y);} 1170 1171 #undef scalbn 1172 #define scalbn(__x, __y) __tg_scalbn(__tg_promote1((__x))(__x), __y) 1173 1174 // scalbln 1175 1176 static float 1177 _TG_ATTRS 1178 __tg_scalbln(float __x, long __y) {return scalblnf(__x, __y);} 1179 1180 static double 1181 _TG_ATTRS 1182 __tg_scalbln(double __x, long __y) {return scalbln(__x, __y);} 1183 1184 static long double 1185 _TG_ATTRS 1186 __tg_scalbln(long double __x, long __y) {return scalblnl(__x, __y);} 1187 1188 #undef scalbln 1189 #define scalbln(__x, __y) __tg_scalbln(__tg_promote1((__x))(__x), __y) 1190 1191 // tgamma 1192 1193 static float 1194 _TG_ATTRS 1195 __tg_tgamma(float __x) {return tgammaf(__x);} 1196 1197 static double 1198 _TG_ATTRS 1199 __tg_tgamma(double __x) {return tgamma(__x);} 1200 1201 static long double 1202 _TG_ATTRS 1203 __tg_tgamma(long double __x) {return tgammal(__x);} 1204 1205 #undef tgamma 1206 #define tgamma(__x) __tg_tgamma(__tg_promote1((__x))(__x)) 1207 1208 // trunc 1209 1210 static float 1211 _TG_ATTRS 1212 __tg_trunc(float __x) {return truncf(__x);} 1213 1214 static double 1215 _TG_ATTRS 1216 __tg_trunc(double __x) {return trunc(__x);} 1217 1218 static long double 1219 _TG_ATTRS 1220 __tg_trunc(long double __x) {return truncl(__x);} 1221 1222 #undef trunc 1223 #define trunc(__x) __tg_trunc(__tg_promote1((__x))(__x)) 1224 1225 // carg 1226 1227 static float 1228 _TG_ATTRS 1229 __tg_carg(float __x) {return atan2f(0.F, __x);} 1230 1231 static double 1232 _TG_ATTRS 1233 __tg_carg(double __x) {return atan2(0., __x);} 1234 1235 static long double 1236 _TG_ATTRS 1237 __tg_carg(long double __x) {return atan2l(0.L, __x);} 1238 1239 static float 1240 _TG_ATTRS 1241 __tg_carg(float _Complex __x) {return cargf(__x);} 1242 1243 static double 1244 _TG_ATTRS 1245 __tg_carg(double _Complex __x) {return carg(__x);} 1246 1247 static long double 1248 _TG_ATTRS 1249 __tg_carg(long double _Complex __x) {return cargl(__x);} 1250 1251 #undef carg 1252 #define carg(__x) __tg_carg(__tg_promote1((__x))(__x)) 1253 1254 // cimag 1255 1256 static float 1257 _TG_ATTRS 1258 __tg_cimag(float __x) {return 0;} 1259 1260 static double 1261 _TG_ATTRS 1262 __tg_cimag(double __x) {return 0;} 1263 1264 static long double 1265 _TG_ATTRS 1266 __tg_cimag(long double __x) {return 0;} 1267 1268 static float 1269 _TG_ATTRS 1270 __tg_cimag(float _Complex __x) {return cimagf(__x);} 1271 1272 static double 1273 _TG_ATTRS 1274 __tg_cimag(double _Complex __x) {return cimag(__x);} 1275 1276 static long double 1277 _TG_ATTRS 1278 __tg_cimag(long double _Complex __x) {return cimagl(__x);} 1279 1280 #undef cimag 1281 #define cimag(__x) __tg_cimag(__tg_promote1((__x))(__x)) 1282 1283 // conj 1284 1285 static float _Complex 1286 _TG_ATTRS 1287 __tg_conj(float __x) {return __x;} 1288 1289 static double _Complex 1290 _TG_ATTRS 1291 __tg_conj(double __x) {return __x;} 1292 1293 static long double _Complex 1294 _TG_ATTRS 1295 __tg_conj(long double __x) {return __x;} 1296 1297 static float _Complex 1298 _TG_ATTRS 1299 __tg_conj(float _Complex __x) {return conjf(__x);} 1300 1301 static double _Complex 1302 _TG_ATTRS 1303 __tg_conj(double _Complex __x) {return conj(__x);} 1304 1305 static long double _Complex 1306 _TG_ATTRS 1307 __tg_conj(long double _Complex __x) {return conjl(__x);} 1308 1309 #undef conj 1310 #define conj(__x) __tg_conj(__tg_promote1((__x))(__x)) 1311 1312 // cproj 1313 1314 static float _Complex 1315 _TG_ATTRS 1316 __tg_cproj(float __x) {return cprojf(__x);} 1317 1318 static double _Complex 1319 _TG_ATTRS 1320 __tg_cproj(double __x) {return cproj(__x);} 1321 1322 static long double _Complex 1323 _TG_ATTRS 1324 __tg_cproj(long double __x) {return cprojl(__x);} 1325 1326 static float _Complex 1327 _TG_ATTRS 1328 __tg_cproj(float _Complex __x) {return cprojf(__x);} 1329 1330 static double _Complex 1331 _TG_ATTRS 1332 __tg_cproj(double _Complex __x) {return cproj(__x);} 1333 1334 static long double _Complex 1335 _TG_ATTRS 1336 __tg_cproj(long double _Complex __x) {return cprojl(__x);} 1337 1338 #undef cproj 1339 #define cproj(__x) __tg_cproj(__tg_promote1((__x))(__x)) 1340 1341 // creal 1342 1343 static float 1344 _TG_ATTRS 1345 __tg_creal(float __x) {return __x;} 1346 1347 static double 1348 _TG_ATTRS 1349 __tg_creal(double __x) {return __x;} 1350 1351 static long double 1352 _TG_ATTRS 1353 __tg_creal(long double __x) {return __x;} 1354 1355 static float 1356 _TG_ATTRS 1357 __tg_creal(float _Complex __x) {return crealf(__x);} 1358 1359 static double 1360 _TG_ATTRS 1361 __tg_creal(double _Complex __x) {return creal(__x);} 1362 1363 static long double 1364 _TG_ATTRS 1365 __tg_creal(long double _Complex __x) {return creall(__x);} 1366 1367 #undef creal 1368 #define creal(__x) __tg_creal(__tg_promote1((__x))(__x)) 1369 1370 #undef _TG_ATTRSp 1371 #undef _TG_ATTRS 1372 1373 #endif /* __cplusplus */ 1374 #endif /* __TGMATH_H */ 1375