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