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