]>
Commit | Line | Data |
---|---|---|
40e5dd58 BK |
1 | // -*- C++ -*- C math library. |
2 | ||
3 | // Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. | |
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 | ||
34 | // Note: this is not a conforming implementation. | |
35 | ||
36 | #ifndef _CPP_CMATH | |
37 | #define _CPP_CMATH 1 | |
38 | # pragma GCC system_header | |
39 | # include_next <math.h> | |
40 | # include_next <stdlib.h> | |
41 | ||
42 | # include <bits/c++config.h> | |
43 | ||
44 | namespace std { | |
45 | ||
46 | // | |
47 | // int | |
48 | // | |
49 | ||
50 | inline int abs(int i) | |
51 | { return i > 0 ? i : -i; } | |
52 | ||
53 | inline long abs(long i) | |
54 | { return i > 0 ? i : -i; } | |
55 | ||
56 | // | |
57 | // float | |
58 | // | |
59 | ||
60 | #if _GLIBCPP_HAVE___BUILTIN_FABSF | |
61 | inline float abs(float __x) | |
62 | { return __builtin_fabsf(__x); } | |
63 | #elif _GLIBCPP_HAVE_FABSF | |
64 | inline float abs(float __x) | |
65 | { return ::fabsf(__x); } | |
66 | #else | |
67 | inline float abs(float __x) | |
68 | { return ::fabs(static_cast<double>(__x)); } | |
69 | #endif | |
70 | ||
71 | #if _GLIBCPP_HAVE_ACOSF | |
72 | inline float acos(float __x) | |
73 | { return ::acosf(__x); } | |
74 | #else | |
75 | inline float acos(float __x) | |
76 | { return ::acos(static_cast<double>(__x)); } | |
77 | #endif | |
78 | ||
79 | #if _GLIBCPP_HAVE_ASINF | |
80 | inline float asin(float __x) | |
81 | { return ::asinf(__x); } | |
82 | #else | |
83 | inline float asin(float __x) | |
84 | { return ::asin(static_cast<double>(__x)); } | |
85 | #endif | |
86 | ||
87 | #if _GLIBCPP_HAVE_ATANF | |
88 | inline float atan(float __x) | |
89 | { return ::atanf(__x); } | |
90 | #else | |
91 | inline float atan(float __x) | |
92 | { return ::atan(static_cast<double>(__x)); } | |
93 | #endif | |
94 | ||
95 | #if _GLIBCPP_HAVE_ATAN2F | |
96 | inline float atan2(float __y, float __x) | |
97 | { return ::atan2f(__y, __x); } | |
98 | #else | |
99 | inline float atan2(float __y, float __x) | |
100 | { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); } | |
101 | #endif | |
102 | ||
103 | #if _GLIBCPP_HAVE_CEILF | |
104 | inline float ceil(float __x) | |
105 | { return ::ceilf(__x); } | |
106 | #else | |
107 | inline float ceil(float __x) | |
108 | { return ::ceil(static_cast<double>(__x)); } | |
109 | #endif | |
110 | ||
111 | #if _GLIBCPP_HAVE___BUILTIN_COSF | |
112 | inline float cos(float __x) | |
113 | { return __builtin_cosf(__x); } | |
114 | #elif _GLIBCPP_HAVE_COSF | |
115 | inline float cos(float __x) | |
116 | { return ::cosf(__x); } | |
117 | #else | |
118 | inline float cos(float __x) | |
119 | { return ::cos(static_cast<double>(__x)); } | |
120 | #endif | |
121 | ||
122 | #if _GLIBCPP_HAVE_COSHF | |
123 | inline float cosh(float __x) | |
124 | { return ::coshf(__x); } | |
125 | #else | |
126 | inline float cosh(float __x) | |
127 | { return ::cosh(static_cast<double>(__x)); } | |
128 | #endif | |
129 | ||
130 | #if _GLIBCPP_HAVE_EXPF | |
131 | inline float exp(float __x) | |
132 | { return ::expf(__x); } | |
133 | #else | |
134 | inline float exp(float __x) | |
135 | { return ::exp(static_cast<double>(__x)); } | |
136 | #endif | |
137 | ||
138 | #if _GLIBCPP_HAVE___BUILTIN_FABSF | |
139 | inline float fabs(float __x) | |
140 | { return __builtin_fabsf(__x); } | |
141 | #elif _GLIBCPP_HAVE_FABSF | |
142 | inline float fabs(float __x) | |
143 | { return ::fabsf(__x); } | |
144 | #else | |
145 | inline float fabs(float __x) | |
146 | { return ::fabs(static_cast<double>(__x)); } | |
147 | #endif | |
148 | ||
149 | #if _GLIBCPP_HAVE_FLOORF | |
150 | inline float floor(float __x) | |
151 | { return ::floorf(__x); } | |
152 | #else | |
153 | inline float floor(float __x) | |
154 | { return ::floor(static_cast<double>(__x)); } | |
155 | #endif | |
156 | ||
157 | #if _GLIBCPP_HAVE_FMODF | |
158 | inline float fmod(float __x, float __y) | |
159 | { return ::fmodf(__x, __y); } | |
160 | #else | |
161 | inline float fmod(float __x, float __y) | |
162 | { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); } | |
163 | #endif | |
164 | ||
165 | #if _GLIBCPP_HAVE_FREXPF | |
166 | inline float frexp(float __x, int* __exp) | |
167 | { return ::frexpf(__x, __exp); } | |
168 | #else | |
169 | inline float frexp(float __x, int* __exp) | |
170 | { return ::frexp(__x, __exp); } | |
171 | #endif | |
172 | ||
173 | #if _GLIBCPP_HAVE_LDEXPF | |
174 | inline float ldexp(float __x, int __exp) | |
175 | { return ::ldexpf(__x, __exp); } | |
176 | #else | |
177 | inline float ldexp(float __x, int __exp) | |
178 | { return ::ldexp(static_cast<double>(__x), __exp); } | |
179 | #endif | |
180 | ||
181 | #if _GLIBCPP_HAVE_LOGF | |
182 | inline float log(float __x) | |
183 | { return ::logf(__x); } | |
184 | #else | |
185 | inline float log(float __x) | |
186 | { return ::log(static_cast<double>(__x)); } | |
187 | #endif | |
188 | ||
189 | #if _GLIBCPP_HAVE_LOG10F | |
190 | inline float log10(float __x) | |
191 | { return ::log10f(__x); } | |
192 | #else | |
193 | inline float log10(float __x) | |
194 | { return ::log10(static_cast<double>(__x)); } | |
195 | #endif | |
196 | ||
197 | #if _GLIBCPP_HAVE_MODFF | |
198 | inline float modf(float __x, float* __iptr) | |
199 | { return ::modff(__x, __iptr); } | |
200 | #else | |
201 | inline float modf(float __x, float* __iptr) | |
202 | { | |
203 | double __tmp; | |
204 | double __res = ::modf(static_cast<double>(__x), &__tmp); | |
205 | *__iptr = static_cast<float> (__tmp); | |
206 | return __res; | |
207 | } | |
208 | #endif | |
209 | ||
210 | #if _GLIBCPP_HAVE_POWF | |
211 | inline float pow(float __x, float __y) | |
212 | { return ::powf(__x, __y); } | |
213 | #else | |
214 | inline float pow(float __x, float __y) | |
215 | { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); } | |
216 | #endif | |
217 | ||
218 | float pow(float, int); | |
219 | ||
220 | #if _GLIBCPP_HAVE___BUILTIN_SINF | |
221 | inline float sin(float __x) | |
222 | { return __builtin_sinf(__x); } | |
223 | #elif _GLIBCPP_HAVE_SINF | |
224 | inline float sin(float __x) | |
225 | { return ::sinf(__x); } | |
226 | #else | |
227 | inline float sin(float __x) | |
228 | { return ::sin(static_cast<double>(__x)); } | |
229 | #endif | |
230 | ||
231 | #if _GLIBCPP_HAVE_SINHF | |
232 | inline float sinh(float __x) | |
233 | { return ::sinhf(__x); } | |
234 | #else | |
235 | inline float sinh(float __x) | |
236 | { return ::sinh(static_cast<double>(__x)); } | |
237 | #endif | |
238 | ||
239 | #if _GLIBCPP_HAVE___BUILTIN_SQRTF | |
240 | inline float sqrt(float __x) | |
241 | { return __builtin_sqrtf(__x); } | |
242 | #elif _GLIBCPP_HAVE_SQRTF | |
243 | inline float sqrt(float __x) | |
244 | { return ::sqrtf(__x); } | |
245 | #else | |
246 | inline float sqrt(float __x) | |
247 | { return ::sqrt(static_cast<double>(__x)); } | |
248 | #endif | |
249 | ||
250 | #if _GLIBCPP_HAVE_TANF | |
251 | inline float tan(float __x) | |
252 | { return ::tanf(__x); } | |
253 | #else | |
254 | inline float tan(float __x) | |
255 | { return ::tan(static_cast<double>(__x)); } | |
256 | #endif | |
257 | ||
258 | #if _GLIBCPP_HAVE_TANHF | |
259 | inline float tanh(float __x) | |
260 | { return ::tanhf(__x); } | |
261 | #else | |
262 | inline float tanh(float __x) | |
263 | { return ::tanh(static_cast<double>(__x)); } | |
264 | #endif | |
265 | ||
266 | // | |
267 | // double | |
268 | // | |
269 | ||
270 | #if _GLIBCPP_HAVE___BUILTIN_FABS | |
271 | inline double abs(double __x) | |
272 | { return __builtin_fabs(__x); } | |
273 | #else | |
274 | inline double abs(double __x) | |
275 | { return ::fabs(__x); } | |
276 | #endif | |
277 | ||
278 | inline double acos(double __x) | |
279 | { return ::acos(__x); } | |
280 | ||
281 | inline double asin(double __x) | |
282 | { return ::asin(__x); } | |
283 | ||
284 | inline double atan(double __x) | |
285 | { return ::atan(__x); } | |
286 | ||
287 | inline double atan2(double __y, double __x) | |
288 | { return ::atan2(__y, __x); } | |
289 | ||
290 | inline double ceil(double __x) | |
291 | { return ::ceil(__x); } | |
292 | ||
293 | #if _GLIBCPP_HAVE___BUILTIN_COS | |
294 | inline double cos(double __x) | |
295 | { return __builtin_cos(__x); } | |
296 | #else | |
297 | inline double cos(double __x) | |
298 | { return ::cos(__x); } | |
299 | #endif | |
300 | ||
301 | inline double cosh(double __x) | |
302 | { return ::cosh(__x); } | |
303 | ||
304 | inline double exp(double __x) | |
305 | { return ::exp(__x); } | |
306 | ||
307 | ||
308 | #if _GLIBCPP_HAVE___BUILTIN_FABS | |
309 | inline double fabs(double __x) | |
310 | { return __builtin_fabs(__x); } | |
311 | #else | |
312 | inline double fabs(double __x) | |
313 | { return ::fabs(__x); } | |
314 | #endif | |
315 | ||
316 | inline double floor(double __x) | |
317 | { return ::floor(__x); } | |
318 | ||
319 | inline double fmod(double __x, double __y) | |
320 | { return ::fmod(__x, __y); } | |
321 | ||
322 | inline double frexp(double __x, int* __exp) | |
323 | { return ::frexp(__x, __exp); } | |
324 | ||
325 | inline double ldexp(double __x, int __exp) | |
326 | { return ::ldexp(__x, __exp); } | |
327 | ||
328 | inline double log(double __x) | |
329 | { return ::log(__x); } | |
330 | ||
331 | inline double log10(double __x) | |
332 | { return ::log10(__x); } | |
333 | ||
334 | inline double modf(double __x, double* __iptr) | |
335 | { return ::modf(__x, __iptr); } | |
336 | ||
337 | inline double pow(double __x, double __y) | |
338 | { return ::pow(__x, __y); } | |
339 | ||
340 | double pow (double, int); | |
341 | ||
342 | #if _GLIBCPP_HAVE___BUILTIN_SIN | |
343 | inline double sin(double __x) | |
344 | { return __builtin_sin(__x); } | |
345 | #else | |
346 | inline double sin(double __x) | |
347 | { return ::sin(__x); } | |
348 | #endif | |
349 | ||
350 | inline double sinh(double __x) | |
351 | { return ::sinh(__x); } | |
352 | ||
353 | #if _GLIBCPP_HAVE___BUILTIN_SQRT | |
354 | inline double sqrt(double __x) | |
355 | { return __builtin_fsqrt(__x); } | |
356 | #else | |
357 | inline double sqrt(double __x) | |
358 | { return ::sqrt(__x); } | |
359 | #endif | |
360 | ||
361 | inline double tan(double __x) | |
362 | { return ::tan(__x); } | |
363 | ||
364 | inline double tanh(double __x) | |
365 | { return ::tanh(__x); } | |
366 | ||
367 | // | |
368 | // long double | |
369 | // | |
370 | #if _GLIBCPP_HAVE___BUILTIN_FABSL | |
371 | inline long double abs(long double __x) | |
372 | { return __builtin_fabsl(__x); } | |
373 | #elif _GLIBCPP_HAVE_FABSL | |
374 | inline long double abs(long double __x) | |
375 | { return ::fabsl(__x); } | |
376 | #endif | |
377 | ||
378 | #if _GLIBCPP_HAVE_ACOSL | |
379 | inline long double acos(long double __x) | |
380 | { return ::acosl(__x); } | |
381 | #endif | |
382 | ||
383 | #if _GLIBCPP_HAVE_ASINL | |
384 | inline long double asin(long double __x) | |
385 | { return ::asinl(__x); } | |
386 | #endif | |
387 | ||
388 | #if _GLIBCPP_HAVE_ATANL | |
389 | inline long double atan(long double __x) | |
390 | { return ::atanl(__x); } | |
391 | #endif | |
392 | ||
393 | #if _GLIBCPP_HAVE_ATAN2L | |
394 | inline long double atan2(long double __y, long double __x) | |
395 | { return ::atan2l(__y, __x); } | |
396 | #endif | |
397 | ||
398 | #if _GLIBCPP_HAVE_CEILL | |
399 | inline long double ceil(long double __x) | |
400 | { return ::ceill(__x); } | |
401 | #endif | |
402 | ||
403 | #if _GLIBCPP_HAVE___BUILTIN_COSL | |
404 | inline long double cos(long double __x) | |
405 | { return __builtin_cosl(__x); } | |
406 | #elif _GLIBCPP_HAVE_COSL | |
407 | inline long double cos(long double __x) | |
408 | { return ::cosl(__x); } | |
409 | #endif | |
410 | ||
411 | #if _GLIBCPP_HAVE_COSHL | |
412 | inline long double cosh(long double __x) | |
413 | { return ::coshl(__x); } | |
414 | #endif | |
415 | ||
416 | #if _GLIBCPP_HAVE_EXPL | |
417 | inline long double exp(long double __x) | |
418 | { return ::expl(__x); } | |
419 | #endif | |
420 | ||
421 | #if _GLIBCPP_HAVE___BUILTIN_FABSL | |
422 | inline long double fabs(long double __x) | |
423 | { return __builtin_fabsl(__x); } | |
424 | #elif _GLIBCPP_HAVE_FABSL | |
425 | inline long double fabs(long double __x) | |
426 | { return ::fabsl(__x); } | |
427 | #endif | |
428 | ||
429 | #if _GLIBCPP_HAVE_FLOORL | |
430 | inline long double floor(long double __x) | |
431 | { return ::floorl(__x); } | |
432 | #endif | |
433 | ||
434 | #if _GLIBCPP_HAVE_FMODL | |
435 | inline long double fmod(long double __x, long double __y) | |
436 | { return ::fmodl(__x, __y); } | |
437 | #endif | |
438 | ||
439 | #if _GLIBCPP_HAVE_FREXPL | |
440 | inline long double frexp(long double __x, int* __exp) | |
441 | { return ::frexpl(__x, __exp); } | |
442 | #endif | |
443 | ||
444 | #if _GLIBCPP_HAVE_LDEXPL | |
445 | inline long double ldexp(long double __x, int __exp) | |
446 | { return ::ldexpl(__x, __exp); } | |
447 | #endif | |
448 | ||
449 | #if _GLIBCPP_HAVE_LOGL | |
450 | inline long double log(long double __x) | |
451 | { return ::logl(__x); } | |
452 | #endif | |
453 | ||
454 | #if _GLIBCPP_HAVE_LOG10L | |
455 | inline long double log10(long double __x) | |
456 | { return ::log10l(__x); } | |
457 | #endif | |
458 | ||
459 | #if _GLIBCPP_HAVE_MODFL | |
460 | inline long double modf(long double __x, long double* __iptr) | |
461 | { return ::modfl(__x, __iptr); } | |
462 | #endif | |
463 | ||
464 | #if _GLIBCPP_HAVE_POWL | |
465 | inline long double pow(long double __x, long double __y) | |
466 | { return ::powl(__x, __y); } | |
467 | #endif | |
468 | ||
469 | long double pow(long double, int); | |
470 | ||
471 | #if _GLIBCPP_HAVE___BUILTIN_SINL | |
472 | inline long double sin(long double __x) | |
473 | { return __builtin_sinl(__x); } | |
474 | #elif _GLIBCPP_HAVE_SINL | |
475 | inline long double sin(long double __x) | |
476 | { return ::sinl(__x); } | |
477 | #endif | |
478 | ||
479 | #if _GLIBCPP_HAVE_SINHL | |
480 | inline long double sinh(long double __x) | |
481 | { return ::sinhl(__x); } | |
482 | #endif | |
483 | ||
484 | #if _GLIBCPP_HAVE___BUILTIN_SQRTL | |
485 | inline long double sqrt(long double __x) | |
486 | { return __builtin_sqrtl(__x); } | |
487 | #elif _GLIBCPP_HAVE_SQRTL | |
488 | inline long double sqrt(long double __x) | |
489 | { return ::sqrtl(__x); } | |
490 | #endif | |
491 | ||
492 | #if _GLIBCPP_HAVE_TANL | |
493 | inline long double tan(long double __x) | |
494 | { return ::tanl(__x); } | |
495 | #endif | |
496 | ||
497 | #if _GLIBCPP_HAVE_TANHL | |
498 | inline long double tanh(long double __x) | |
499 | { return ::tanhl(__x); } | |
500 | #endif | |
501 | ||
502 | } // std | |
503 | ||
504 | #endif // _CPP_CMATH | |
505 | ||
506 |