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