cmath revision 1.1.1.1.2.1 1 // TR1 cmath -*- C++ -*-
2
3 // Copyright (C) 2006-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /** @file tr1/cmath
26 * This is a TR1 C++ Library header.
27 */
28
29 #ifndef _GLIBCXX_TR1_CMATH
30 #define _GLIBCXX_TR1_CMATH 1
31
32 #pragma GCC system_header
33
34 #include <cmath>
35
36 #ifdef _GLIBCXX_USE_C99_MATH_TR1
37
38 #undef acosh
39 #undef acoshf
40 #undef acoshl
41 #undef asinh
42 #undef asinhf
43 #undef asinhl
44 #undef atanh
45 #undef atanhf
46 #undef atanhl
47 #undef cbrt
48 #undef cbrtf
49 #undef cbrtl
50 #undef copysign
51 #undef copysignf
52 #undef copysignl
53 #undef erf
54 #undef erff
55 #undef erfl
56 #undef erfc
57 #undef erfcf
58 #undef erfcl
59 #undef exp2
60 #undef exp2f
61 #undef exp2l
62 #undef expm1
63 #undef expm1f
64 #undef expm1l
65 #undef fdim
66 #undef fdimf
67 #undef fdiml
68 #undef fma
69 #undef fmaf
70 #undef fmal
71 #undef fmax
72 #undef fmaxf
73 #undef fmaxl
74 #undef fmin
75 #undef fminf
76 #undef fminl
77 #undef hypot
78 #undef hypotf
79 #undef hypotl
80 #undef ilogb
81 #undef ilogbf
82 #undef ilogbl
83 #undef lgamma
84 #undef lgammaf
85 #undef lgammal
86 #undef llrint
87 #undef llrintf
88 #undef llrintl
89 #undef llround
90 #undef llroundf
91 #undef llroundl
92 #undef log1p
93 #undef log1pf
94 #undef log1pl
95 #undef log2
96 #undef log2f
97 #undef log2l
98 #undef logb
99 #undef logbf
100 #undef logbl
101 #undef lrint
102 #undef lrintf
103 #undef lrintl
104 #undef lround
105 #undef lroundf
106 #undef lroundl
107 #undef nan
108 #undef nanf
109 #undef nanl
110 #undef nearbyint
111 #undef nearbyintf
112 #undef nearbyintl
113 #undef nextafter
114 #undef nextafterf
115 #undef nextafterl
116 #undef nexttoward
117 #undef nexttowardf
118 #undef nexttowardl
119 #undef remainder
120 #undef remainderf
121 #undef remainderl
122 #undef remquo
123 #undef remquof
124 #undef remquol
125 #undef rint
126 #undef rintf
127 #undef rintl
128 #undef round
129 #undef roundf
130 #undef roundl
131 #undef scalbln
132 #undef scalblnf
133 #undef scalblnl
134 #undef scalbn
135 #undef scalbnf
136 #undef scalbnl
137 #undef tgamma
138 #undef tgammaf
139 #undef tgammal
140 #undef trunc
141 #undef truncf
142 #undef truncl
143
144 #endif
145
146 namespace std _GLIBCXX_VISIBILITY(default)
147 {
148 namespace tr1
149 {
150 _GLIBCXX_BEGIN_NAMESPACE_VERSION
151
152 #if _GLIBCXX_USE_C99_MATH_TR1
153
154 // types
155 using ::double_t;
156 using ::float_t;
157
158 // functions
159 using ::acosh;
160 using ::acoshf;
161 using ::acoshl;
162
163 using ::asinh;
164 using ::asinhf;
165 using ::asinhl;
166
167 using ::atanh;
168 using ::atanhf;
169 using ::atanhl;
170
171 using ::cbrt;
172 using ::cbrtf;
173 using ::cbrtl;
174
175 using ::copysign;
176 using ::copysignf;
177 using ::copysignl;
178
179 using ::erf;
180 using ::erff;
181 using ::erfl;
182
183 using ::erfc;
184 using ::erfcf;
185 using ::erfcl;
186
187 using ::exp2;
188 using ::exp2f;
189 using ::exp2l;
190
191 using ::expm1;
192 using ::expm1f;
193 using ::expm1l;
194
195 using ::fdim;
196 using ::fdimf;
197 using ::fdiml;
198
199 using ::fma;
200 using ::fmaf;
201 using ::fmal;
202
203 using ::fmax;
204 using ::fmaxf;
205 using ::fmaxl;
206
207 using ::fmin;
208 using ::fminf;
209 using ::fminl;
210
211 using ::hypot;
212 using ::hypotf;
213 using ::hypotl;
214
215 using ::ilogb;
216 using ::ilogbf;
217 using ::ilogbl;
218
219 using ::lgamma;
220 using ::lgammaf;
221 using ::lgammal;
222
223 using ::llrint;
224 using ::llrintf;
225 using ::llrintl;
226
227 using ::llround;
228 using ::llroundf;
229 using ::llroundl;
230
231 using ::log1p;
232 using ::log1pf;
233 using ::log1pl;
234
235 using ::log2;
236 using ::log2f;
237 using ::log2l;
238
239 using ::logb;
240 using ::logbf;
241 using ::logbl;
242
243 using ::lrint;
244 using ::lrintf;
245 using ::lrintl;
246
247 using ::lround;
248 using ::lroundf;
249 using ::lroundl;
250
251 using ::nan;
252 using ::nanf;
253 using ::nanl;
254
255 using ::nearbyint;
256 using ::nearbyintf;
257 using ::nearbyintl;
258
259 using ::nextafter;
260 using ::nextafterf;
261 using ::nextafterl;
262
263 using ::nexttoward;
264 using ::nexttowardf;
265 using ::nexttowardl;
266
267 using ::remainder;
268 using ::remainderf;
269 using ::remainderl;
270
271 using ::remquo;
272 using ::remquof;
273 using ::remquol;
274
275 using ::rint;
276 using ::rintf;
277 using ::rintl;
278
279 using ::round;
280 using ::roundf;
281 using ::roundl;
282
283 using ::scalbln;
284 using ::scalblnf;
285 using ::scalblnl;
286
287 using ::scalbn;
288 using ::scalbnf;
289 using ::scalbnl;
290
291 using ::tgamma;
292 using ::tgammaf;
293 using ::tgammal;
294
295 using ::trunc;
296 using ::truncf;
297 using ::truncl;
298
299 #endif
300
301 #if _GLIBCXX_USE_C99_MATH
302 #if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
303
304 /// Function template definitions [8.16.3].
305 template<typename _Tp>
306 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
307 int>::__type
308 fpclassify(_Tp __f)
309 {
310 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
311 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
312 FP_SUBNORMAL, FP_ZERO, __type(__f));
313 }
314
315 template<typename _Tp>
316 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
317 int>::__type
318 isfinite(_Tp __f)
319 {
320 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
321 return __builtin_isfinite(__type(__f));
322 }
323
324 template<typename _Tp>
325 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
326 int>::__type
327 isinf(_Tp __f)
328 {
329 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
330 return __builtin_isinf(__type(__f));
331 }
332
333 template<typename _Tp>
334 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
335 int>::__type
336 isnan(_Tp __f)
337 {
338 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
339 return __builtin_isnan(__type(__f));
340 }
341
342 template<typename _Tp>
343 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
344 int>::__type
345 isnormal(_Tp __f)
346 {
347 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
348 return __builtin_isnormal(__type(__f));
349 }
350
351 template<typename _Tp>
352 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
353 int>::__type
354 signbit(_Tp __f)
355 {
356 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
357 return __builtin_signbit(__type(__f));
358 }
359
360 template<typename _Tp>
361 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
362 int>::__type
363 isgreater(_Tp __f1, _Tp __f2)
364 {
365 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
366 return __builtin_isgreater(__type(__f1), __type(__f2));
367 }
368
369 template<typename _Tp>
370 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
371 int>::__type
372 isgreaterequal(_Tp __f1, _Tp __f2)
373 {
374 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
375 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
376 }
377
378 template<typename _Tp>
379 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
380 int>::__type
381 isless(_Tp __f1, _Tp __f2)
382 {
383 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
384 return __builtin_isless(__type(__f1), __type(__f2));
385 }
386
387 template<typename _Tp>
388 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
389 int>::__type
390 islessequal(_Tp __f1, _Tp __f2)
391 {
392 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
393 return __builtin_islessequal(__type(__f1), __type(__f2));
394 }
395
396 template<typename _Tp>
397 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
398 int>::__type
399 islessgreater(_Tp __f1, _Tp __f2)
400 {
401 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
402 return __builtin_islessgreater(__type(__f1), __type(__f2));
403 }
404
405 template<typename _Tp>
406 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
407 int>::__type
408 isunordered(_Tp __f1, _Tp __f2)
409 {
410 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
411 return __builtin_isunordered(__type(__f1), __type(__f2));
412 }
413
414 #endif
415 #endif
416
417 #if _GLIBCXX_USE_C99_MATH_TR1
418
419 /// Additional overloads [8.16.4].
420 using std::acos;
421
422 inline float
423 acosh(float __x)
424 { return __builtin_acoshf(__x); }
425
426 inline long double
427 acosh(long double __x)
428 { return __builtin_acoshl(__x); }
429
430 template<typename _Tp>
431 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
432 double>::__type
433 acosh(_Tp __x)
434 { return __builtin_acosh(__x); }
435
436 using std::asin;
437
438 inline float
439 asinh(float __x)
440 { return __builtin_asinhf(__x); }
441
442 inline long double
443 asinh(long double __x)
444 { return __builtin_asinhl(__x); }
445
446 template<typename _Tp>
447 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
448 double>::__type
449 asinh(_Tp __x)
450 { return __builtin_asinh(__x); }
451
452 using std::atan;
453 using std::atan2;
454
455 inline float
456 atanh(float __x)
457 { return __builtin_atanhf(__x); }
458
459 inline long double
460 atanh(long double __x)
461 { return __builtin_atanhl(__x); }
462
463 template<typename _Tp>
464 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
465 double>::__type
466 atanh(_Tp __x)
467 { return __builtin_atanh(__x); }
468
469 inline float
470 cbrt(float __x)
471 { return __builtin_cbrtf(__x); }
472
473 inline long double
474 cbrt(long double __x)
475 { return __builtin_cbrtl(__x); }
476
477 template<typename _Tp>
478 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
479 double>::__type
480 cbrt(_Tp __x)
481 { return __builtin_cbrt(__x); }
482
483 using std::ceil;
484
485 inline float
486 copysign(float __x, float __y)
487 { return __builtin_copysignf(__x, __y); }
488
489 inline long double
490 copysign(long double __x, long double __y)
491 { return __builtin_copysignl(__x, __y); }
492
493 template<typename _Tp, typename _Up>
494 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
495 copysign(_Tp __x, _Up __y)
496 {
497 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
498 return copysign(__type(__x), __type(__y));
499 }
500
501 using std::cos;
502 using std::cosh;
503
504 inline float
505 erf(float __x)
506 { return __builtin_erff(__x); }
507
508 inline long double
509 erf(long double __x)
510 { return __builtin_erfl(__x); }
511
512 template<typename _Tp>
513 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
514 double>::__type
515 erf(_Tp __x)
516 { return __builtin_erf(__x); }
517
518 inline float
519 erfc(float __x)
520 { return __builtin_erfcf(__x); }
521
522 inline long double
523 erfc(long double __x)
524 { return __builtin_erfcl(__x); }
525
526 template<typename _Tp>
527 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
528 double>::__type
529 erfc(_Tp __x)
530 { return __builtin_erfc(__x); }
531
532 using std::exp;
533
534 inline float
535 exp2(float __x)
536 { return __builtin_exp2f(__x); }
537
538 inline long double
539 exp2(long double __x)
540 { return __builtin_exp2l(__x); }
541
542 template<typename _Tp>
543 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
544 double>::__type
545 exp2(_Tp __x)
546 { return __builtin_exp2(__x); }
547
548 inline float
549 expm1(float __x)
550 { return __builtin_expm1f(__x); }
551
552 inline long double
553 expm1(long double __x)
554 { return __builtin_expm1l(__x); }
555
556 template<typename _Tp>
557 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
558 double>::__type
559 expm1(_Tp __x)
560 { return __builtin_expm1(__x); }
561
562 // Note: we deal with fabs in a special way, because an using std::fabs
563 // would bring in also the overloads for complex types, which in C++0x
564 // mode have a different return type.
565 // With __CORRECT_ISO_CPP_MATH_H_PROTO, math.h imports std::fabs in the
566 // global namespace after the declarations of the float / double / long
567 // double overloads but before the std::complex overloads.
568 using ::fabs;
569
570 #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
571 inline float
572 fabs(float __x)
573 { return __builtin_fabsf(__x); }
574
575 inline long double
576 fabs(long double __x)
577 { return __builtin_fabsl(__x); }
578
579 template<typename _Tp>
580 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
581 double>::__type
582 fabs(_Tp __x)
583 { return __builtin_fabs(__x); }
584 #endif
585
586 inline float
587 fdim(float __x, float __y)
588 { return __builtin_fdimf(__x, __y); }
589
590 inline long double
591 fdim(long double __x, long double __y)
592 { return __builtin_fdiml(__x, __y); }
593
594 template<typename _Tp, typename _Up>
595 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
596 fdim(_Tp __x, _Up __y)
597 {
598 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
599 return fdim(__type(__x), __type(__y));
600 }
601
602 using std::floor;
603
604 inline float
605 fma(float __x, float __y, float __z)
606 { return __builtin_fmaf(__x, __y, __z); }
607
608 inline long double
609 fma(long double __x, long double __y, long double __z)
610 { return __builtin_fmal(__x, __y, __z); }
611
612 template<typename _Tp, typename _Up, typename _Vp>
613 inline typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
614 fma(_Tp __x, _Up __y, _Vp __z)
615 {
616 typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type;
617 return fma(__type(__x), __type(__y), __type(__z));
618 }
619
620 inline float
621 fmax(float __x, float __y)
622 { return __builtin_fmaxf(__x, __y); }
623
624 inline long double
625 fmax(long double __x, long double __y)
626 { return __builtin_fmaxl(__x, __y); }
627
628 template<typename _Tp, typename _Up>
629 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
630 fmax(_Tp __x, _Up __y)
631 {
632 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
633 return fmax(__type(__x), __type(__y));
634 }
635
636 inline float
637 fmin(float __x, float __y)
638 { return __builtin_fminf(__x, __y); }
639
640 inline long double
641 fmin(long double __x, long double __y)
642 { return __builtin_fminl(__x, __y); }
643
644 template<typename _Tp, typename _Up>
645 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
646 fmin(_Tp __x, _Up __y)
647 {
648 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
649 return fmin(__type(__x), __type(__y));
650 }
651
652 using std::fmod;
653 using std::frexp;
654
655 inline float
656 hypot(float __x, float __y)
657 { return __builtin_hypotf(__x, __y); }
658
659 inline long double
660 hypot(long double __x, long double __y)
661 { return __builtin_hypotl(__x, __y); }
662
663 template<typename _Tp, typename _Up>
664 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
665 hypot(_Tp __y, _Up __x)
666 {
667 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
668 return hypot(__type(__y), __type(__x));
669 }
670
671 inline int
672 ilogb(float __x)
673 { return __builtin_ilogbf(__x); }
674
675 inline int
676 ilogb(long double __x)
677 { return __builtin_ilogbl(__x); }
678
679 template<typename _Tp>
680 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
681 int>::__type
682 ilogb(_Tp __x)
683 { return __builtin_ilogb(__x); }
684
685 using std::ldexp;
686
687 inline float
688 lgamma(float __x)
689 { return __builtin_lgammaf(__x); }
690
691 inline long double
692 lgamma(long double __x)
693 { return __builtin_lgammal(__x); }
694
695 template<typename _Tp>
696 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
697 double>::__type
698 lgamma(_Tp __x)
699 { return __builtin_lgamma(__x); }
700
701 inline long long
702 llrint(float __x)
703 { return __builtin_llrintf(__x); }
704
705 inline long long
706 llrint(long double __x)
707 { return __builtin_llrintl(__x); }
708
709 template<typename _Tp>
710 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
711 long long>::__type
712 llrint(_Tp __x)
713 { return __builtin_llrint(__x); }
714
715 inline long long
716 llround(float __x)
717 { return __builtin_llroundf(__x); }
718
719 inline long long
720 llround(long double __x)
721 { return __builtin_llroundl(__x); }
722
723 template<typename _Tp>
724 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
725 long long>::__type
726 llround(_Tp __x)
727 { return __builtin_llround(__x); }
728
729 using std::log;
730 using std::log10;
731
732 inline float
733 log1p(float __x)
734 { return __builtin_log1pf(__x); }
735
736 inline long double
737 log1p(long double __x)
738 { return __builtin_log1pl(__x); }
739
740 template<typename _Tp>
741 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
742 double>::__type
743 log1p(_Tp __x)
744 { return __builtin_log1p(__x); }
745
746 // DR 568.
747 inline float
748 log2(float __x)
749 { return __builtin_log2f(__x); }
750
751 inline long double
752 log2(long double __x)
753 { return __builtin_log2l(__x); }
754
755 template<typename _Tp>
756 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
757 double>::__type
758 log2(_Tp __x)
759 { return __builtin_log2(__x); }
760
761 inline float
762 logb(float __x)
763 { return __builtin_logbf(__x); }
764
765 inline long double
766 logb(long double __x)
767 { return __builtin_logbl(__x); }
768
769 template<typename _Tp>
770 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
771 double>::__type
772 logb(_Tp __x)
773 {
774 return __builtin_logb(__x);
775 }
776
777 inline long
778 lrint(float __x)
779 { return __builtin_lrintf(__x); }
780
781 inline long
782 lrint(long double __x)
783 { return __builtin_lrintl(__x); }
784
785 template<typename _Tp>
786 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
787 long>::__type
788 lrint(_Tp __x)
789 { return __builtin_lrint(__x); }
790
791 inline long
792 lround(float __x)
793 { return __builtin_lroundf(__x); }
794
795 inline long
796 lround(long double __x)
797 { return __builtin_lroundl(__x); }
798
799 template<typename _Tp>
800 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
801 long>::__type
802 lround(_Tp __x)
803 { return __builtin_lround(__x); }
804
805 inline float
806 nearbyint(float __x)
807 { return __builtin_nearbyintf(__x); }
808
809 inline long double
810 nearbyint(long double __x)
811 { return __builtin_nearbyintl(__x); }
812
813 template<typename _Tp>
814 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
815 double>::__type
816 nearbyint(_Tp __x)
817 { return __builtin_nearbyint(__x); }
818
819 inline float
820 nextafter(float __x, float __y)
821 { return __builtin_nextafterf(__x, __y); }
822
823 inline long double
824 nextafter(long double __x, long double __y)
825 { return __builtin_nextafterl(__x, __y); }
826
827 template<typename _Tp, typename _Up>
828 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
829 nextafter(_Tp __x, _Up __y)
830 {
831 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
832 return nextafter(__type(__x), __type(__y));
833 }
834
835 inline float
836 nexttoward(float __x, long double __y)
837 { return __builtin_nexttowardf(__x, __y); }
838
839 inline long double
840 nexttoward(long double __x, long double __y)
841 { return __builtin_nexttowardl(__x, __y); }
842
843 template<typename _Tp>
844 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
845 double>::__type
846 nexttoward(_Tp __x, long double __y)
847 { return __builtin_nexttoward(__x, __y); }
848
849 // DR 550. What should the return type of pow(float,int) be?
850 // NB: C++0x and TR1 != C++03.
851 // using std::pow;
852
853 inline float
854 remainder(float __x, float __y)
855 { return __builtin_remainderf(__x, __y); }
856
857 inline long double
858 remainder(long double __x, long double __y)
859 { return __builtin_remainderl(__x, __y); }
860
861 template<typename _Tp, typename _Up>
862 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
863 remainder(_Tp __x, _Up __y)
864 {
865 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
866 return remainder(__type(__x), __type(__y));
867 }
868
869 inline float
870 remquo(float __x, float __y, int* __pquo)
871 { return __builtin_remquof(__x, __y, __pquo); }
872
873 inline long double
874 remquo(long double __x, long double __y, int* __pquo)
875 { return __builtin_remquol(__x, __y, __pquo); }
876
877 template<typename _Tp, typename _Up>
878 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
879 remquo(_Tp __x, _Up __y, int* __pquo)
880 {
881 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
882 return remquo(__type(__x), __type(__y), __pquo);
883 }
884
885 inline float
886 rint(float __x)
887 { return __builtin_rintf(__x); }
888
889 inline long double
890 rint(long double __x)
891 { return __builtin_rintl(__x); }
892
893 template<typename _Tp>
894 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
895 double>::__type
896 rint(_Tp __x)
897 { return __builtin_rint(__x); }
898
899 inline float
900 round(float __x)
901 { return __builtin_roundf(__x); }
902
903 inline long double
904 round(long double __x)
905 { return __builtin_roundl(__x); }
906
907 template<typename _Tp>
908 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
909 double>::__type
910 round(_Tp __x)
911 { return __builtin_round(__x); }
912
913 inline float
914 scalbln(float __x, long __ex)
915 { return __builtin_scalblnf(__x, __ex); }
916
917 inline long double
918 scalbln(long double __x, long __ex)
919 { return __builtin_scalblnl(__x, __ex); }
920
921 template<typename _Tp>
922 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
923 double>::__type
924 scalbln(_Tp __x, long __ex)
925 { return __builtin_scalbln(__x, __ex); }
926
927 inline float
928 scalbn(float __x, int __ex)
929 { return __builtin_scalbnf(__x, __ex); }
930
931 inline long double
932 scalbn(long double __x, int __ex)
933 { return __builtin_scalbnl(__x, __ex); }
934
935 template<typename _Tp>
936 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
937 double>::__type
938 scalbn(_Tp __x, int __ex)
939 { return __builtin_scalbn(__x, __ex); }
940
941 using std::sin;
942 using std::sinh;
943 using std::sqrt;
944 using std::tan;
945 using std::tanh;
946
947 inline float
948 tgamma(float __x)
949 { return __builtin_tgammaf(__x); }
950
951 inline long double
952 tgamma(long double __x)
953 { return __builtin_tgammal(__x); }
954
955 template<typename _Tp>
956 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
957 double>::__type
958 tgamma(_Tp __x)
959 { return __builtin_tgamma(__x); }
960
961 inline float
962 trunc(float __x)
963 { return __builtin_truncf(__x); }
964
965 inline long double
966 trunc(long double __x)
967 { return __builtin_truncl(__x); }
968
969 template<typename _Tp>
970 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
971 double>::__type
972 trunc(_Tp __x)
973 { return __builtin_trunc(__x); }
974
975 #endif
976 _GLIBCXX_END_NAMESPACE_VERSION
977 }
978 }
979
980 namespace std _GLIBCXX_VISIBILITY(default)
981 {
982 namespace tr1
983 {
984 _GLIBCXX_BEGIN_NAMESPACE_VERSION
985
986 // DR 550. What should the return type of pow(float,int) be?
987 // NB: C++0x and TR1 != C++03.
988 inline double
989 pow(double __x, double __y)
990 { return std::pow(__x, __y); }
991
992 inline float
993 pow(float __x, float __y)
994 { return std::pow(__x, __y); }
995
996 inline long double
997 pow(long double __x, long double __y)
998 { return std::pow(__x, __y); }
999
1000 template<typename _Tp, typename _Up>
1001 inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1002 pow(_Tp __x, _Up __y)
1003 {
1004 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1005 return std::pow(__type(__x), __type(__y));
1006 }
1007
1008 _GLIBCXX_END_NAMESPACE_VERSION
1009 }
1010 }
1011
1012 #include <bits/stl_algobase.h>
1013 #include <limits>
1014 #include <tr1/type_traits>
1015
1016 #include <tr1/gamma.tcc>
1017 #include <tr1/bessel_function.tcc>
1018 #include <tr1/beta_function.tcc>
1019 #include <tr1/ell_integral.tcc>
1020 #include <tr1/exp_integral.tcc>
1021 #include <tr1/hypergeometric.tcc>
1022 #include <tr1/legendre_function.tcc>
1023 #include <tr1/modified_bessel_func.tcc>
1024 #include <tr1/poly_hermite.tcc>
1025 #include <tr1/poly_laguerre.tcc>
1026 #include <tr1/riemann_zeta.tcc>
1027
1028 namespace std _GLIBCXX_VISIBILITY(default)
1029 {
1030 namespace tr1
1031 {
1032 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1033
1034 /**
1035 * @defgroup tr1_math_spec_func Mathematical Special Functions
1036 * @ingroup numerics
1037 *
1038 * A collection of advanced mathematical special functions.
1039 * @{
1040 */
1041
1042 inline float
1043 assoc_laguerref(unsigned int __n, unsigned int __m, float __x)
1044 { return __detail::__assoc_laguerre<float>(__n, __m, __x); }
1045
1046 inline long double
1047 assoc_laguerrel(unsigned int __n, unsigned int __m, long double __x)
1048 {
1049 return __detail::__assoc_laguerre<long double>(__n, __m, __x);
1050 }
1051
1052 /// 5.2.1.1 Associated Laguerre polynomials.
1053 template<typename _Tp>
1054 inline typename __gnu_cxx::__promote<_Tp>::__type
1055 assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
1056 {
1057 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1058 return __detail::__assoc_laguerre<__type>(__n, __m, __x);
1059 }
1060
1061 inline float
1062 assoc_legendref(unsigned int __l, unsigned int __m, float __x)
1063 { return __detail::__assoc_legendre_p<float>(__l, __m, __x); }
1064
1065 inline long double
1066 assoc_legendrel(unsigned int __l, unsigned int __m, long double __x)
1067 { return __detail::__assoc_legendre_p<long double>(__l, __m, __x); }
1068
1069 /// 5.2.1.2 Associated Legendre functions.
1070 template<typename _Tp>
1071 inline typename __gnu_cxx::__promote<_Tp>::__type
1072 assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x)
1073 {
1074 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1075 return __detail::__assoc_legendre_p<__type>(__l, __m, __x);
1076 }
1077
1078 inline float
1079 betaf(float __x, float __y)
1080 { return __detail::__beta<float>(__x, __y); }
1081
1082 inline long double
1083 betal(long double __x, long double __y)
1084 { return __detail::__beta<long double>(__x, __y); }
1085
1086 /// 5.2.1.3 Beta functions.
1087 template<typename _Tpx, typename _Tpy>
1088 inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type
1089 beta(_Tpx __x, _Tpy __y)
1090 {
1091 typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type;
1092 return __detail::__beta<__type>(__x, __y);
1093 }
1094
1095 inline float
1096 comp_ellint_1f(float __k)
1097 { return __detail::__comp_ellint_1<float>(__k); }
1098
1099 inline long double
1100 comp_ellint_1l(long double __k)
1101 { return __detail::__comp_ellint_1<long double>(__k); }
1102
1103 /// 5.2.1.4 Complete elliptic integrals of the first kind.
1104 template<typename _Tp>
1105 inline typename __gnu_cxx::__promote<_Tp>::__type
1106 comp_ellint_1(_Tp __k)
1107 {
1108 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1109 return __detail::__comp_ellint_1<__type>(__k);
1110 }
1111
1112 inline float
1113 comp_ellint_2f(float __k)
1114 { return __detail::__comp_ellint_2<float>(__k); }
1115
1116 inline long double
1117 comp_ellint_2l(long double __k)
1118 { return __detail::__comp_ellint_2<long double>(__k); }
1119
1120 /// 5.2.1.5 Complete elliptic integrals of the second kind.
1121 template<typename _Tp>
1122 inline typename __gnu_cxx::__promote<_Tp>::__type
1123 comp_ellint_2(_Tp __k)
1124 {
1125 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1126 return __detail::__comp_ellint_2<__type>(__k);
1127 }
1128
1129 inline float
1130 comp_ellint_3f(float __k, float __nu)
1131 { return __detail::__comp_ellint_3<float>(__k, __nu); }
1132
1133 inline long double
1134 comp_ellint_3l(long double __k, long double __nu)
1135 { return __detail::__comp_ellint_3<long double>(__k, __nu); }
1136
1137 /// 5.2.1.6 Complete elliptic integrals of the third kind.
1138 template<typename _Tp, typename _Tpn>
1139 inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type
1140 comp_ellint_3(_Tp __k, _Tpn __nu)
1141 {
1142 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type;
1143 return __detail::__comp_ellint_3<__type>(__k, __nu);
1144 }
1145
1146 inline float
1147 conf_hypergf(float __a, float __c, float __x)
1148 { return __detail::__conf_hyperg<float>(__a, __c, __x); }
1149
1150 inline long double
1151 conf_hypergl(long double __a, long double __c, long double __x)
1152 { return __detail::__conf_hyperg<long double>(__a, __c, __x); }
1153
1154 /// 5.2.1.7 Confluent hypergeometric functions.
1155 template<typename _Tpa, typename _Tpc, typename _Tp>
1156 inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type
1157 conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x)
1158 {
1159 typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type;
1160 return __detail::__conf_hyperg<__type>(__a, __c, __x);
1161 }
1162
1163 inline float
1164 cyl_bessel_if(float __nu, float __x)
1165 { return __detail::__cyl_bessel_i<float>(__nu, __x); }
1166
1167 inline long double
1168 cyl_bessel_il(long double __nu, long double __x)
1169 { return __detail::__cyl_bessel_i<long double>(__nu, __x); }
1170
1171 /// 5.2.1.8 Regular modified cylindrical Bessel functions.
1172 template<typename _Tpnu, typename _Tp>
1173 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1174 cyl_bessel_i(_Tpnu __nu, _Tp __x)
1175 {
1176 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1177 return __detail::__cyl_bessel_i<__type>(__nu, __x);
1178 }
1179
1180 inline float
1181 cyl_bessel_jf(float __nu, float __x)
1182 { return __detail::__cyl_bessel_j<float>(__nu, __x); }
1183
1184 inline long double
1185 cyl_bessel_jl(long double __nu, long double __x)
1186 { return __detail::__cyl_bessel_j<long double>(__nu, __x); }
1187
1188 /// 5.2.1.9 Cylindrical Bessel functions (of the first kind).
1189 template<typename _Tpnu, typename _Tp>
1190 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1191 cyl_bessel_j(_Tpnu __nu, _Tp __x)
1192 {
1193 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1194 return __detail::__cyl_bessel_j<__type>(__nu, __x);
1195 }
1196
1197 inline float
1198 cyl_bessel_kf(float __nu, float __x)
1199 { return __detail::__cyl_bessel_k<float>(__nu, __x); }
1200
1201 inline long double
1202 cyl_bessel_kl(long double __nu, long double __x)
1203 { return __detail::__cyl_bessel_k<long double>(__nu, __x); }
1204
1205 /// 5.2.1.10 Irregular modified cylindrical Bessel functions.
1206 template<typename _Tpnu, typename _Tp>
1207 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1208 cyl_bessel_k(_Tpnu __nu, _Tp __x)
1209 {
1210 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1211 return __detail::__cyl_bessel_k<__type>(__nu, __x);
1212 }
1213
1214 inline float
1215 cyl_neumannf(float __nu, float __x)
1216 { return __detail::__cyl_neumann_n<float>(__nu, __x); }
1217
1218 inline long double
1219 cyl_neumannl(long double __nu, long double __x)
1220 { return __detail::__cyl_neumann_n<long double>(__nu, __x); }
1221
1222 /// 5.2.1.11 Cylindrical Neumann functions.
1223 template<typename _Tpnu, typename _Tp>
1224 inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1225 cyl_neumann(_Tpnu __nu, _Tp __x)
1226 {
1227 typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1228 return __detail::__cyl_neumann_n<__type>(__nu, __x);
1229 }
1230
1231 inline float
1232 ellint_1f(float __k, float __phi)
1233 { return __detail::__ellint_1<float>(__k, __phi); }
1234
1235 inline long double
1236 ellint_1l(long double __k, long double __phi)
1237 { return __detail::__ellint_1<long double>(__k, __phi); }
1238
1239 /// 5.2.1.12 Incomplete elliptic integrals of the first kind.
1240 template<typename _Tp, typename _Tpp>
1241 inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
1242 ellint_1(_Tp __k, _Tpp __phi)
1243 {
1244 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
1245 return __detail::__ellint_1<__type>(__k, __phi);
1246 }
1247
1248 inline float
1249 ellint_2f(float __k, float __phi)
1250 { return __detail::__ellint_2<float>(__k, __phi); }
1251
1252 inline long double
1253 ellint_2l(long double __k, long double __phi)
1254 { return __detail::__ellint_2<long double>(__k, __phi); }
1255
1256 /// 5.2.1.13 Incomplete elliptic integrals of the second kind.
1257 template<typename _Tp, typename _Tpp>
1258 inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
1259 ellint_2(_Tp __k, _Tpp __phi)
1260 {
1261 typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
1262 return __detail::__ellint_2<__type>(__k, __phi);
1263 }
1264
1265 inline float
1266 ellint_3f(float __k, float __nu, float __phi)
1267 { return __detail::__ellint_3<float>(__k, __nu, __phi); }
1268
1269 inline long double
1270 ellint_3l(long double __k, long double __nu, long double __phi)
1271 { return __detail::__ellint_3<long double>(__k, __nu, __phi); }
1272
1273 /// 5.2.1.14 Incomplete elliptic integrals of the third kind.
1274 template<typename _Tp, typename _Tpn, typename _Tpp>
1275 inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type
1276 ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi)
1277 {
1278 typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type;
1279 return __detail::__ellint_3<__type>(__k, __nu, __phi);
1280 }
1281
1282 inline float
1283 expintf(float __x)
1284 { return __detail::__expint<float>(__x); }
1285
1286 inline long double
1287 expintl(long double __x)
1288 { return __detail::__expint<long double>(__x); }
1289
1290 /// 5.2.1.15 Exponential integrals.
1291 template<typename _Tp>
1292 inline typename __gnu_cxx::__promote<_Tp>::__type
1293 expint(_Tp __x)
1294 {
1295 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1296 return __detail::__expint<__type>(__x);
1297 }
1298
1299 inline float
1300 hermitef(unsigned int __n, float __x)
1301 { return __detail::__poly_hermite<float>(__n, __x); }
1302
1303 inline long double
1304 hermitel(unsigned int __n, long double __x)
1305 { return __detail::__poly_hermite<long double>(__n, __x); }
1306
1307 /// 5.2.1.16 Hermite polynomials.
1308 template<typename _Tp>
1309 inline typename __gnu_cxx::__promote<_Tp>::__type
1310 hermite(unsigned int __n, _Tp __x)
1311 {
1312 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1313 return __detail::__poly_hermite<__type>(__n, __x);
1314 }
1315
1316 inline float
1317 hypergf(float __a, float __b, float __c, float __x)
1318 { return __detail::__hyperg<float>(__a, __b, __c, __x); }
1319
1320 inline long double
1321 hypergl(long double __a, long double __b, long double __c, long double __x)
1322 { return __detail::__hyperg<long double>(__a, __b, __c, __x); }
1323
1324 /// 5.2.1.17 Hypergeometric functions.
1325 template<typename _Tpa, typename _Tpb, typename _Tpc, typename _Tp>
1326 inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type
1327 hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x)
1328 {
1329 typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type;
1330 return __detail::__hyperg<__type>(__a, __b, __c, __x);
1331 }
1332
1333 inline float
1334 laguerref(unsigned int __n, float __x)
1335 { return __detail::__laguerre<float>(__n, __x); }
1336
1337 inline long double
1338 laguerrel(unsigned int __n, long double __x)
1339 { return __detail::__laguerre<long double>(__n, __x); }
1340
1341 /// 5.2.1.18 Laguerre polynomials.
1342 template<typename _Tp>
1343 inline typename __gnu_cxx::__promote<_Tp>::__type
1344 laguerre(unsigned int __n, _Tp __x)
1345 {
1346 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1347 return __detail::__laguerre<__type>(__n, __x);
1348 }
1349
1350 inline float
1351 legendref(unsigned int __n, float __x)
1352 { return __detail::__poly_legendre_p<float>(__n, __x); }
1353
1354 inline long double
1355 legendrel(unsigned int __n, long double __x)
1356 { return __detail::__poly_legendre_p<long double>(__n, __x); }
1357
1358 /// 5.2.1.19 Legendre polynomials.
1359 template<typename _Tp>
1360 inline typename __gnu_cxx::__promote<_Tp>::__type
1361 legendre(unsigned int __n, _Tp __x)
1362 {
1363 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1364 return __detail::__poly_legendre_p<__type>(__n, __x);
1365 }
1366
1367 inline float
1368 riemann_zetaf(float __x)
1369 { return __detail::__riemann_zeta<float>(__x); }
1370
1371 inline long double
1372 riemann_zetal(long double __x)
1373 { return __detail::__riemann_zeta<long double>(__x); }
1374
1375 /// 5.2.1.20 Riemann zeta function.
1376 template<typename _Tp>
1377 inline typename __gnu_cxx::__promote<_Tp>::__type
1378 riemann_zeta(_Tp __x)
1379 {
1380 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1381 return __detail::__riemann_zeta<__type>(__x);
1382 }
1383
1384 inline float
1385 sph_besself(unsigned int __n, float __x)
1386 { return __detail::__sph_bessel<float>(__n, __x); }
1387
1388 inline long double
1389 sph_bessell(unsigned int __n, long double __x)
1390 { return __detail::__sph_bessel<long double>(__n, __x); }
1391
1392 /// 5.2.1.21 Spherical Bessel functions.
1393 template<typename _Tp>
1394 inline typename __gnu_cxx::__promote<_Tp>::__type
1395 sph_bessel(unsigned int __n, _Tp __x)
1396 {
1397 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1398 return __detail::__sph_bessel<__type>(__n, __x);
1399 }
1400
1401 inline float
1402 sph_legendref(unsigned int __l, unsigned int __m, float __theta)
1403 { return __detail::__sph_legendre<float>(__l, __m, __theta); }
1404
1405 inline long double
1406 sph_legendrel(unsigned int __l, unsigned int __m, long double __theta)
1407 { return __detail::__sph_legendre<long double>(__l, __m, __theta); }
1408
1409 /// 5.2.1.22 Spherical associated Legendre functions.
1410 template<typename _Tp>
1411 inline typename __gnu_cxx::__promote<_Tp>::__type
1412 sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta)
1413 {
1414 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1415 return __detail::__sph_legendre<__type>(__l, __m, __theta);
1416 }
1417
1418 inline float
1419 sph_neumannf(unsigned int __n, float __x)
1420 { return __detail::__sph_neumann<float>(__n, __x); }
1421
1422 inline long double
1423 sph_neumannl(unsigned int __n, long double __x)
1424 { return __detail::__sph_neumann<long double>(__n, __x); }
1425
1426 /// 5.2.1.23 Spherical Neumann functions.
1427 template<typename _Tp>
1428 inline typename __gnu_cxx::__promote<_Tp>::__type
1429 sph_neumann(unsigned int __n, _Tp __x)
1430 {
1431 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1432 return __detail::__sph_neumann<__type>(__n, __x);
1433 }
1434
1435 /* @} */ // tr1_math_spec_func
1436 _GLIBCXX_END_NAMESPACE_VERSION
1437 }
1438 }
1439
1440 #endif // _GLIBCXX_TR1_CMATH
1441