1369 lines · c
1/*===---- tgmath.h - Standard header for type generic math ----------------===*\2 *3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4 * See https://llvm.org/LICENSE.txt for license information.5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6 *7\*===----------------------------------------------------------------------===*/8 9#ifndef __CLANG_TGMATH_H10#define __CLANG_TGMATH_H11 12/* C99 7.22 Type-generic math <tgmath.h>. */13#include <math.h>14 15/*16 * Allow additional definitions and implementation-defined values on Apple17 * platforms. This is done after #include <math.h> to avoid depcycle conflicts18 * between libcxx and darwin in C++ modules builds.19 */20#if defined(__APPLE__) && __STDC_HOSTED__ && __has_include_next(<tgmath.h>)21# include_next <tgmath.h>22#else23 24/* C++ handles type genericity with overloading in math.h. */25#ifndef __cplusplus26#include <complex.h>27 28#define _TG_ATTRSp __attribute__((__overloadable__))29#define _TG_ATTRS __attribute__((__overloadable__, __always_inline__))30 31// promotion32 33typedef void _Argument_type_is_not_arithmetic;34static _Argument_type_is_not_arithmetic __tg_promote(...)35 __attribute__((__unavailable__,__overloadable__));36static double _TG_ATTRSp __tg_promote(int);37static double _TG_ATTRSp __tg_promote(unsigned int);38static double _TG_ATTRSp __tg_promote(long);39static double _TG_ATTRSp __tg_promote(unsigned long);40static double _TG_ATTRSp __tg_promote(long long);41static double _TG_ATTRSp __tg_promote(unsigned long long);42static float _TG_ATTRSp __tg_promote(float);43static double _TG_ATTRSp __tg_promote(double);44static long double _TG_ATTRSp __tg_promote(long double);45static float _Complex _TG_ATTRSp __tg_promote(float _Complex);46static double _Complex _TG_ATTRSp __tg_promote(double _Complex);47static long double _Complex _TG_ATTRSp __tg_promote(long double _Complex);48 49#define __tg_promote1(__x) (__typeof__(__tg_promote(__x)))50#define __tg_promote2(__x, __y) (__typeof__(__tg_promote(__x) + \51 __tg_promote(__y)))52#define __tg_promote3(__x, __y, __z) (__typeof__(__tg_promote(__x) + \53 __tg_promote(__y) + \54 __tg_promote(__z)))55 56// acos57 58static float59 _TG_ATTRS60 __tg_acos(float __x) {return acosf(__x);}61 62static double63 _TG_ATTRS64 __tg_acos(double __x) {return acos(__x);}65 66static long double67 _TG_ATTRS68 __tg_acos(long double __x) {return acosl(__x);}69 70static float _Complex71 _TG_ATTRS72 __tg_acos(float _Complex __x) {return cacosf(__x);}73 74static double _Complex75 _TG_ATTRS76 __tg_acos(double _Complex __x) {return cacos(__x);}77 78static long double _Complex79 _TG_ATTRS80 __tg_acos(long double _Complex __x) {return cacosl(__x);}81 82#undef acos83#define acos(__x) __tg_acos(__tg_promote1((__x))(__x))84 85// asin86 87static float88 _TG_ATTRS89 __tg_asin(float __x) {return asinf(__x);}90 91static double92 _TG_ATTRS93 __tg_asin(double __x) {return asin(__x);}94 95static long double96 _TG_ATTRS97 __tg_asin(long double __x) {return asinl(__x);}98 99static float _Complex100 _TG_ATTRS101 __tg_asin(float _Complex __x) {return casinf(__x);}102 103static double _Complex104 _TG_ATTRS105 __tg_asin(double _Complex __x) {return casin(__x);}106 107static long double _Complex108 _TG_ATTRS109 __tg_asin(long double _Complex __x) {return casinl(__x);}110 111#undef asin112#define asin(__x) __tg_asin(__tg_promote1((__x))(__x))113 114// atan115 116static float117 _TG_ATTRS118 __tg_atan(float __x) {return atanf(__x);}119 120static double121 _TG_ATTRS122 __tg_atan(double __x) {return atan(__x);}123 124static long double125 _TG_ATTRS126 __tg_atan(long double __x) {return atanl(__x);}127 128static float _Complex129 _TG_ATTRS130 __tg_atan(float _Complex __x) {return catanf(__x);}131 132static double _Complex133 _TG_ATTRS134 __tg_atan(double _Complex __x) {return catan(__x);}135 136static long double _Complex137 _TG_ATTRS138 __tg_atan(long double _Complex __x) {return catanl(__x);}139 140#undef atan141#define atan(__x) __tg_atan(__tg_promote1((__x))(__x))142 143// acosh144 145static float146 _TG_ATTRS147 __tg_acosh(float __x) {return acoshf(__x);}148 149static double150 _TG_ATTRS151 __tg_acosh(double __x) {return acosh(__x);}152 153static long double154 _TG_ATTRS155 __tg_acosh(long double __x) {return acoshl(__x);}156 157static float _Complex158 _TG_ATTRS159 __tg_acosh(float _Complex __x) {return cacoshf(__x);}160 161static double _Complex162 _TG_ATTRS163 __tg_acosh(double _Complex __x) {return cacosh(__x);}164 165static long double _Complex166 _TG_ATTRS167 __tg_acosh(long double _Complex __x) {return cacoshl(__x);}168 169#undef acosh170#define acosh(__x) __tg_acosh(__tg_promote1((__x))(__x))171 172// asinh173 174static float175 _TG_ATTRS176 __tg_asinh(float __x) {return asinhf(__x);}177 178static double179 _TG_ATTRS180 __tg_asinh(double __x) {return asinh(__x);}181 182static long double183 _TG_ATTRS184 __tg_asinh(long double __x) {return asinhl(__x);}185 186static float _Complex187 _TG_ATTRS188 __tg_asinh(float _Complex __x) {return casinhf(__x);}189 190static double _Complex191 _TG_ATTRS192 __tg_asinh(double _Complex __x) {return casinh(__x);}193 194static long double _Complex195 _TG_ATTRS196 __tg_asinh(long double _Complex __x) {return casinhl(__x);}197 198#undef asinh199#define asinh(__x) __tg_asinh(__tg_promote1((__x))(__x))200 201// atanh202 203static float204 _TG_ATTRS205 __tg_atanh(float __x) {return atanhf(__x);}206 207static double208 _TG_ATTRS209 __tg_atanh(double __x) {return atanh(__x);}210 211static long double212 _TG_ATTRS213 __tg_atanh(long double __x) {return atanhl(__x);}214 215static float _Complex216 _TG_ATTRS217 __tg_atanh(float _Complex __x) {return catanhf(__x);}218 219static double _Complex220 _TG_ATTRS221 __tg_atanh(double _Complex __x) {return catanh(__x);}222 223static long double _Complex224 _TG_ATTRS225 __tg_atanh(long double _Complex __x) {return catanhl(__x);}226 227#undef atanh228#define atanh(__x) __tg_atanh(__tg_promote1((__x))(__x))229 230// cos231 232static float233 _TG_ATTRS234 __tg_cos(float __x) {return cosf(__x);}235 236static double237 _TG_ATTRS238 __tg_cos(double __x) {return cos(__x);}239 240static long double241 _TG_ATTRS242 __tg_cos(long double __x) {return cosl(__x);}243 244static float _Complex245 _TG_ATTRS246 __tg_cos(float _Complex __x) {return ccosf(__x);}247 248static double _Complex249 _TG_ATTRS250 __tg_cos(double _Complex __x) {return ccos(__x);}251 252static long double _Complex253 _TG_ATTRS254 __tg_cos(long double _Complex __x) {return ccosl(__x);}255 256#undef cos257#define cos(__x) __tg_cos(__tg_promote1((__x))(__x))258 259// sin260 261static float262 _TG_ATTRS263 __tg_sin(float __x) {return sinf(__x);}264 265static double266 _TG_ATTRS267 __tg_sin(double __x) {return sin(__x);}268 269static long double270 _TG_ATTRS271 __tg_sin(long double __x) {return sinl(__x);}272 273static float _Complex274 _TG_ATTRS275 __tg_sin(float _Complex __x) {return csinf(__x);}276 277static double _Complex278 _TG_ATTRS279 __tg_sin(double _Complex __x) {return csin(__x);}280 281static long double _Complex282 _TG_ATTRS283 __tg_sin(long double _Complex __x) {return csinl(__x);}284 285#undef sin286#define sin(__x) __tg_sin(__tg_promote1((__x))(__x))287 288// tan289 290static float291 _TG_ATTRS292 __tg_tan(float __x) {return tanf(__x);}293 294static double295 _TG_ATTRS296 __tg_tan(double __x) {return tan(__x);}297 298static long double299 _TG_ATTRS300 __tg_tan(long double __x) {return tanl(__x);}301 302static float _Complex303 _TG_ATTRS304 __tg_tan(float _Complex __x) {return ctanf(__x);}305 306static double _Complex307 _TG_ATTRS308 __tg_tan(double _Complex __x) {return ctan(__x);}309 310static long double _Complex311 _TG_ATTRS312 __tg_tan(long double _Complex __x) {return ctanl(__x);}313 314#undef tan315#define tan(__x) __tg_tan(__tg_promote1((__x))(__x))316 317// cosh318 319static float320 _TG_ATTRS321 __tg_cosh(float __x) {return coshf(__x);}322 323static double324 _TG_ATTRS325 __tg_cosh(double __x) {return cosh(__x);}326 327static long double328 _TG_ATTRS329 __tg_cosh(long double __x) {return coshl(__x);}330 331static float _Complex332 _TG_ATTRS333 __tg_cosh(float _Complex __x) {return ccoshf(__x);}334 335static double _Complex336 _TG_ATTRS337 __tg_cosh(double _Complex __x) {return ccosh(__x);}338 339static long double _Complex340 _TG_ATTRS341 __tg_cosh(long double _Complex __x) {return ccoshl(__x);}342 343#undef cosh344#define cosh(__x) __tg_cosh(__tg_promote1((__x))(__x))345 346// sinh347 348static float349 _TG_ATTRS350 __tg_sinh(float __x) {return sinhf(__x);}351 352static double353 _TG_ATTRS354 __tg_sinh(double __x) {return sinh(__x);}355 356static long double357 _TG_ATTRS358 __tg_sinh(long double __x) {return sinhl(__x);}359 360static float _Complex361 _TG_ATTRS362 __tg_sinh(float _Complex __x) {return csinhf(__x);}363 364static double _Complex365 _TG_ATTRS366 __tg_sinh(double _Complex __x) {return csinh(__x);}367 368static long double _Complex369 _TG_ATTRS370 __tg_sinh(long double _Complex __x) {return csinhl(__x);}371 372#undef sinh373#define sinh(__x) __tg_sinh(__tg_promote1((__x))(__x))374 375// tanh376 377static float378 _TG_ATTRS379 __tg_tanh(float __x) {return tanhf(__x);}380 381static double382 _TG_ATTRS383 __tg_tanh(double __x) {return tanh(__x);}384 385static long double386 _TG_ATTRS387 __tg_tanh(long double __x) {return tanhl(__x);}388 389static float _Complex390 _TG_ATTRS391 __tg_tanh(float _Complex __x) {return ctanhf(__x);}392 393static double _Complex394 _TG_ATTRS395 __tg_tanh(double _Complex __x) {return ctanh(__x);}396 397static long double _Complex398 _TG_ATTRS399 __tg_tanh(long double _Complex __x) {return ctanhl(__x);}400 401#undef tanh402#define tanh(__x) __tg_tanh(__tg_promote1((__x))(__x))403 404// exp405 406static float407 _TG_ATTRS408 __tg_exp(float __x) {return expf(__x);}409 410static double411 _TG_ATTRS412 __tg_exp(double __x) {return exp(__x);}413 414static long double415 _TG_ATTRS416 __tg_exp(long double __x) {return expl(__x);}417 418static float _Complex419 _TG_ATTRS420 __tg_exp(float _Complex __x) {return cexpf(__x);}421 422static double _Complex423 _TG_ATTRS424 __tg_exp(double _Complex __x) {return cexp(__x);}425 426static long double _Complex427 _TG_ATTRS428 __tg_exp(long double _Complex __x) {return cexpl(__x);}429 430#undef exp431#define exp(__x) __tg_exp(__tg_promote1((__x))(__x))432 433// log434 435static float436 _TG_ATTRS437 __tg_log(float __x) {return logf(__x);}438 439static double440 _TG_ATTRS441 __tg_log(double __x) {return log(__x);}442 443static long double444 _TG_ATTRS445 __tg_log(long double __x) {return logl(__x);}446 447static float _Complex448 _TG_ATTRS449 __tg_log(float _Complex __x) {return clogf(__x);}450 451static double _Complex452 _TG_ATTRS453 __tg_log(double _Complex __x) {return clog(__x);}454 455static long double _Complex456 _TG_ATTRS457 __tg_log(long double _Complex __x) {return clogl(__x);}458 459#undef log460#define log(__x) __tg_log(__tg_promote1((__x))(__x))461 462// pow463 464static float465 _TG_ATTRS466 __tg_pow(float __x, float __y) {return powf(__x, __y);}467 468static double469 _TG_ATTRS470 __tg_pow(double __x, double __y) {return pow(__x, __y);}471 472static long double473 _TG_ATTRS474 __tg_pow(long double __x, long double __y) {return powl(__x, __y);}475 476static float _Complex477 _TG_ATTRS478 __tg_pow(float _Complex __x, float _Complex __y) {return cpowf(__x, __y);}479 480static double _Complex481 _TG_ATTRS482 __tg_pow(double _Complex __x, double _Complex __y) {return cpow(__x, __y);}483 484static long double _Complex485 _TG_ATTRS486 __tg_pow(long double _Complex __x, long double _Complex __y)487 {return cpowl(__x, __y);}488 489#undef pow490#define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \491 __tg_promote2((__x), (__y))(__y))492 493// sqrt494 495static float496 _TG_ATTRS497 __tg_sqrt(float __x) {return sqrtf(__x);}498 499static double500 _TG_ATTRS501 __tg_sqrt(double __x) {return sqrt(__x);}502 503static long double504 _TG_ATTRS505 __tg_sqrt(long double __x) {return sqrtl(__x);}506 507static float _Complex508 _TG_ATTRS509 __tg_sqrt(float _Complex __x) {return csqrtf(__x);}510 511static double _Complex512 _TG_ATTRS513 __tg_sqrt(double _Complex __x) {return csqrt(__x);}514 515static long double _Complex516 _TG_ATTRS517 __tg_sqrt(long double _Complex __x) {return csqrtl(__x);}518 519#undef sqrt520#define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x))521 522// fabs523 524static float525 _TG_ATTRS526 __tg_fabs(float __x) {return fabsf(__x);}527 528static double529 _TG_ATTRS530 __tg_fabs(double __x) {return fabs(__x);}531 532static long double533 _TG_ATTRS534 __tg_fabs(long double __x) {return fabsl(__x);}535 536static float537 _TG_ATTRS538 __tg_fabs(float _Complex __x) {return cabsf(__x);}539 540static double541 _TG_ATTRS542 __tg_fabs(double _Complex __x) {return cabs(__x);}543 544static long double545 _TG_ATTRS546 __tg_fabs(long double _Complex __x) {return cabsl(__x);}547 548#undef fabs549#define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x))550 551// atan2552 553static float554 _TG_ATTRS555 __tg_atan2(float __x, float __y) {return atan2f(__x, __y);}556 557static double558 _TG_ATTRS559 __tg_atan2(double __x, double __y) {return atan2(__x, __y);}560 561static long double562 _TG_ATTRS563 __tg_atan2(long double __x, long double __y) {return atan2l(__x, __y);}564 565#undef atan2566#define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \567 __tg_promote2((__x), (__y))(__y))568 569// cbrt570 571static float572 _TG_ATTRS573 __tg_cbrt(float __x) {return cbrtf(__x);}574 575static double576 _TG_ATTRS577 __tg_cbrt(double __x) {return cbrt(__x);}578 579static long double580 _TG_ATTRS581 __tg_cbrt(long double __x) {return cbrtl(__x);}582 583#undef cbrt584#define cbrt(__x) __tg_cbrt(__tg_promote1((__x))(__x))585 586// ceil587 588static float589 _TG_ATTRS590 __tg_ceil(float __x) {return ceilf(__x);}591 592static double593 _TG_ATTRS594 __tg_ceil(double __x) {return ceil(__x);}595 596static long double597 _TG_ATTRS598 __tg_ceil(long double __x) {return ceill(__x);}599 600#undef ceil601#define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x))602 603// copysign604 605static float606 _TG_ATTRS607 __tg_copysign(float __x, float __y) {return copysignf(__x, __y);}608 609static double610 _TG_ATTRS611 __tg_copysign(double __x, double __y) {return copysign(__x, __y);}612 613static long double614 _TG_ATTRS615 __tg_copysign(long double __x, long double __y) {return copysignl(__x, __y);}616 617#undef copysign618#define copysign(__x, __y) __tg_copysign(__tg_promote2((__x), (__y))(__x), \619 __tg_promote2((__x), (__y))(__y))620 621// erf622 623static float624 _TG_ATTRS625 __tg_erf(float __x) {return erff(__x);}626 627static double628 _TG_ATTRS629 __tg_erf(double __x) {return erf(__x);}630 631static long double632 _TG_ATTRS633 __tg_erf(long double __x) {return erfl(__x);}634 635#undef erf636#define erf(__x) __tg_erf(__tg_promote1((__x))(__x))637 638// erfc639 640static float641 _TG_ATTRS642 __tg_erfc(float __x) {return erfcf(__x);}643 644static double645 _TG_ATTRS646 __tg_erfc(double __x) {return erfc(__x);}647 648static long double649 _TG_ATTRS650 __tg_erfc(long double __x) {return erfcl(__x);}651 652#undef erfc653#define erfc(__x) __tg_erfc(__tg_promote1((__x))(__x))654 655// exp2656 657static float658 _TG_ATTRS659 __tg_exp2(float __x) {return exp2f(__x);}660 661static double662 _TG_ATTRS663 __tg_exp2(double __x) {return exp2(__x);}664 665static long double666 _TG_ATTRS667 __tg_exp2(long double __x) {return exp2l(__x);}668 669#undef exp2670#define exp2(__x) __tg_exp2(__tg_promote1((__x))(__x))671 672// expm1673 674static float675 _TG_ATTRS676 __tg_expm1(float __x) {return expm1f(__x);}677 678static double679 _TG_ATTRS680 __tg_expm1(double __x) {return expm1(__x);}681 682static long double683 _TG_ATTRS684 __tg_expm1(long double __x) {return expm1l(__x);}685 686#undef expm1687#define expm1(__x) __tg_expm1(__tg_promote1((__x))(__x))688 689// fdim690 691static float692 _TG_ATTRS693 __tg_fdim(float __x, float __y) {return fdimf(__x, __y);}694 695static double696 _TG_ATTRS697 __tg_fdim(double __x, double __y) {return fdim(__x, __y);}698 699static long double700 _TG_ATTRS701 __tg_fdim(long double __x, long double __y) {return fdiml(__x, __y);}702 703#undef fdim704#define fdim(__x, __y) __tg_fdim(__tg_promote2((__x), (__y))(__x), \705 __tg_promote2((__x), (__y))(__y))706 707// floor708 709static float710 _TG_ATTRS711 __tg_floor(float __x) {return floorf(__x);}712 713static double714 _TG_ATTRS715 __tg_floor(double __x) {return floor(__x);}716 717static long double718 _TG_ATTRS719 __tg_floor(long double __x) {return floorl(__x);}720 721#undef floor722#define floor(__x) __tg_floor(__tg_promote1((__x))(__x))723 724// fma725 726static float727 _TG_ATTRS728 __tg_fma(float __x, float __y, float __z)729 {return fmaf(__x, __y, __z);}730 731static double732 _TG_ATTRS733 __tg_fma(double __x, double __y, double __z)734 {return fma(__x, __y, __z);}735 736static long double737 _TG_ATTRS738 __tg_fma(long double __x,long double __y, long double __z)739 {return fmal(__x, __y, __z);}740 741#undef fma742#define fma(__x, __y, __z) \743 __tg_fma(__tg_promote3((__x), (__y), (__z))(__x), \744 __tg_promote3((__x), (__y), (__z))(__y), \745 __tg_promote3((__x), (__y), (__z))(__z))746 747// fmax748 749static float750 _TG_ATTRS751 __tg_fmax(float __x, float __y) {return fmaxf(__x, __y);}752 753static double754 _TG_ATTRS755 __tg_fmax(double __x, double __y) {return fmax(__x, __y);}756 757static long double758 _TG_ATTRS759 __tg_fmax(long double __x, long double __y) {return fmaxl(__x, __y);}760 761#undef fmax762#define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \763 __tg_promote2((__x), (__y))(__y))764 765// fmin766 767static float768 _TG_ATTRS769 __tg_fmin(float __x, float __y) {return fminf(__x, __y);}770 771static double772 _TG_ATTRS773 __tg_fmin(double __x, double __y) {return fmin(__x, __y);}774 775static long double776 _TG_ATTRS777 __tg_fmin(long double __x, long double __y) {return fminl(__x, __y);}778 779#undef fmin780#define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \781 __tg_promote2((__x), (__y))(__y))782 783// fmod784 785static float786 _TG_ATTRS787 __tg_fmod(float __x, float __y) {return fmodf(__x, __y);}788 789static double790 _TG_ATTRS791 __tg_fmod(double __x, double __y) {return fmod(__x, __y);}792 793static long double794 _TG_ATTRS795 __tg_fmod(long double __x, long double __y) {return fmodl(__x, __y);}796 797#undef fmod798#define fmod(__x, __y) __tg_fmod(__tg_promote2((__x), (__y))(__x), \799 __tg_promote2((__x), (__y))(__y))800 801// frexp802 803static float804 _TG_ATTRS805 __tg_frexp(float __x, int* __y) {return frexpf(__x, __y);}806 807static double808 _TG_ATTRS809 __tg_frexp(double __x, int* __y) {return frexp(__x, __y);}810 811static long double812 _TG_ATTRS813 __tg_frexp(long double __x, int* __y) {return frexpl(__x, __y);}814 815#undef frexp816#define frexp(__x, __y) __tg_frexp(__tg_promote1((__x))(__x), __y)817 818// hypot819 820static float821 _TG_ATTRS822 __tg_hypot(float __x, float __y) {return hypotf(__x, __y);}823 824static double825 _TG_ATTRS826 __tg_hypot(double __x, double __y) {return hypot(__x, __y);}827 828static long double829 _TG_ATTRS830 __tg_hypot(long double __x, long double __y) {return hypotl(__x, __y);}831 832#undef hypot833#define hypot(__x, __y) __tg_hypot(__tg_promote2((__x), (__y))(__x), \834 __tg_promote2((__x), (__y))(__y))835 836// ilogb837 838static int839 _TG_ATTRS840 __tg_ilogb(float __x) {return ilogbf(__x);}841 842static int843 _TG_ATTRS844 __tg_ilogb(double __x) {return ilogb(__x);}845 846static int847 _TG_ATTRS848 __tg_ilogb(long double __x) {return ilogbl(__x);}849 850#undef ilogb851#define ilogb(__x) __tg_ilogb(__tg_promote1((__x))(__x))852 853// ldexp854 855static float856 _TG_ATTRS857 __tg_ldexp(float __x, int __y) {return ldexpf(__x, __y);}858 859static double860 _TG_ATTRS861 __tg_ldexp(double __x, int __y) {return ldexp(__x, __y);}862 863static long double864 _TG_ATTRS865 __tg_ldexp(long double __x, int __y) {return ldexpl(__x, __y);}866 867#undef ldexp868#define ldexp(__x, __y) __tg_ldexp(__tg_promote1((__x))(__x), __y)869 870// lgamma871 872static float873 _TG_ATTRS874 __tg_lgamma(float __x) {return lgammaf(__x);}875 876static double877 _TG_ATTRS878 __tg_lgamma(double __x) {return lgamma(__x);}879 880static long double881 _TG_ATTRS882 __tg_lgamma(long double __x) {return lgammal(__x);}883 884#undef lgamma885#define lgamma(__x) __tg_lgamma(__tg_promote1((__x))(__x))886 887// llrint888 889static long long890 _TG_ATTRS891 __tg_llrint(float __x) {return llrintf(__x);}892 893static long long894 _TG_ATTRS895 __tg_llrint(double __x) {return llrint(__x);}896 897static long long898 _TG_ATTRS899 __tg_llrint(long double __x) {return llrintl(__x);}900 901#undef llrint902#define llrint(__x) __tg_llrint(__tg_promote1((__x))(__x))903 904// llround905 906static long long907 _TG_ATTRS908 __tg_llround(float __x) {return llroundf(__x);}909 910static long long911 _TG_ATTRS912 __tg_llround(double __x) {return llround(__x);}913 914static long long915 _TG_ATTRS916 __tg_llround(long double __x) {return llroundl(__x);}917 918#undef llround919#define llround(__x) __tg_llround(__tg_promote1((__x))(__x))920 921// log10922 923static float924 _TG_ATTRS925 __tg_log10(float __x) {return log10f(__x);}926 927static double928 _TG_ATTRS929 __tg_log10(double __x) {return log10(__x);}930 931static long double932 _TG_ATTRS933 __tg_log10(long double __x) {return log10l(__x);}934 935#undef log10936#define log10(__x) __tg_log10(__tg_promote1((__x))(__x))937 938// log1p939 940static float941 _TG_ATTRS942 __tg_log1p(float __x) {return log1pf(__x);}943 944static double945 _TG_ATTRS946 __tg_log1p(double __x) {return log1p(__x);}947 948static long double949 _TG_ATTRS950 __tg_log1p(long double __x) {return log1pl(__x);}951 952#undef log1p953#define log1p(__x) __tg_log1p(__tg_promote1((__x))(__x))954 955// log2956 957static float958 _TG_ATTRS959 __tg_log2(float __x) {return log2f(__x);}960 961static double962 _TG_ATTRS963 __tg_log2(double __x) {return log2(__x);}964 965static long double966 _TG_ATTRS967 __tg_log2(long double __x) {return log2l(__x);}968 969#undef log2970#define log2(__x) __tg_log2(__tg_promote1((__x))(__x))971 972// logb973 974static float975 _TG_ATTRS976 __tg_logb(float __x) {return logbf(__x);}977 978static double979 _TG_ATTRS980 __tg_logb(double __x) {return logb(__x);}981 982static long double983 _TG_ATTRS984 __tg_logb(long double __x) {return logbl(__x);}985 986#undef logb987#define logb(__x) __tg_logb(__tg_promote1((__x))(__x))988 989// lrint990 991static long992 _TG_ATTRS993 __tg_lrint(float __x) {return lrintf(__x);}994 995static long996 _TG_ATTRS997 __tg_lrint(double __x) {return lrint(__x);}998 999static long1000 _TG_ATTRS1001 __tg_lrint(long double __x) {return lrintl(__x);}1002 1003#undef lrint1004#define lrint(__x) __tg_lrint(__tg_promote1((__x))(__x))1005 1006// lround1007 1008static long1009 _TG_ATTRS1010 __tg_lround(float __x) {return lroundf(__x);}1011 1012static long1013 _TG_ATTRS1014 __tg_lround(double __x) {return lround(__x);}1015 1016static long1017 _TG_ATTRS1018 __tg_lround(long double __x) {return lroundl(__x);}1019 1020#undef lround1021#define lround(__x) __tg_lround(__tg_promote1((__x))(__x))1022 1023// nearbyint1024 1025static float1026 _TG_ATTRS1027 __tg_nearbyint(float __x) {return nearbyintf(__x);}1028 1029static double1030 _TG_ATTRS1031 __tg_nearbyint(double __x) {return nearbyint(__x);}1032 1033static long double1034 _TG_ATTRS1035 __tg_nearbyint(long double __x) {return nearbyintl(__x);}1036 1037#undef nearbyint1038#define nearbyint(__x) __tg_nearbyint(__tg_promote1((__x))(__x))1039 1040// nextafter1041 1042static float1043 _TG_ATTRS1044 __tg_nextafter(float __x, float __y) {return nextafterf(__x, __y);}1045 1046static double1047 _TG_ATTRS1048 __tg_nextafter(double __x, double __y) {return nextafter(__x, __y);}1049 1050static long double1051 _TG_ATTRS1052 __tg_nextafter(long double __x, long double __y) {return nextafterl(__x, __y);}1053 1054#undef nextafter1055#define nextafter(__x, __y) __tg_nextafter(__tg_promote2((__x), (__y))(__x), \1056 __tg_promote2((__x), (__y))(__y))1057 1058// nexttoward1059 1060static float1061 _TG_ATTRS1062 __tg_nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);}1063 1064static double1065 _TG_ATTRS1066 __tg_nexttoward(double __x, long double __y) {return nexttoward(__x, __y);}1067 1068static long double1069 _TG_ATTRS1070 __tg_nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);}1071 1072#undef nexttoward1073#define nexttoward(__x, __y) __tg_nexttoward(__tg_promote1((__x))(__x), (__y))1074 1075// remainder1076 1077static float1078 _TG_ATTRS1079 __tg_remainder(float __x, float __y) {return remainderf(__x, __y);}1080 1081static double1082 _TG_ATTRS1083 __tg_remainder(double __x, double __y) {return remainder(__x, __y);}1084 1085static long double1086 _TG_ATTRS1087 __tg_remainder(long double __x, long double __y) {return remainderl(__x, __y);}1088 1089#undef remainder1090#define remainder(__x, __y) __tg_remainder(__tg_promote2((__x), (__y))(__x), \1091 __tg_promote2((__x), (__y))(__y))1092 1093// remquo1094 1095static float1096 _TG_ATTRS1097 __tg_remquo(float __x, float __y, int* __z)1098 {return remquof(__x, __y, __z);}1099 1100static double1101 _TG_ATTRS1102 __tg_remquo(double __x, double __y, int* __z)1103 {return remquo(__x, __y, __z);}1104 1105static long double1106 _TG_ATTRS1107 __tg_remquo(long double __x,long double __y, int* __z)1108 {return remquol(__x, __y, __z);}1109 1110#undef remquo1111#define remquo(__x, __y, __z) \1112 __tg_remquo(__tg_promote2((__x), (__y))(__x), \1113 __tg_promote2((__x), (__y))(__y), \1114 (__z))1115 1116// rint1117 1118static float1119 _TG_ATTRS1120 __tg_rint(float __x) {return rintf(__x);}1121 1122static double1123 _TG_ATTRS1124 __tg_rint(double __x) {return rint(__x);}1125 1126static long double1127 _TG_ATTRS1128 __tg_rint(long double __x) {return rintl(__x);}1129 1130#undef rint1131#define rint(__x) __tg_rint(__tg_promote1((__x))(__x))1132 1133// round1134 1135static float1136 _TG_ATTRS1137 __tg_round(float __x) {return roundf(__x);}1138 1139static double1140 _TG_ATTRS1141 __tg_round(double __x) {return round(__x);}1142 1143static long double1144 _TG_ATTRS1145 __tg_round(long double __x) {return roundl(__x);}1146 1147#undef round1148#define round(__x) __tg_round(__tg_promote1((__x))(__x))1149 1150// scalbn1151 1152static float1153 _TG_ATTRS1154 __tg_scalbn(float __x, int __y) {return scalbnf(__x, __y);}1155 1156static double1157 _TG_ATTRS1158 __tg_scalbn(double __x, int __y) {return scalbn(__x, __y);}1159 1160static long double1161 _TG_ATTRS1162 __tg_scalbn(long double __x, int __y) {return scalbnl(__x, __y);}1163 1164#undef scalbn1165#define scalbn(__x, __y) __tg_scalbn(__tg_promote1((__x))(__x), __y)1166 1167// scalbln1168 1169static float1170 _TG_ATTRS1171 __tg_scalbln(float __x, long __y) {return scalblnf(__x, __y);}1172 1173static double1174 _TG_ATTRS1175 __tg_scalbln(double __x, long __y) {return scalbln(__x, __y);}1176 1177static long double1178 _TG_ATTRS1179 __tg_scalbln(long double __x, long __y) {return scalblnl(__x, __y);}1180 1181#undef scalbln1182#define scalbln(__x, __y) __tg_scalbln(__tg_promote1((__x))(__x), __y)1183 1184// tgamma1185 1186static float1187 _TG_ATTRS1188 __tg_tgamma(float __x) {return tgammaf(__x);}1189 1190static double1191 _TG_ATTRS1192 __tg_tgamma(double __x) {return tgamma(__x);}1193 1194static long double1195 _TG_ATTRS1196 __tg_tgamma(long double __x) {return tgammal(__x);}1197 1198#undef tgamma1199#define tgamma(__x) __tg_tgamma(__tg_promote1((__x))(__x))1200 1201// trunc1202 1203static float1204 _TG_ATTRS1205 __tg_trunc(float __x) {return truncf(__x);}1206 1207static double1208 _TG_ATTRS1209 __tg_trunc(double __x) {return trunc(__x);}1210 1211static long double1212 _TG_ATTRS1213 __tg_trunc(long double __x) {return truncl(__x);}1214 1215#undef trunc1216#define trunc(__x) __tg_trunc(__tg_promote1((__x))(__x))1217 1218// carg1219 1220static float1221 _TG_ATTRS1222 __tg_carg(float __x) {return atan2f(0.F, __x);}1223 1224static double1225 _TG_ATTRS1226 __tg_carg(double __x) {return atan2(0., __x);}1227 1228static long double1229 _TG_ATTRS1230 __tg_carg(long double __x) {return atan2l(0.L, __x);}1231 1232static float1233 _TG_ATTRS1234 __tg_carg(float _Complex __x) {return cargf(__x);}1235 1236static double1237 _TG_ATTRS1238 __tg_carg(double _Complex __x) {return carg(__x);}1239 1240static long double1241 _TG_ATTRS1242 __tg_carg(long double _Complex __x) {return cargl(__x);}1243 1244#undef carg1245#define carg(__x) __tg_carg(__tg_promote1((__x))(__x))1246 1247// cimag1248 1249static float1250 _TG_ATTRS1251 __tg_cimag(float __x) {return 0;}1252 1253static double1254 _TG_ATTRS1255 __tg_cimag(double __x) {return 0;}1256 1257static long double1258 _TG_ATTRS1259 __tg_cimag(long double __x) {return 0;}1260 1261static float1262 _TG_ATTRS1263 __tg_cimag(float _Complex __x) {return cimagf(__x);}1264 1265static double1266 _TG_ATTRS1267 __tg_cimag(double _Complex __x) {return cimag(__x);}1268 1269static long double1270 _TG_ATTRS1271 __tg_cimag(long double _Complex __x) {return cimagl(__x);}1272 1273#undef cimag1274#define cimag(__x) __tg_cimag(__tg_promote1((__x))(__x))1275 1276// conj1277 1278static float _Complex1279 _TG_ATTRS1280 __tg_conj(float __x) {return __x;}1281 1282static double _Complex1283 _TG_ATTRS1284 __tg_conj(double __x) {return __x;}1285 1286static long double _Complex1287 _TG_ATTRS1288 __tg_conj(long double __x) {return __x;}1289 1290static float _Complex1291 _TG_ATTRS1292 __tg_conj(float _Complex __x) {return conjf(__x);}1293 1294static double _Complex1295 _TG_ATTRS1296 __tg_conj(double _Complex __x) {return conj(__x);}1297 1298static long double _Complex1299 _TG_ATTRS1300 __tg_conj(long double _Complex __x) {return conjl(__x);}1301 1302#undef conj1303#define conj(__x) __tg_conj(__tg_promote1((__x))(__x))1304 1305// cproj1306 1307static float _Complex1308 _TG_ATTRS1309 __tg_cproj(float __x) {return cprojf(__x);}1310 1311static double _Complex1312 _TG_ATTRS1313 __tg_cproj(double __x) {return cproj(__x);}1314 1315static long double _Complex1316 _TG_ATTRS1317 __tg_cproj(long double __x) {return cprojl(__x);}1318 1319static float _Complex1320 _TG_ATTRS1321 __tg_cproj(float _Complex __x) {return cprojf(__x);}1322 1323static double _Complex1324 _TG_ATTRS1325 __tg_cproj(double _Complex __x) {return cproj(__x);}1326 1327static long double _Complex1328 _TG_ATTRS1329 __tg_cproj(long double _Complex __x) {return cprojl(__x);}1330 1331#undef cproj1332#define cproj(__x) __tg_cproj(__tg_promote1((__x))(__x))1333 1334// creal1335 1336static float1337 _TG_ATTRS1338 __tg_creal(float __x) {return __x;}1339 1340static double1341 _TG_ATTRS1342 __tg_creal(double __x) {return __x;}1343 1344static long double1345 _TG_ATTRS1346 __tg_creal(long double __x) {return __x;}1347 1348static float1349 _TG_ATTRS1350 __tg_creal(float _Complex __x) {return crealf(__x);}1351 1352static double1353 _TG_ATTRS1354 __tg_creal(double _Complex __x) {return creal(__x);}1355 1356static long double1357 _TG_ATTRS1358 __tg_creal(long double _Complex __x) {return creall(__x);}1359 1360#undef creal1361#define creal(__x) __tg_creal(__tg_promote1((__x))(__x))1362 1363#undef _TG_ATTRSp1364#undef _TG_ATTRS1365 1366#endif /* __cplusplus */1367#endif /* __has_include_next */1368#endif /* __CLANG_TGMATH_H */1369