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