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