1 // -*- C++ -*- C forwarding header.
2 
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21 
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30 
31 //
32 // ISO C++ 14882: 26.5  C library
33 //
34 
35 /** @file cmath
36  *  This is a Standard C++ Library file.  You should @c #include this file
37  *  in your programs, rather than any of the "*.h" implementation files.
38  *
39  *  This is the C++ version of the Standard C Library header @c math.h,
40  *  and its contents are (mostly) the same as that header, but are all
41  *  contained in the namespace @c std.
42  */
43 
44 #ifndef _CPP_CMATH
45 #define _CPP_CMATH 1
46 
47 #pragma GCC system_header
48 
49 #include <bits/c++config.h>
50 
51 #include <math.h>
52 
53 // Get rid of those macros defined in <math.h> in lieu of real functions.
54 #undef abs
55 #undef div
56 #undef acos
57 #undef asin
58 #undef atan
59 #undef atan2
60 #undef ceil
61 #undef cos
62 #undef cosh
63 #undef exp
64 #undef fabs
65 #undef floor
66 #undef fmod
67 #undef frexp
68 #undef ldexp
69 #undef log
70 #undef log10
71 #undef modf
72 #undef pow
73 #undef sin
74 #undef sinh
75 #undef sqrt
76 #undef tan
77 #undef tanh
78 
79 namespace std
80 {
81   // Forward declaration of a helper function.  This really should be
82   // an `exported' forward declaration.
83   template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
84 
85   template<typename _Tp>
86   inline _Tp
87     __cmath_abs(_Tp __x)
88     {
89       return __x < _Tp() ? -__x : __x;
90     }
91 
92   inline double
93   abs(double __x)
94   { return __builtin_fabs(__x); }
95 
96   inline float
97   abs(float __x)
98   { return __builtin_fabsf(__x); }
99 
100   inline long double
101   abs(long double __x)
102   { return __builtin_fabsl(__x); }
103 
104 #if _GLIBCPP_HAVE_ACOSF
105   inline float
106   acos(float __x) { return ::acosf(__x); }
107 #else
108   inline float
109   acos(float __x) { return ::acos(static_cast<double>(__x)); }
110 #endif
111 
112   using ::acos;
113 
114 #if _GLIBCPP_HAVE_ACOSL
115   inline long double
116   acos(long double __x) { return ::acosl(__x); }
117 #else
118   inline long double
119   acos(long double __x) { return ::acos(static_cast<double>(__x)); }
120 #endif
121 
122   using ::asin;
123 
124 #if _GLIBCPP_HAVE_ASINF
125   inline float
126   asin(float __x) { return ::asinf(__x); }
127 #else
128   inline float
129   asin(float __x) { return ::asin(static_cast<double>(__x)); }
130 #endif
131 
132 #if _GLIBCPP_HAVE_ASINL
133   inline long double
134   asin(long double __x) { return ::asinl(__x); }
135 #else
136   inline long double
137   asin(long double __x) { return ::asin(static_cast<double>(__x)); }
138 #endif
139 
140   using ::atan;
141 
142 #if _GLIBCPP_HAVE_ATANF
143   inline float
144   atan(float __x) { return ::atanf(__x); }
145 #else
146   inline float
147   atan(float __x) { return ::atan(static_cast<double>(__x)); }
148 #endif
149 
150 #if _GLIBCPP_HAVE_ATANL
151   inline long double
152   atan(long double __x) { return ::atanl(__x); }
153 #else
154   inline long double
155   atan(long double __x) { return ::atan(static_cast<double>(__x)); }
156 #endif
157 
158   using ::atan2;
159 
160 #if _GLIBCPP_HAVE_ATAN2F
161   inline float
162   atan2(float __y, float __x) { return ::atan2f(__y, __x); }
163 #else
164   inline float
165   atan2(float __y, float __x)
166   { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
167 #endif
168 
169 #if _GLIBCPP_HAVE_ATAN2L
170   inline long double
171   atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
172 #else
173   inline long double
174   atan2(long double __y, long double __x)
175   { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
176 #endif
177 
178   using ::ceil;
179 
180 #if _GLIBCPP_HAVE_CEILF
181   inline float
182   ceil(float __x) { return ::ceilf(__x); }
183 #else
184   inline float
185   ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
186 #endif
187 
188 #if _GLIBCPP_HAVE_CEILL
189   inline long double
190   ceil(long double __x) { return ::ceill(__x); }
191 #else
192   inline long double
193   ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
194 #endif
195 
196   using ::cos;
197 
198   inline float
199   cos(float __x)
200   { return __builtin_cosf(__x); }
201 
202   inline long double
203   cos(long double __x)
204   { return __builtin_cosl(__x); }
205 
206   using ::cosh;
207 
208 #if _GLIBCPP_HAVE_COSHF
209   inline float
210   cosh(float __x) { return ::coshf(__x); }
211 #else
212   inline float
213   cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
214 #endif
215 
216 #if _GLIBCPP_HAVE_COSHL
217   inline long double
218   cosh(long double __x) { return ::coshl(__x); }
219 #else
220   inline long double
221   cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
222 #endif
223 
224   using ::exp;
225 
226 #if _GLIBCPP_HAVE_EXPF
227   inline float
228   exp(float __x) { return ::expf(__x); }
229 #else
230   inline float
231   exp(float __x) { return ::exp(static_cast<double>(__x)); }
232 #endif
233 
234 #if _GLIBCPP_HAVE_EXPL
235   inline long double
236   exp(long double __x) { return ::expl(__x); }
237 #else
238   inline long double
239   exp(long double __x) { return ::exp(static_cast<double>(__x)); }
240 #endif
241 
242   using ::fabs;
243 
244   inline float
245   fabs(float __x)
246   { return __builtin_fabsf(__x); }
247 
248   inline long double
249   fabs(long double __x)
250   { return __builtin_fabsl(__x); }
251 
252   using ::floor;
253 
254 #if _GLIBCPP_HAVE_FLOORF
255   inline float
256   floor(float __x) { return ::floorf(__x); }
257 #else
258   inline float
259   floor(float __x) { return ::floor(static_cast<double>(__x)); }
260 #endif
261 
262 #if _GLIBCPP_HAVE_FLOORL
263   inline long double
264   floor(long double __x) { return ::floorl(__x); }
265 #else
266   inline long double
267   floor(long double __x) { return ::floor(static_cast<double>(__x)); }
268 #endif
269 
270   using ::fmod;
271 
272 #if _GLIBCPP_HAVE_FMODF
273   inline float
274   fmod(float __x, float __y) { return ::fmodf(__x, __y); }
275 #else
276   inline float
277   fmod(float __x, float __y)
278   { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
279 #endif
280 
281 #if _GLIBCPP_HAVE_FMODL
282   inline long double
283   fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
284 #else
285   inline long double
286   fmod(long double __x, long double __y)
287   { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
288 #endif
289 
290   using ::frexp;
291 
292 #if _GLIBCPP_HAVE_FREXPF
293   inline float
294   frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
295 #else
296   inline float
297   frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
298 #endif
299 
300 #if _GLIBCPP_HAVE_FREXPL
301   inline long double
302   frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
303 #else
304   inline long double
305   frexp(long double __x, int* __exp)
306   { return ::frexp(static_cast<double>(__x), __exp); }
307 #endif
308 
309   using ::ldexp;
310 
311 #if _GLIBCPP_HAVE_LDEXPF
312   inline float
313   ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
314 #else
315   inline float
316   ldexp(float __x, int __exp)
317   { return ::ldexp(static_cast<double>(__x), __exp); }
318 #endif
319 
320 #if _GLIBCPP_HAVE_LDEXPL
321   inline long double
322   ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
323 #else
324   inline long double
325   ldexp(long double __x, int __exp)
326   { return ::ldexp(static_cast<double>(__x), __exp); }
327 #endif
328 
329   using ::log;
330 
331 #if _GLIBCPP_HAVE_LOGF
332   inline float
333   log(float __x) { return ::logf(__x); }
334 #else
335   inline float log(float __x)
336   { return ::log(static_cast<double>(__x)); }
337 #endif
338 
339 #if _GLIBCPP_HAVE_LOGL
340   inline long double
341   log(long double __x) { return ::logl(__x); }
342 #else
343   inline long double
344   log(long double __x) { return ::log(static_cast<double>(__x)); }
345 #endif
346 
347   using ::log10;
348 
349 #if _GLIBCPP_HAVE_LOG10F
350   inline float
351   log10(float __x) { return ::log10f(__x); }
352 #else
353   inline float
354   log10(float __x) { return ::log10(static_cast<double>(__x)); }
355 #endif
356 
357 #if _GLIBCPP_HAVE_LOG10L
358   inline long double
359   log10(long double __x) { return ::log10l(__x); }
360 #else
361   inline long double
362   log10(long double __x) { return ::log10(static_cast<double>(__x)); }
363 #endif
364 
365   using ::modf;
366 
367 #if _GLIBCPP_HAVE_MODFF
368   inline float
369   modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
370 #else
371   inline float
372   modf(float __x, float* __iptr)
373   {
374     double __tmp;
375     double __res = ::modf(static_cast<double>(__x), &__tmp);
376     *__iptr = static_cast<float>(__tmp);
377     return __res;
378   }
379 #endif
380 
381 #if _GLIBCPP_HAVE_MODFL
382   inline long double
383   modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
384 #else
385   inline long double
386   modf(long double __x, long double* __iptr)
387   {
388     double __tmp;
389     double __res = ::modf(static_cast<double>(__x), &__tmp);
390     * __iptr = static_cast<long double>(__tmp);
391     return __res;
392   }
393 #endif
394 
395   template<typename _Tp>
396     inline _Tp
397     __pow_helper(_Tp __x, int __n)
398     {
399       return __n < 0
400         ? _Tp(1)/__cmath_power(__x, -__n)
401         : __cmath_power(__x, __n);
402     }
403 
404   using ::pow;
405 
406 #if _GLIBCPP_HAVE_POWF
407   inline float
408   pow(float __x, float __y) { return ::powf(__x, __y); }
409 #else
410   inline float
411   pow(float __x, float __y)
412   { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
413 #endif
414 
415 #if _GLIBCPP_HAVE_POWL
416   inline long double
417   pow(long double __x, long double __y) { return ::powl(__x, __y); }
418 #else
419   inline long double
420   pow(long double __x, long double __y)
421   { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
422 #endif
423 
424   inline double
425   pow(double __x, int __i)
426   { return __pow_helper(__x, __i); }
427 
428   inline float
429   pow(float __x, int __n)
430   { return __pow_helper(__x, __n); }
431 
432   inline long double
433   pow(long double __x, int __n)
434   { return __pow_helper(__x, __n); }
435 
436   using ::sin;
437 
438   inline float
439   sin(float __x)
440   { return __builtin_sinf(__x); }
441 
442   inline long double
443   sin(long double __x)
444   { return __builtin_sinl(__x); }
445 
446   using ::sinh;
447 
448 #if _GLIBCPP_HAVE_SINHF
449   inline float
450   sinh(float __x) { return ::sinhf(__x); }
451 #else
452   inline float
453   sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
454 #endif
455 
456 #if _GLIBCPP_HAVE_SINHL
457   inline long double
458   sinh(long double __x) { return ::sinhl(__x); }
459 #else
460   inline long double
461   sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
462 #endif
463 
464   using ::sqrt;
465 
466   inline float
467   sqrt(float __x)
468   { return __builtin_sqrtf(__x); }
469 
470   inline long double
471   sqrt(long double __x)
472   { return __builtin_sqrtl(__x); }
473 
474   using ::tan;
475 
476 #if _GLIBCPP_HAVE_TANF
477   inline float
478   tan(float __x) { return ::tanf(__x); }
479 #else
480   inline float
481   tan(float __x) { return ::tan(static_cast<double>(__x)); }
482 #endif
483 
484 #if _GLIBCPP_HAVE_TANL
485   inline long double
486   tan(long double __x) { return ::tanl(__x); }
487 #else
488   inline long double
489   tan(long double __x) { return ::tan(static_cast<double>(__x)); }
490 #endif
491 
492   using ::tanh;
493 
494 #if _GLIBCPP_HAVE_TANHF
495   inline float
496   tanh(float __x) { return ::tanhf(__x); }
497 #else
498   inline float
499   tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
500 #endif
501 
502 #if _GLIBCPP_HAVE_TANHL
503   inline long double
504   tanh(long double __x) { return ::tanhl(__x); }
505 #else
506   inline long double
507   tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
508 #endif
509 }
510 
511 
512 #if _GLIBCPP_USE_C99
513 // These are possible macros imported from C99-land. For strict
514 // conformance, remove possible C99-injected names from the global
515 // namespace, and sequester them in the __gnu_cxx extension namespace.
516 namespace __gnu_cxx
517 {
518   template<typename _Tp>
519     int
520     __capture_fpclassify(_Tp __f) { return fpclassify(__f); }
521 
522   template<typename _Tp>
523     int
524     __capture_isfinite(_Tp __f) { return isfinite(__f); }
525 
526   template<typename _Tp>
527     int
528     __capture_isinf(_Tp __f) { return isinf(__f); }
529 
530   template<typename _Tp>
531     int
532     __capture_isnan(_Tp __f) { return isnan(__f); }
533 
534   template<typename _Tp>
535     int
536     __capture_isnormal(_Tp __f) { return isnormal(__f); }
537 
538   template<typename _Tp>
539     int
540     __capture_signbit(_Tp __f) { return signbit(__f); }
541 
542   template<typename _Tp>
543     int
544     __capture_isgreater(_Tp __f1, _Tp __f2)
545     { return isgreater(__f1, __f2); }
546 
547   template<typename _Tp>
548      int
549      __capture_isgreaterequal(_Tp __f1, _Tp __f2)
550      { return isgreaterequal(__f1, __f2); }
551 
552   template<typename _Tp>
553      int
554      __capture_isless(_Tp __f1, _Tp __f2) { return isless(__f1, __f2); }
555 
556   template<typename _Tp>
557      int
558      __capture_islessequal(_Tp __f1, _Tp __f2)
559      { return islessequal(__f1, __f2); }
560 
561   template<typename _Tp>
562      int
563      __capture_islessgreater(_Tp __f1, _Tp __f2)
564      { return islessgreater(__f1, __f2); }
565 
566   template<typename _Tp>
567      int
568      __capture_isunordered(_Tp __f1, _Tp __f2)
569      { return isunordered(__f1, __f2); }
570 }
571 #endif
572 
573 #undef fpclassify
574 #undef isfinite
575 #undef isinf
576 #undef isnan
577 #undef isnormal
578 #undef signbit
579 #undef isgreater
580 #undef isgreaterequal
581 #undef isless
582 #undef islessequal
583 #undef islessgreater
584 #undef isunordered
585 
586 #if _GLIBCPP_USE_C99
587 namespace __gnu_cxx
588 {
589   template<typename _Tp>
590     int
591     fpclassify(_Tp __f) { return __capture_fpclassify(__f); }
592 
593   template<typename _Tp>
594     int
595     isfinite(_Tp __f) { return __capture_isfinite(__f); }
596 
597   template<typename _Tp>
598     int
599     isinf(_Tp __f) { return __capture_isinf(__f); }
600 
601   template<typename _Tp>
602     int
603     isnan(_Tp __f) { return __capture_isnan(__f); }
604 
605   template<typename _Tp>
606     int
607     isnormal(_Tp __f) { return __capture_isnormal(__f); }
608 
609   template<typename _Tp>
610     int
611     signbit(_Tp __f) { return __capture_signbit(__f); }
612 
613   template<typename _Tp>
614     int
615     isgreater(_Tp __f1, _Tp __f2) { return __capture_isgreater(__f1, __f2); }
616 
617   template<typename _Tp>
618     int
619     isgreaterequal(_Tp __f1, _Tp __f2)
620     { return __capture_isgreaterequal(__f1, __f2); }
621 
622   template<typename _Tp>
623     int
624     isless(_Tp __f1, _Tp __f2) { return __capture_isless(__f1, __f2); }
625 
626   template<typename _Tp>
627     int
628     islessequal(_Tp __f1, _Tp __f2)
629     { return __capture_islessequal(__f1, __f2); }
630 
631   template<typename _Tp>
632     int
633     islessgreater(_Tp __f1, _Tp __f2)
634     { return __capture_islessgreater(__f1, __f2); }
635 
636   template<typename _Tp>
637     int
638     isunordered(_Tp __f1, _Tp __f2)
639     { return __capture_isunordered(__f1, __f2); }
640 }
641 
642 namespace std
643 {
644   using __gnu_cxx::fpclassify;
645   using __gnu_cxx::isfinite;
646   using __gnu_cxx::isinf;
647   using __gnu_cxx::isnan;
648   using __gnu_cxx::isnormal;
649   using __gnu_cxx::signbit;
650   using __gnu_cxx::isgreater;
651   using __gnu_cxx::isgreaterequal;
652   using __gnu_cxx::isless;
653   using __gnu_cxx::islessequal;
654   using __gnu_cxx::islessgreater;
655   using __gnu_cxx::isunordered;
656 }
657 #endif
658 
659 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
660 #  define export
661 #  include <bits/cmath.tcc>
662 #endif
663 
664 #endif
665