zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

tgmath.h (32313B) - Raw


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