1// TR1 cmath -*- C++ -*-
2
3// Copyright (C) 2006-2014 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
146namespace std _GLIBCXX_VISIBILITY(default)
147{
148namespace 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  inline float
850  remainder(float __x, float __y)
851  { return __builtin_remainderf(__x, __y); }
852
853  inline long double
854  remainder(long double __x, long double __y)
855  { return __builtin_remainderl(__x, __y); }
856
857  template<typename _Tp, typename _Up>
858    inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
859    remainder(_Tp __x, _Up __y)
860    {
861      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
862      return remainder(__type(__x), __type(__y));
863    }
864
865  inline float
866  remquo(float __x, float __y, int* __pquo)
867  { return __builtin_remquof(__x, __y, __pquo); }
868
869  inline long double
870  remquo(long double __x, long double __y, int* __pquo)
871  { return __builtin_remquol(__x, __y, __pquo); }
872
873  template<typename _Tp, typename _Up>
874    inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
875    remquo(_Tp __x, _Up __y, int* __pquo)
876    {
877      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
878      return remquo(__type(__x), __type(__y), __pquo);
879    }
880
881  inline float
882  rint(float __x)
883  { return __builtin_rintf(__x); }
884
885  inline long double
886  rint(long double __x)
887  { return __builtin_rintl(__x); }
888
889  template<typename _Tp>
890    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
891					   double>::__type
892    rint(_Tp __x)
893    { return __builtin_rint(__x); }
894
895  inline float
896  round(float __x)
897  { return __builtin_roundf(__x); }
898
899  inline long double
900  round(long double __x)
901  { return __builtin_roundl(__x); }
902
903  template<typename _Tp>
904    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
905					   double>::__type
906    round(_Tp __x)
907    { return __builtin_round(__x); }
908
909  inline float
910  scalbln(float __x, long __ex)
911  { return __builtin_scalblnf(__x, __ex); }
912
913  inline long double
914  scalbln(long double __x, long __ex)
915  { return __builtin_scalblnl(__x, __ex); }
916
917  template<typename _Tp>
918    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
919					   double>::__type
920    scalbln(_Tp __x, long __ex)
921    { return __builtin_scalbln(__x, __ex); }
922
923  inline float
924  scalbn(float __x, int __ex)
925  { return __builtin_scalbnf(__x, __ex); }
926
927  inline long double
928  scalbn(long double __x, int __ex)
929  { return __builtin_scalbnl(__x, __ex); }
930
931  template<typename _Tp>
932    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
933					   double>::__type
934    scalbn(_Tp __x, int __ex)
935    { return __builtin_scalbn(__x, __ex); }
936
937  using std::sin;
938  using std::sinh;
939  using std::sqrt;
940  using std::tan;
941  using std::tanh;
942
943  inline float
944  tgamma(float __x)
945  { return __builtin_tgammaf(__x); }
946
947  inline long double
948  tgamma(long double __x)
949  { return __builtin_tgammal(__x); }
950
951  template<typename _Tp>
952    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
953					   double>::__type
954    tgamma(_Tp __x)
955    { return __builtin_tgamma(__x); }
956
957  inline float
958  trunc(float __x)
959  { return __builtin_truncf(__x); }
960
961  inline long double
962  trunc(long double __x)
963  { return __builtin_truncl(__x); }
964
965  template<typename _Tp>
966    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
967					   double>::__type
968    trunc(_Tp __x)
969    { return __builtin_trunc(__x); }
970
971#endif
972_GLIBCXX_END_NAMESPACE_VERSION
973}
974}
975
976namespace std _GLIBCXX_VISIBILITY(default)
977{
978namespace tr1
979{
980_GLIBCXX_BEGIN_NAMESPACE_VERSION
981
982  // DR 550. What should the return type of pow(float,int) be?
983  // NB: C++0x and TR1 != C++03.
984
985  // The std::tr1::pow(double, double) overload cannot be provided
986  // here, because it would clash with ::pow(double,double) declared
987  // in <math.h>, if <tr1/math.h> is included at the same time (raised
988  // by the fix of PR c++/54537). It is not possible either to use the
989  // using-declaration 'using ::pow;' here, because if the user code
990  // has a 'using std::pow;', it would bring the pow(*,int) averloads
991  // in the tr1 namespace, which is undesirable. Consequently, the
992  // solution is to forward std::tr1::pow(double,double) to
993  // std::pow(double,double) via the templatized version below. See
994  // the discussion about this issue here:
995  // http://gcc.gnu.org/ml/gcc-patches/2012-09/msg01278.html
996
997  inline float
998  pow(float __x, float __y)
999  { return std::pow(__x, __y); }
1000
1001  inline long double
1002  pow(long double __x, long double __y)
1003  { return std::pow(__x, __y); }
1004
1005  template<typename _Tp, typename _Up>
1006    inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type
1007    pow(_Tp __x, _Up __y)
1008    {
1009      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1010      return std::pow(__type(__x), __type(__y));
1011    }
1012
1013_GLIBCXX_END_NAMESPACE_VERSION
1014}
1015}
1016
1017#include <bits/stl_algobase.h>
1018#include <limits>
1019#include <tr1/type_traits>
1020
1021#include <tr1/gamma.tcc>
1022#include <tr1/bessel_function.tcc>
1023#include <tr1/beta_function.tcc>
1024#include <tr1/ell_integral.tcc>
1025#include <tr1/exp_integral.tcc>
1026#include <tr1/hypergeometric.tcc>
1027#include <tr1/legendre_function.tcc>
1028#include <tr1/modified_bessel_func.tcc>
1029#include <tr1/poly_hermite.tcc>
1030#include <tr1/poly_laguerre.tcc>
1031#include <tr1/riemann_zeta.tcc>
1032
1033namespace std _GLIBCXX_VISIBILITY(default)
1034{
1035namespace tr1
1036{
1037_GLIBCXX_BEGIN_NAMESPACE_VERSION
1038
1039  /**
1040   * @defgroup tr1_math_spec_func Mathematical Special Functions
1041   * @ingroup numerics
1042   *
1043   * A collection of advanced mathematical special functions.
1044   * @{
1045   */
1046
1047  inline float
1048  assoc_laguerref(unsigned int __n, unsigned int __m, float __x)
1049  { return __detail::__assoc_laguerre<float>(__n, __m, __x); }
1050
1051  inline long double
1052  assoc_laguerrel(unsigned int __n, unsigned int __m, long double __x)
1053  {
1054    return __detail::__assoc_laguerre<long double>(__n, __m, __x);
1055  }
1056
1057  ///  5.2.1.1  Associated Laguerre polynomials.
1058  template<typename _Tp>
1059    inline typename __gnu_cxx::__promote<_Tp>::__type
1060    assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
1061    {
1062      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1063      return __detail::__assoc_laguerre<__type>(__n, __m, __x);
1064    }
1065
1066  inline float
1067  assoc_legendref(unsigned int __l, unsigned int __m, float __x)
1068  { return __detail::__assoc_legendre_p<float>(__l, __m, __x); }
1069
1070  inline long double
1071  assoc_legendrel(unsigned int __l, unsigned int __m, long double __x)
1072  { return __detail::__assoc_legendre_p<long double>(__l, __m, __x); }
1073
1074  ///  5.2.1.2  Associated Legendre functions.
1075  template<typename _Tp>
1076    inline typename __gnu_cxx::__promote<_Tp>::__type
1077    assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x)
1078    {
1079      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1080      return __detail::__assoc_legendre_p<__type>(__l, __m, __x);
1081    }
1082
1083  inline float
1084  betaf(float __x, float __y)
1085  { return __detail::__beta<float>(__x, __y); }
1086
1087  inline long double
1088  betal(long double __x, long double __y)
1089  { return __detail::__beta<long double>(__x, __y); }
1090
1091  ///  5.2.1.3  Beta functions.
1092  template<typename _Tpx, typename _Tpy>
1093    inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type
1094    beta(_Tpx __x, _Tpy __y)
1095    {
1096      typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type;
1097      return __detail::__beta<__type>(__x, __y);
1098    }
1099
1100  inline float
1101  comp_ellint_1f(float __k)
1102  { return __detail::__comp_ellint_1<float>(__k); }
1103
1104  inline long double
1105  comp_ellint_1l(long double __k)
1106  { return __detail::__comp_ellint_1<long double>(__k); }
1107
1108  ///  5.2.1.4  Complete elliptic integrals of the first kind.
1109  template<typename _Tp>
1110    inline typename __gnu_cxx::__promote<_Tp>::__type
1111    comp_ellint_1(_Tp __k)
1112    {
1113      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1114      return __detail::__comp_ellint_1<__type>(__k);
1115    }
1116
1117  inline float
1118  comp_ellint_2f(float __k)
1119  { return __detail::__comp_ellint_2<float>(__k); }
1120
1121  inline long double
1122  comp_ellint_2l(long double __k)
1123  { return __detail::__comp_ellint_2<long double>(__k); }
1124
1125  ///  5.2.1.5  Complete elliptic integrals of the second kind.
1126  template<typename _Tp>
1127    inline typename __gnu_cxx::__promote<_Tp>::__type
1128    comp_ellint_2(_Tp __k)
1129    {
1130      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1131      return __detail::__comp_ellint_2<__type>(__k);
1132    }
1133
1134  inline float
1135  comp_ellint_3f(float __k, float __nu)
1136  { return __detail::__comp_ellint_3<float>(__k, __nu); }
1137
1138  inline long double
1139  comp_ellint_3l(long double __k, long double __nu)
1140  { return __detail::__comp_ellint_3<long double>(__k, __nu); }
1141
1142  ///  5.2.1.6  Complete elliptic integrals of the third kind.
1143  template<typename _Tp, typename _Tpn>
1144    inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type
1145    comp_ellint_3(_Tp __k, _Tpn __nu)
1146    {
1147      typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type;
1148      return __detail::__comp_ellint_3<__type>(__k, __nu);
1149    }
1150
1151  inline float
1152  conf_hypergf(float __a, float __c, float __x)
1153  { return __detail::__conf_hyperg<float>(__a, __c, __x); }
1154
1155  inline long double
1156  conf_hypergl(long double __a, long double __c, long double __x)
1157  { return __detail::__conf_hyperg<long double>(__a, __c, __x); }
1158
1159  ///  5.2.1.7  Confluent hypergeometric functions.
1160  template<typename _Tpa, typename _Tpc, typename _Tp>
1161    inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type
1162    conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x)
1163    {
1164      typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type;
1165      return __detail::__conf_hyperg<__type>(__a, __c, __x);
1166    }
1167
1168  inline float
1169  cyl_bessel_if(float __nu, float __x)
1170  { return __detail::__cyl_bessel_i<float>(__nu, __x); }
1171
1172  inline long double
1173  cyl_bessel_il(long double __nu, long double __x)
1174  { return __detail::__cyl_bessel_i<long double>(__nu, __x); }
1175
1176  ///  5.2.1.8  Regular modified cylindrical Bessel functions.
1177  template<typename _Tpnu, typename _Tp>
1178    inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1179    cyl_bessel_i(_Tpnu __nu, _Tp __x)
1180    {
1181      typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1182      return __detail::__cyl_bessel_i<__type>(__nu, __x);
1183    }
1184
1185  inline float
1186  cyl_bessel_jf(float __nu, float __x)
1187  { return __detail::__cyl_bessel_j<float>(__nu, __x); }
1188
1189  inline long double
1190  cyl_bessel_jl(long double __nu, long double __x)
1191  { return __detail::__cyl_bessel_j<long double>(__nu, __x); }
1192
1193  ///  5.2.1.9  Cylindrical Bessel functions (of the first kind).
1194  template<typename _Tpnu, typename _Tp>
1195    inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1196    cyl_bessel_j(_Tpnu __nu, _Tp __x)
1197    {
1198      typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1199      return __detail::__cyl_bessel_j<__type>(__nu, __x);
1200    }
1201
1202  inline float
1203  cyl_bessel_kf(float __nu, float __x)
1204  { return __detail::__cyl_bessel_k<float>(__nu, __x); }
1205
1206  inline long double
1207  cyl_bessel_kl(long double __nu, long double __x)
1208  { return __detail::__cyl_bessel_k<long double>(__nu, __x); }
1209
1210  ///  5.2.1.10  Irregular modified cylindrical Bessel functions.
1211  template<typename _Tpnu, typename _Tp>
1212    inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1213    cyl_bessel_k(_Tpnu __nu, _Tp __x)
1214    {
1215      typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1216      return __detail::__cyl_bessel_k<__type>(__nu, __x);
1217    }
1218
1219  inline float
1220  cyl_neumannf(float __nu, float __x)
1221  { return __detail::__cyl_neumann_n<float>(__nu, __x); }
1222
1223  inline long double
1224  cyl_neumannl(long double __nu, long double __x)
1225  { return __detail::__cyl_neumann_n<long double>(__nu, __x); }
1226
1227  ///  5.2.1.11  Cylindrical Neumann functions.
1228  template<typename _Tpnu, typename _Tp>
1229    inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type
1230    cyl_neumann(_Tpnu __nu, _Tp __x)
1231    {
1232      typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type;
1233      return __detail::__cyl_neumann_n<__type>(__nu, __x);
1234    }
1235
1236  inline float
1237  ellint_1f(float __k, float __phi)
1238  { return __detail::__ellint_1<float>(__k, __phi); }
1239
1240  inline long double
1241  ellint_1l(long double __k, long double __phi)
1242  { return __detail::__ellint_1<long double>(__k, __phi); }
1243
1244  ///  5.2.1.12  Incomplete elliptic integrals of the first kind.
1245  template<typename _Tp, typename _Tpp>
1246    inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
1247    ellint_1(_Tp __k, _Tpp __phi)
1248    {
1249      typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
1250      return __detail::__ellint_1<__type>(__k, __phi);
1251    }
1252
1253  inline float
1254  ellint_2f(float __k, float __phi)
1255  { return __detail::__ellint_2<float>(__k, __phi); }
1256
1257  inline long double
1258  ellint_2l(long double __k, long double __phi)
1259  { return __detail::__ellint_2<long double>(__k, __phi); }
1260
1261  ///  5.2.1.13  Incomplete elliptic integrals of the second kind.
1262  template<typename _Tp, typename _Tpp>
1263    inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type
1264    ellint_2(_Tp __k, _Tpp __phi)
1265    {
1266      typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type;
1267      return __detail::__ellint_2<__type>(__k, __phi);
1268    }
1269
1270  inline float
1271  ellint_3f(float __k, float __nu, float __phi)
1272  { return __detail::__ellint_3<float>(__k, __nu, __phi); }
1273
1274  inline long double
1275  ellint_3l(long double __k, long double __nu, long double __phi)
1276  { return __detail::__ellint_3<long double>(__k, __nu, __phi); }
1277
1278  ///  5.2.1.14  Incomplete elliptic integrals of the third kind.
1279  template<typename _Tp, typename _Tpn, typename _Tpp>
1280    inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type
1281    ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi)
1282    {
1283      typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type;
1284      return __detail::__ellint_3<__type>(__k, __nu, __phi);
1285    }
1286
1287  inline float
1288  expintf(float __x)
1289  { return __detail::__expint<float>(__x); }
1290
1291  inline long double
1292  expintl(long double __x)
1293  { return __detail::__expint<long double>(__x); }
1294
1295  ///  5.2.1.15  Exponential integrals.
1296  template<typename _Tp>
1297    inline typename __gnu_cxx::__promote<_Tp>::__type
1298    expint(_Tp __x)
1299    {
1300      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1301      return __detail::__expint<__type>(__x);
1302    }
1303
1304  inline float
1305  hermitef(unsigned int __n, float __x)
1306  { return __detail::__poly_hermite<float>(__n, __x); }
1307
1308  inline long double
1309  hermitel(unsigned int __n, long double __x)
1310  { return __detail::__poly_hermite<long double>(__n, __x); }
1311
1312  ///  5.2.1.16  Hermite polynomials.
1313  template<typename _Tp>
1314    inline typename __gnu_cxx::__promote<_Tp>::__type
1315    hermite(unsigned int __n, _Tp __x)
1316    {
1317      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1318      return __detail::__poly_hermite<__type>(__n, __x);
1319    }
1320
1321  inline float
1322  hypergf(float __a, float __b, float __c, float __x)
1323  { return __detail::__hyperg<float>(__a, __b, __c, __x); }
1324
1325  inline long double
1326  hypergl(long double __a, long double __b, long double __c, long double __x)
1327  { return __detail::__hyperg<long double>(__a, __b, __c, __x); }
1328
1329  ///  5.2.1.17  Hypergeometric functions.
1330  template<typename _Tpa, typename _Tpb, typename _Tpc, typename _Tp>
1331    inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type
1332    hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x)
1333    {
1334      typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type;
1335      return __detail::__hyperg<__type>(__a, __b, __c, __x);
1336    }
1337
1338  inline float
1339  laguerref(unsigned int __n, float __x)
1340  { return __detail::__laguerre<float>(__n, __x); }
1341
1342  inline long double
1343  laguerrel(unsigned int __n, long double __x)
1344  { return __detail::__laguerre<long double>(__n, __x); }
1345
1346  ///  5.2.1.18  Laguerre polynomials.
1347  template<typename _Tp>
1348    inline typename __gnu_cxx::__promote<_Tp>::__type
1349    laguerre(unsigned int __n, _Tp __x)
1350    {
1351      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1352      return __detail::__laguerre<__type>(__n, __x);
1353    }
1354
1355  inline float
1356  legendref(unsigned int __n, float __x)
1357  { return __detail::__poly_legendre_p<float>(__n, __x); }
1358
1359  inline long double
1360  legendrel(unsigned int __n, long double __x)
1361  { return __detail::__poly_legendre_p<long double>(__n, __x); }
1362
1363  ///  5.2.1.19  Legendre polynomials.
1364  template<typename _Tp>
1365    inline typename __gnu_cxx::__promote<_Tp>::__type
1366    legendre(unsigned int __n, _Tp __x)
1367    {
1368      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1369      return __detail::__poly_legendre_p<__type>(__n, __x);
1370    }
1371
1372  inline float
1373  riemann_zetaf(float __x)
1374  { return __detail::__riemann_zeta<float>(__x); }
1375
1376  inline long double
1377  riemann_zetal(long double __x)
1378  { return __detail::__riemann_zeta<long double>(__x); }
1379
1380  ///  5.2.1.20  Riemann zeta function.
1381  template<typename _Tp>
1382    inline typename __gnu_cxx::__promote<_Tp>::__type
1383    riemann_zeta(_Tp __x)
1384    {
1385      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1386      return __detail::__riemann_zeta<__type>(__x);
1387    }
1388
1389  inline float
1390  sph_besself(unsigned int __n, float __x)
1391  { return __detail::__sph_bessel<float>(__n, __x); }
1392
1393  inline long double
1394  sph_bessell(unsigned int __n, long double __x)
1395  { return __detail::__sph_bessel<long double>(__n, __x); }
1396
1397  ///  5.2.1.21  Spherical Bessel functions.
1398  template<typename _Tp>
1399    inline typename __gnu_cxx::__promote<_Tp>::__type
1400    sph_bessel(unsigned int __n, _Tp __x)
1401    {
1402      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1403      return __detail::__sph_bessel<__type>(__n, __x);
1404    }
1405
1406  inline float
1407  sph_legendref(unsigned int __l, unsigned int __m, float __theta)
1408  { return __detail::__sph_legendre<float>(__l, __m, __theta); }
1409
1410  inline long double
1411  sph_legendrel(unsigned int __l, unsigned int __m, long double __theta)
1412  { return __detail::__sph_legendre<long double>(__l, __m, __theta); }
1413
1414  ///  5.2.1.22  Spherical associated Legendre functions.
1415  template<typename _Tp>
1416    inline typename __gnu_cxx::__promote<_Tp>::__type
1417    sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta)
1418    {
1419      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1420      return __detail::__sph_legendre<__type>(__l, __m, __theta);
1421    }
1422
1423  inline float
1424  sph_neumannf(unsigned int __n, float __x)
1425  { return __detail::__sph_neumann<float>(__n, __x); }
1426
1427  inline long double
1428  sph_neumannl(unsigned int __n, long double __x)
1429  { return __detail::__sph_neumann<long double>(__n, __x); }
1430
1431  ///  5.2.1.23  Spherical Neumann functions.
1432  template<typename _Tp>
1433    inline typename __gnu_cxx::__promote<_Tp>::__type
1434    sph_neumann(unsigned int __n, _Tp __x)
1435    {
1436      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1437      return __detail::__sph_neumann<__type>(__n, __x);
1438    }
1439
1440  /* @} */ // tr1_math_spec_func
1441_GLIBCXX_END_NAMESPACE_VERSION
1442}
1443}
1444
1445#endif // _GLIBCXX_TR1_CMATH
1446