]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/c_std/cmath
builtins.def (BUILT_IN_ICEIL{,F,L}, [...]): New builtin definitions.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / cmath
CommitLineData
34ff0b99 1// -*- C++ -*- C forwarding header.
22aef514 2
0e7edcd5 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2a60a9f6 4// 2006, 2007, 2008, 2009, 2010
34ff0b99 5// Free Software Foundation, Inc.
22aef514
BK
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
748086b7 10// Free Software Foundation; either version 3, or (at your option)
22aef514
BK
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
748086b7
JJ
18// Under Section 7 of GPL version 3, you are granted additional
19// permissions described in the GCC Runtime Library Exception, version
20// 3.1, as published by the Free Software Foundation.
22aef514 21
748086b7
JJ
22// You should have received a copy of the GNU General Public License and
23// a copy of the GCC Runtime Library Exception along with this program;
24// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25// <http://www.gnu.org/licenses/>.
22aef514 26
143c27b0 27/** @file include/cmath
ffe94f83 28 * This is a Standard C++ Library file. You should @c #include this file
2a60a9f6 29 * in your programs, rather than any of the @a *.h implementation files.
ffe94f83
PE
30 *
31 * This is the C++ version of the Standard C Library header @c math.h,
32 * and its contents are (mostly) the same as that header, but are all
097588e4
PC
33 * contained in the namespace @c std (except for names which are defined
34 * as macros in C).
ffe94f83
PE
35 */
36
143c27b0
BK
37//
38// ISO C++ 14882: 26.5 C library
39//
40
1143680e
SE
41#ifndef _GLIBCXX_CMATH
42#define _GLIBCXX_CMATH 1
34ff0b99
BK
43
44#pragma GCC system_header
22aef514 45
98e6e789 46#include <bits/c++config.h>
cdc958d8 47#include <bits/cpp_type_traits.h>
105c6331 48#include <ext/type_traits.h>
4e588ec9 49
c0dae541 50#include <math.h>
22aef514 51
8089616e
BK
52// Get rid of those macros defined in <math.h> in lieu of real functions.
53#undef abs
54#undef div
55#undef acos
56#undef asin
57#undef atan
58#undef atan2
59#undef ceil
60#undef cos
61#undef cosh
62#undef exp
63#undef fabs
64#undef floor
65#undef fmod
66#undef frexp
67#undef ldexp
68#undef log
69#undef log10
70#undef modf
71#undef pow
72#undef sin
73#undef sinh
4200d6fe 74#undef sqrt
8089616e
BK
75#undef tan
76#undef tanh
77
12ffa228
BK
78namespace std _GLIBCXX_VISIBILITY(default)
79{
80_GLIBCXX_BEGIN_NAMESPACE_VERSION
b39d0359 81
4e588ec9
GDR
82 inline double
83 abs(double __x)
84 { return __builtin_fabs(__x); }
85
d52e4867
RS
86 inline float
87 abs(float __x)
88 { return __builtin_fabsf(__x); }
89
4e588ec9
GDR
90 inline long double
91 abs(long double __x)
92 { return __builtin_fabsl(__x); }
93
7cf8aefc
PC
94 template<typename _Tp>
95 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
96 double>::__type
97 abs(_Tp __x)
98 { return __builtin_fabs(__x); }
99
de96ac46 100 using ::acos;
c85dfef7
RS
101
102 inline float
103 acos(float __x)
104 { return __builtin_acosf(__x); }
105
106 inline long double
107 acos(long double __x)
108 { return __builtin_acosl(__x); }
4e588ec9 109
cdc958d8 110 template<typename _Tp>
105c6331
BK
111 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
112 double>::__type
cdc958d8 113 acos(_Tp __x)
105c6331 114 { return __builtin_acos(__x); }
7dd8177f 115
d52e4867
RS
116 using ::asin;
117
7dd8177f 118 inline float
c85dfef7
RS
119 asin(float __x)
120 { return __builtin_asinf(__x); }
22aef514 121
7dd8177f 122 inline long double
c85dfef7
RS
123 asin(long double __x)
124 { return __builtin_asinl(__x); }
4e588ec9 125
cdc958d8 126 template<typename _Tp>
7cf8aefc
PC
127 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
128 double>::__type
cdc958d8 129 asin(_Tp __x)
c85dfef7 130 { return __builtin_asin(__x); }
cdc958d8 131
d52e4867
RS
132 using ::atan;
133
7dd8177f 134 inline float
c85dfef7
RS
135 atan(float __x)
136 { return __builtin_atanf(__x); }
22aef514 137
7dd8177f 138 inline long double
c85dfef7
RS
139 atan(long double __x)
140 { return __builtin_atanl(__x); }
4e588ec9 141
cdc958d8 142 template<typename _Tp>
7cf8aefc
PC
143 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
144 double>::__type
cdc958d8 145 atan(_Tp __x)
c85dfef7 146 { return __builtin_atan(__x); }
7dd8177f 147
d52e4867
RS
148 using ::atan2;
149
7dd8177f 150 inline float
98e6e789 151 atan2(float __y, float __x)
c85dfef7 152 { return __builtin_atan2f(__y, __x); }
22aef514 153
7dd8177f 154 inline long double
c85dfef7
RS
155 atan2(long double __y, long double __x)
156 { return __builtin_atan2l(__y, __x); }
4e588ec9 157
cdc958d8 158 template<typename _Tp, typename _Up>
105c6331
BK
159 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
160 && __is_integer<_Up>::__value,
161 double>::__type
c85dfef7
RS
162 atan2(_Tp __y, _Up __x)
163 { return __builtin_atan2(__y, __x); }
cdc958d8 164
d52e4867
RS
165 using ::ceil;
166
7dd8177f 167 inline float
c85dfef7
RS
168 ceil(float __x)
169 { return __builtin_ceilf(__x); }
22aef514 170
7dd8177f 171 inline long double
c85dfef7
RS
172 ceil(long double __x)
173 { return __builtin_ceill(__x); }
22aef514 174
cdc958d8 175 template<typename _Tp>
105c6331
BK
176 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
177 double>::__type
cdc958d8 178 ceil(_Tp __x)
c85dfef7 179 { return __builtin_ceil(__x); }
7dd8177f 180
d52e4867
RS
181 using ::cos;
182
4e588ec9
GDR
183 inline float
184 cos(float __x)
185 { return __builtin_cosf(__x); }
186
4e588ec9
GDR
187 inline long double
188 cos(long double __x)
189 { return __builtin_cosl(__x); }
190
cdc958d8 191 template<typename _Tp>
105c6331
BK
192 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
193 double>::__type
cdc958d8
GDR
194 cos(_Tp __x)
195 { return __builtin_cos(__x); }
196
d52e4867
RS
197 using ::cosh;
198
7dd8177f 199 inline float
c85dfef7
RS
200 cosh(float __x)
201 { return __builtin_coshf(__x); }
22aef514 202
7dd8177f 203 inline long double
c85dfef7
RS
204 cosh(long double __x)
205 { return __builtin_coshl(__x); }
4e588ec9 206
cdc958d8 207 template<typename _Tp>
105c6331
BK
208 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
209 double>::__type
cdc958d8 210 cosh(_Tp __x)
c85dfef7 211 { return __builtin_cosh(__x); }
cdc958d8 212
d52e4867
RS
213 using ::exp;
214
7dd8177f 215 inline float
c85dfef7
RS
216 exp(float __x)
217 { return __builtin_expf(__x); }
22aef514 218
7dd8177f 219 inline long double
c85dfef7
RS
220 exp(long double __x)
221 { return __builtin_expl(__x); }
22aef514 222
cdc958d8 223 template<typename _Tp>
105c6331
BK
224 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
225 double>::__type
cdc958d8 226 exp(_Tp __x)
c85dfef7 227 { return __builtin_exp(__x); }
7dd8177f 228
d52e4867
RS
229 using ::fabs;
230
4e588ec9
GDR
231 inline float
232 fabs(float __x)
233 { return __builtin_fabsf(__x); }
234
4e588ec9
GDR
235 inline long double
236 fabs(long double __x)
237 { return __builtin_fabsl(__x); }
238
cdc958d8 239 template<typename _Tp>
105c6331
BK
240 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
241 double>::__type
cdc958d8
GDR
242 fabs(_Tp __x)
243 { return __builtin_fabs(__x); }
244
d52e4867
RS
245 using ::floor;
246
7dd8177f 247 inline float
c85dfef7
RS
248 floor(float __x)
249 { return __builtin_floorf(__x); }
22aef514 250
7dd8177f 251 inline long double
c85dfef7
RS
252 floor(long double __x)
253 { return __builtin_floorl(__x); }
4e588ec9 254
cdc958d8 255 template<typename _Tp>
105c6331
BK
256 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
257 double>::__type
cdc958d8 258 floor(_Tp __x)
c85dfef7 259 { return __builtin_floor(__x); }
7dd8177f 260
d52e4867
RS
261 using ::fmod;
262
7dd8177f 263 inline float
98e6e789 264 fmod(float __x, float __y)
c85dfef7 265 { return __builtin_fmodf(__x, __y); }
22aef514 266
7dd8177f 267 inline long double
c85dfef7
RS
268 fmod(long double __x, long double __y)
269 { return __builtin_fmodl(__x, __y); }
4e588ec9 270
d52e4867
RS
271 using ::frexp;
272
7dd8177f 273 inline float
c85dfef7
RS
274 frexp(float __x, int* __exp)
275 { return __builtin_frexpf(__x, __exp); }
22aef514 276
7dd8177f 277 inline long double
c85dfef7
RS
278 frexp(long double __x, int* __exp)
279 { return __builtin_frexpl(__x, __exp); }
4e588ec9 280
cdc958d8 281 template<typename _Tp>
105c6331
BK
282 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
283 double>::__type
cdc958d8 284 frexp(_Tp __x, int* __exp)
c85dfef7 285 { return __builtin_frexp(__x, __exp); }
7dd8177f 286
d52e4867
RS
287 using ::ldexp;
288
7dd8177f 289 inline float
98e6e789 290 ldexp(float __x, int __exp)
c85dfef7 291 { return __builtin_ldexpf(__x, __exp); }
22aef514 292
7dd8177f 293 inline long double
c85dfef7
RS
294 ldexp(long double __x, int __exp)
295 { return __builtin_ldexpl(__x, __exp); }
4e588ec9 296
cdc958d8 297 template<typename _Tp>
105c6331
BK
298 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
299 double>::__type
7cf8aefc
PC
300 ldexp(_Tp __x, int __exp)
301 { return __builtin_ldexp(__x, __exp); }
cdc958d8 302
d52e4867
RS
303 using ::log;
304
7dd8177f 305 inline float
c85dfef7
RS
306 log(float __x)
307 { return __builtin_logf(__x); }
22aef514 308
7dd8177f 309 inline long double
c85dfef7
RS
310 log(long double __x)
311 { return __builtin_logl(__x); }
4e588ec9 312
cdc958d8 313 template<typename _Tp>
105c6331
BK
314 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
315 double>::__type
cdc958d8 316 log(_Tp __x)
c85dfef7 317 { return __builtin_log(__x); }
7dd8177f 318
d52e4867
RS
319 using ::log10;
320
7dd8177f 321 inline float
c85dfef7
RS
322 log10(float __x)
323 { return __builtin_log10f(__x); }
22aef514 324
7dd8177f 325 inline long double
c85dfef7
RS
326 log10(long double __x)
327 { return __builtin_log10l(__x); }
4e588ec9 328
cdc958d8 329 template<typename _Tp>
105c6331
BK
330 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
331 double>::__type
cdc958d8 332 log10(_Tp __x)
c85dfef7 333 { return __builtin_log10(__x); }
7dd8177f 334
d52e4867
RS
335 using ::modf;
336
7dd8177f 337 inline float
98e6e789 338 modf(float __x, float* __iptr)
c85dfef7
RS
339 { return __builtin_modff(__x, __iptr); }
340
7dd8177f 341 inline long double
c85dfef7
RS
342 modf(long double __x, long double* __iptr)
343 { return __builtin_modfl(__x, __iptr); }
4e588ec9 344
d52e4867
RS
345 using ::pow;
346
7dd8177f 347 inline float
98e6e789 348 pow(float __x, float __y)
c85dfef7 349 { return __builtin_powf(__x, __y); }
22aef514 350
7dd8177f 351 inline long double
c85dfef7
RS
352 pow(long double __x, long double __y)
353 { return __builtin_powl(__x, __y); }
22aef514 354
7dd8177f 355 inline double
98e6e789 356 pow(double __x, int __i)
ae63a1cc 357 { return __builtin_powi(__x, __i); }
22aef514 358
7dd8177f 359 inline float
d52e4867 360 pow(float __x, int __n)
ae63a1cc 361 { return __builtin_powif(__x, __n); }
d52e4867 362
7dd8177f 363 inline long double
4e588ec9 364 pow(long double __x, int __n)
ae63a1cc 365 { return __builtin_powil(__x, __n); }
22aef514 366
d52e4867
RS
367 using ::sin;
368
4e588ec9
GDR
369 inline float
370 sin(float __x)
371 { return __builtin_sinf(__x); }
22aef514 372
4e588ec9
GDR
373 inline long double
374 sin(long double __x)
375 { return __builtin_sinl(__x); }
22aef514 376
cdc958d8 377 template<typename _Tp>
105c6331
BK
378 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
379 double>::__type
cdc958d8
GDR
380 sin(_Tp __x)
381 { return __builtin_sin(__x); }
382
d52e4867
RS
383 using ::sinh;
384
7dd8177f 385 inline float
c85dfef7
RS
386 sinh(float __x)
387 { return __builtin_sinhf(__x); }
22aef514 388
7dd8177f 389 inline long double
c85dfef7
RS
390 sinh(long double __x)
391 { return __builtin_sinhl(__x); }
22aef514 392
cdc958d8 393 template<typename _Tp>
105c6331
BK
394 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
395 double>::__type
cdc958d8 396 sinh(_Tp __x)
c85dfef7 397 { return __builtin_sinh(__x); }
7dd8177f 398
d52e4867
RS
399 using ::sqrt;
400
4e588ec9
GDR
401 inline float
402 sqrt(float __x)
403 { return __builtin_sqrtf(__x); }
22aef514 404
4e588ec9
GDR
405 inline long double
406 sqrt(long double __x)
407 { return __builtin_sqrtl(__x); }
22aef514 408
cdc958d8 409 template<typename _Tp>
105c6331
BK
410 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
411 double>::__type
cdc958d8
GDR
412 sqrt(_Tp __x)
413 { return __builtin_sqrt(__x); }
7dd8177f 414
d52e4867
RS
415 using ::tan;
416
7dd8177f 417 inline float
c85dfef7
RS
418 tan(float __x)
419 { return __builtin_tanf(__x); }
22aef514 420
7dd8177f 421 inline long double
c85dfef7
RS
422 tan(long double __x)
423 { return __builtin_tanl(__x); }
22aef514 424
cdc958d8 425 template<typename _Tp>
105c6331
BK
426 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
427 double>::__type
cdc958d8 428 tan(_Tp __x)
c85dfef7 429 { return __builtin_tan(__x); }
7dd8177f 430
d52e4867
RS
431 using ::tanh;
432
7dd8177f 433 inline float
c85dfef7
RS
434 tanh(float __x)
435 { return __builtin_tanhf(__x); }
22aef514 436
7dd8177f 437 inline long double
c85dfef7
RS
438 tanh(long double __x)
439 { return __builtin_tanhl(__x); }
cdc958d8
GDR
440
441 template<typename _Tp>
105c6331
BK
442 inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
443 double>::__type
cdc958d8 444 tanh(_Tp __x)
c85dfef7 445 { return __builtin_tanh(__x); }
3cbc7af0 446
12ffa228
BK
447_GLIBCXX_END_NAMESPACE_VERSION
448} // namespace
22aef514 449
517da0ce 450#if _GLIBCXX_USE_C99_MATH
3d7c150e 451#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
3cbc7af0 452
57317d2a 453// These are possible macros imported from C99-land.
7cda84dc
BK
454#undef fpclassify
455#undef isfinite
456#undef isinf
457#undef isnan
458#undef isnormal
459#undef signbit
460#undef isgreater
461#undef isgreaterequal
462#undef isless
463#undef islessequal
464#undef islessgreater
465#undef isunordered
466
12ffa228
BK
467namespace std _GLIBCXX_VISIBILITY(default)
468{
469_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 470
7cda84dc 471 template<typename _Tp>
0e7edcd5
PC
472 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
473 int>::__type
474 fpclassify(_Tp __f)
475 {
476 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
ebd15f80
PC
477 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,
478 FP_SUBNORMAL, FP_ZERO, __type(__f));
0e7edcd5 479 }
7cda84dc
BK
480
481 template<typename _Tp>
0e7edcd5
PC
482 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
483 int>::__type
484 isfinite(_Tp __f)
485 {
486 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
487 return __builtin_isfinite(__type(__f));
488 }
7cda84dc
BK
489
490 template<typename _Tp>
0e7edcd5
PC
491 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
492 int>::__type
493 isinf(_Tp __f)
494 {
495 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
496 return __builtin_isinf(__type(__f));
497 }
7cda84dc
BK
498
499 template<typename _Tp>
0e7edcd5
PC
500 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
501 int>::__type
502 isnan(_Tp __f)
503 {
504 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
505 return __builtin_isnan(__type(__f));
506 }
7cda84dc
BK
507
508 template<typename _Tp>
0e7edcd5
PC
509 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
510 int>::__type
511 isnormal(_Tp __f)
512 {
513 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
514 return __builtin_isnormal(__type(__f));
515 }
7cda84dc
BK
516
517 template<typename _Tp>
0e7edcd5
PC
518 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
519 int>::__type
520 signbit(_Tp __f)
521 {
522 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
523 return __builtin_signbit(__type(__f));
524 }
7cda84dc
BK
525
526 template<typename _Tp>
0e7edcd5
PC
527 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
528 int>::__type
3a2794ab 529 isgreater(_Tp __f1, _Tp __f2)
0e7edcd5
PC
530 {
531 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
532 return __builtin_isgreater(__type(__f1), __type(__f2));
533 }
7cda84dc
BK
534
535 template<typename _Tp>
0e7edcd5
PC
536 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
537 int>::__type
7dd8177f 538 isgreaterequal(_Tp __f1, _Tp __f2)
0e7edcd5
PC
539 {
540 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
541 return __builtin_isgreaterequal(__type(__f1), __type(__f2));
542 }
7cda84dc
BK
543
544 template<typename _Tp>
0e7edcd5
PC
545 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
546 int>::__type
3a2794ab 547 isless(_Tp __f1, _Tp __f2)
0e7edcd5
PC
548 {
549 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
550 return __builtin_isless(__type(__f1), __type(__f2));
551 }
7cda84dc
BK
552
553 template<typename _Tp>
0e7edcd5
PC
554 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
555 int>::__type
7dd8177f 556 islessequal(_Tp __f1, _Tp __f2)
0e7edcd5
PC
557 {
558 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
559 return __builtin_islessequal(__type(__f1), __type(__f2));
560 }
7cda84dc
BK
561
562 template<typename _Tp>
0e7edcd5
PC
563 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
564 int>::__type
7dd8177f 565 islessgreater(_Tp __f1, _Tp __f2)
0e7edcd5
PC
566 {
567 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
568 return __builtin_islessgreater(__type(__f1), __type(__f2));
569 }
7cda84dc
BK
570
571 template<typename _Tp>
0e7edcd5
PC
572 inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
573 int>::__type
7dd8177f 574 isunordered(_Tp __f1, _Tp __f2)
0e7edcd5
PC
575 {
576 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
577 return __builtin_isunordered(__type(__f1), __type(__f2));
578 }
3cbc7af0 579
12ffa228
BK
580_GLIBCXX_END_NAMESPACE_VERSION
581} // namespace std
3cbc7af0 582
3d7c150e 583#endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */
7cda84dc 584#endif
7dd8177f 585
98e6e789 586#endif