OSDN Git Service

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