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