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