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