williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1999
|
williamr@2
|
5 |
* Boris Fomitchev
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
8 |
* or implied. Any use is at your own risk.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
11 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
12 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
13 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
14 |
* modified is included with the above copyright notice.
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@2
|
18 |
#ifndef _STLP_CMATH_H_HEADER
|
williamr@2
|
19 |
# define _STLP_CMATH_H_HEADER
|
williamr@2
|
20 |
|
williamr@2
|
21 |
# include <cmath>
|
williamr@2
|
22 |
|
williamr@2
|
23 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
24 |
|
williamr@2
|
25 |
# if defined (_STLP_SAME_FUNCTION_NAME_RESOLUTION_BUG) && (! defined (_STLP_VXWORKS_TORNADO))
|
williamr@2
|
26 |
|
williamr@2
|
27 |
// this proxy is needed for some compilers to resolve problems
|
williamr@2
|
28 |
// calling sqrt() from within sqrt(), etc.
|
williamr@2
|
29 |
template <class _Tp>
|
williamr@2
|
30 |
struct _STL_math_proxy {
|
williamr@2
|
31 |
static inline _Tp _do_abs(const _Tp& __x) { return _STLP_VENDOR_CSTD::fabs(__x); }
|
williamr@2
|
32 |
static inline _Tp _do_acos(const _Tp& __x) { return _STLP_VENDOR_CSTD::acos(__x); }
|
williamr@2
|
33 |
static inline _Tp _do_asin(const _Tp& __x) { return _STLP_VENDOR_CSTD::asin(__x); }
|
williamr@2
|
34 |
static inline _Tp _do_atan(const _Tp& __x) { return _STLP_VENDOR_CSTD::atan(__x); }
|
williamr@2
|
35 |
static inline _Tp _do_atan2(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::atan2(__x, __y); }
|
williamr@2
|
36 |
static inline _Tp _do_cos(const _Tp& __x) { return _STLP_VENDOR_CSTD::cos(__x); }
|
williamr@2
|
37 |
static inline _Tp _do_cosh(const _Tp& __x) { return _STLP_VENDOR_CSTD::cosh(__x); }
|
williamr@2
|
38 |
static inline _Tp _do_floor(const _Tp& __x) { return _STLP_VENDOR_CSTD::floor(__x); }
|
williamr@2
|
39 |
static inline _Tp _do_ceil(const _Tp& __x) { return _STLP_VENDOR_CSTD::ceil(__x); }
|
williamr@2
|
40 |
static inline _Tp _do_fmod(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::fmod(__x, __y); }
|
williamr@2
|
41 |
static inline _Tp _do_frexp(const _Tp& __x, int* __y) { return _STLP_VENDOR_CSTD::frexp(__x, __y); }
|
williamr@2
|
42 |
static inline _Tp _do_ldexp(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::ldexp(__x, __y); }
|
williamr@2
|
43 |
static inline _Tp _do_modf(const _Tp& __x, double* __y) { return _STLP_VENDOR_CSTD::modf(__x, __y); }
|
williamr@2
|
44 |
static inline _Tp _do_log(const _Tp& __x) { return _STLP_VENDOR_CSTD::log(__x); }
|
williamr@2
|
45 |
static inline _Tp _do_log10(const _Tp& __x) { return _STLP_VENDOR_CSTD::log10(__x); }
|
williamr@2
|
46 |
static inline _Tp _do_pow(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); }
|
williamr@2
|
47 |
static inline _Tp _do_pow(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); }
|
williamr@2
|
48 |
static inline _Tp _do_sin(const _Tp& __x) { return _STLP_VENDOR_CSTD::sin(__x); }
|
williamr@2
|
49 |
static inline _Tp _do_sinh(const _Tp& __x) { return _STLP_VENDOR_CSTD::sinh(__x); }
|
williamr@2
|
50 |
|
williamr@2
|
51 |
static inline _Tp _do_sqrt(const _Tp& __x) { return _STLP_VENDOR_CSTD::sqrt(__x); }
|
williamr@2
|
52 |
static inline _Tp _do_tan(const _Tp& __x) { return _STLP_VENDOR_CSTD::tan(__x); }
|
williamr@2
|
53 |
static inline _Tp _do_tanh(const _Tp& __x) { return _STLP_VENDOR_CSTD::tanh(__x); }
|
williamr@2
|
54 |
static inline _Tp _do_exp(const _Tp& __x) { return _STLP_VENDOR_CSTD::exp(__x); }
|
williamr@2
|
55 |
static inline _Tp _do_hypot(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::hypot(__x, __y); }
|
williamr@2
|
56 |
};
|
williamr@2
|
57 |
|
williamr@2
|
58 |
# define _STLP_DO_ABS(_Tp) _STL_math_proxy<_Tp>::_do_abs
|
williamr@2
|
59 |
# define _STLP_DO_ACOS(_Tp) _STL_math_proxy<_Tp>::_do_acos
|
williamr@2
|
60 |
# define _STLP_DO_ASIN(_Tp) _STL_math_proxy<_Tp>::_do_asin
|
williamr@2
|
61 |
# define _STLP_DO_ATAN(_Tp) _STL_math_proxy<_Tp>::_do_atan
|
williamr@2
|
62 |
# define _STLP_DO_ATAN2(_Tp) _STL_math_proxy<_Tp>::_do_atan2
|
williamr@2
|
63 |
# define _STLP_DO_COS(_Tp) _STL_math_proxy<_Tp>::_do_cos
|
williamr@2
|
64 |
# define _STLP_DO_COSH(_Tp) _STL_math_proxy<_Tp>::_do_cosh
|
williamr@2
|
65 |
# define _STLP_DO_FLOOR(_Tp) _STL_math_proxy<_Tp>::_do_floor
|
williamr@2
|
66 |
# define _STLP_DO_CEIL(_Tp) _STL_math_proxy<_Tp>::_do_ceil
|
williamr@2
|
67 |
# define _STLP_DO_FMOD(_Tp) _STL_math_proxy<_Tp>::_do_fmod
|
williamr@2
|
68 |
# define _STLP_DO_FREXP(_Tp) _STL_math_proxy<_Tp>::_do_frexp
|
williamr@2
|
69 |
# define _STLP_DO_LDEXP(_Tp) _STL_math_proxy<_Tp>::_do_ldexp
|
williamr@2
|
70 |
# define _STLP_DO_MODF(_Tp) _STL_math_proxy<_Tp>::_do_modf
|
williamr@2
|
71 |
# define _STLP_DO_LOG(_Tp) _STL_math_proxy<_Tp>::_do_log
|
williamr@2
|
72 |
# define _STLP_DO_LOG10(_Tp) _STL_math_proxy<_Tp>::_do_log10
|
williamr@2
|
73 |
# define _STLP_DO_POW(_Tp) _STL_math_proxy<_Tp>::_do_pow
|
williamr@2
|
74 |
# define _STLP_DO_SIN(_Tp) _STL_math_proxy<_Tp>::_do_sin
|
williamr@2
|
75 |
# define _STLP_DO_SINH(_Tp) _STL_math_proxy<_Tp>::_do_sinh
|
williamr@2
|
76 |
# define _STLP_DO_SQRT(_Tp) _STL_math_proxy<_Tp>::_do_sqrt
|
williamr@2
|
77 |
# define _STLP_DO_TAN(_Tp) _STL_math_proxy<_Tp>::_do_tan
|
williamr@2
|
78 |
# define _STLP_DO_TANH(_Tp) _STL_math_proxy<_Tp>::_do_tanh
|
williamr@2
|
79 |
# define _STLP_DO_EXP(_Tp) _STL_math_proxy<_Tp>::_do_exp
|
williamr@2
|
80 |
# define _STLP_DO_HYPOT(_Tp) _STL_math_proxy<_Tp>::_do_hypot
|
williamr@2
|
81 |
# else
|
williamr@2
|
82 |
# define _STLP_DO_ABS(_Tp) _STLP_VENDOR_CSTD::fabs
|
williamr@2
|
83 |
# define _STLP_DO_ACOS(_Tp) _STLP_VENDOR_CSTD::acos
|
williamr@2
|
84 |
# define _STLP_DO_ASIN(_Tp) _STLP_VENDOR_CSTD::asin
|
williamr@2
|
85 |
# define _STLP_DO_ATAN(_Tp) _STLP_VENDOR_CSTD::atan
|
williamr@2
|
86 |
# define _STLP_DO_ATAN2(_Tp) _STLP_VENDOR_CSTD::atan2
|
williamr@2
|
87 |
# define _STLP_DO_COS(_Tp) _STLP_VENDOR_CSTD::cos
|
williamr@2
|
88 |
# define _STLP_DO_COSH(_Tp) _STLP_VENDOR_CSTD::cosh
|
williamr@2
|
89 |
# define _STLP_DO_FLOOR(_Tp) _STLP_VENDOR_CSTD::floor
|
williamr@2
|
90 |
# define _STLP_DO_CEIL(_Tp) _STLP_VENDOR_CSTD::ceil
|
williamr@2
|
91 |
# define _STLP_DO_FMOD(_Tp) _STLP_VENDOR_CSTD::fmod
|
williamr@2
|
92 |
# define _STLP_DO_FREXP(_Tp) _STLP_VENDOR_CSTD::frexp
|
williamr@2
|
93 |
# define _STLP_DO_LDEXP(_Tp) _STLP_VENDOR_CSTD::ldexp
|
williamr@2
|
94 |
# define _STLP_DO_MODF(_Tp) _STLP_VENDOR_CSTD::modf
|
williamr@2
|
95 |
# define _STLP_DO_LOG(_Tp) _STLP_VENDOR_CSTD::log
|
williamr@2
|
96 |
# define _STLP_DO_LOG10(_Tp) _STLP_VENDOR_CSTD::log10
|
williamr@2
|
97 |
# define _STLP_DO_POW(_Tp) _STLP_VENDOR_CSTD::pow
|
williamr@2
|
98 |
# define _STLP_DO_SIN(_Tp) _STLP_VENDOR_CSTD::sin
|
williamr@2
|
99 |
# define _STLP_DO_SINH(_Tp) _STLP_VENDOR_CSTD::sinh
|
williamr@2
|
100 |
# define _STLP_DO_SQRT(_Tp) _STLP_VENDOR_CSTD::sqrt
|
williamr@2
|
101 |
# define _STLP_DO_TAN(_Tp) _STLP_VENDOR_CSTD::tan
|
williamr@2
|
102 |
# define _STLP_DO_TANH(_Tp) _STLP_VENDOR_CSTD::tanh
|
williamr@2
|
103 |
# define _STLP_DO_EXP(_Tp) _STLP_VENDOR_CSTD::exp
|
williamr@2
|
104 |
# define _STLP_DO_HYPOT(_Tp) ::hypot
|
williamr@2
|
105 |
# endif
|
williamr@2
|
106 |
|
williamr@2
|
107 |
_STLP_END_NAMESPACE
|
williamr@2
|
108 |
|
williamr@2
|
109 |
# if (defined (_STLP_HAS_NO_NEW_C_HEADERS) || defined(_STLP_MSVC) || defined (__ICL)) && !defined (_STLP_HAS_NO_NAMESPACES)
|
williamr@2
|
110 |
|
williamr@2
|
111 |
#if (! defined (_STLP_USE_NEW_C_HEADERS)) && ! defined (_STLP_VXWORKS_TORNADO)
|
williamr@2
|
112 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
113 |
|
williamr@2
|
114 |
# ifndef _STLP_HAS_NATIVE_FLOAT_ABS
|
williamr@2
|
115 |
inline double abs(double __x) { return _STLP_DO_ABS(double)(__x); }
|
williamr@2
|
116 |
inline float abs (float __x) { return _STLP_DO_ABS(float)(__x); }
|
williamr@2
|
117 |
# endif
|
williamr@2
|
118 |
|
williamr@2
|
119 |
#if ( defined (__SYMBIAN32__) || defined (__WINS__))
|
williamr@2
|
120 |
inline double pow(double __x, int __y) { return _STLP_DO_POW(double)(__x, __y); }
|
williamr@2
|
121 |
inline float acos (float __x) { return _STLP_DO_ACOS(float)(__x); }
|
williamr@2
|
122 |
inline float asin (float __x) { return _STLP_DO_ASIN(float)(__x); }
|
williamr@2
|
123 |
inline float atan (float __x) { return _STLP_DO_ATAN(float)(__x); }
|
williamr@2
|
124 |
inline float atan2(float __x, float __y) { return _STLP_DO_ATAN2(float)(__x, __y); }
|
williamr@2
|
125 |
inline float ceil (float __x) { return _STLP_DO_CEIL(float)(__x); }
|
williamr@2
|
126 |
inline float cos (float __x) { return _STLP_DO_COS(float)(__x); }
|
williamr@2
|
127 |
inline float cosh (float __x) { return _STLP_DO_COSH(float)(__x); }
|
williamr@2
|
128 |
inline float exp (float __x) { return _STLP_DO_EXP(float)(__x); }
|
williamr@2
|
129 |
# ifdef _STLP_USE_NAMESPACES
|
williamr@2
|
130 |
inline float fabs (float __x) { return _STLP_DO_ABS(float)(__x); }
|
williamr@2
|
131 |
# endif
|
williamr@2
|
132 |
inline float floor(float __x) { return _STLP_DO_FLOOR(float)(__x); }
|
williamr@2
|
133 |
inline float fmod (float __x, float __y) { return _STLP_DO_FMOD(float)(__x, __y); }
|
williamr@2
|
134 |
inline float frexp(float __x, int* __y) { return _STLP_DO_FREXP(float)(__x, __y); }
|
williamr@2
|
135 |
inline float ldexp(float __x, int __y) { return _STLP_DO_LDEXP(float)(__x, __y); }
|
williamr@2
|
136 |
// fbp : float versions are not always available
|
williamr@2
|
137 |
#if !defined(_STLP_VENDOR_LONG_DOUBLE_MATH) //*ty 11/25/2001 -
|
williamr@2
|
138 |
inline float modf (float __x, float* __y) {
|
williamr@2
|
139 |
#ifndef __SYMBIAN32__
|
williamr@2
|
140 |
double __dd[2];
|
williamr@2
|
141 |
double __res = _STLP_DO_MODF(double)((double)__x, __dd);
|
williamr@2
|
142 |
__y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1];
|
williamr@2
|
143 |
return (float)__res;
|
williamr@2
|
144 |
#else
|
williamr@2
|
145 |
float f = modff(__x, __y);
|
williamr@2
|
146 |
return f;
|
williamr@2
|
147 |
#endif
|
williamr@2
|
148 |
}
|
williamr@2
|
149 |
#else //*ty 11/25/2001 - i.e. for apple SCpp
|
williamr@2
|
150 |
inline float modf (float __x, float* __y) {
|
williamr@2
|
151 |
long double __dd[2];
|
williamr@2
|
152 |
long double __res = _STLP_DO_MODF(long double)((long double)__x, __dd);
|
williamr@2
|
153 |
__y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1];
|
williamr@2
|
154 |
return (float)__res;
|
williamr@2
|
155 |
}
|
williamr@2
|
156 |
#endif //*ty 11/25/2001 -
|
williamr@2
|
157 |
|
williamr@2
|
158 |
inline float log (float __x) { return _STLP_DO_LOG(float)(__x); }
|
williamr@2
|
159 |
inline float log10(float __x) { return _STLP_DO_LOG10(float)(__x); }
|
williamr@2
|
160 |
inline float pow (float __x, float __y) { return _STLP_DO_POW(float)(__x, __y); }
|
williamr@2
|
161 |
inline float pow (float __x, int __y) { return _STLP_DO_POW(float)(__x, __y); }
|
williamr@2
|
162 |
inline float sin (float __x) { return _STLP_DO_SIN(float)(__x); }
|
williamr@2
|
163 |
inline float sinh (float __x) { return _STLP_DO_SINH(float)(__x); }
|
williamr@2
|
164 |
inline float sqrt (float __x) { return _STLP_DO_SQRT(float)(__x); }
|
williamr@2
|
165 |
inline float tan (float __x) { return _STLP_DO_TAN(float)(__x); }
|
williamr@2
|
166 |
inline float tanh (float __x) { return _STLP_DO_TANH(float)(__x); }
|
williamr@2
|
167 |
|
williamr@2
|
168 |
# if ! (defined (_STLP_NO_LONG_DOUBLE) || defined(_STLP_VENDOR_LONG_DOUBLE_MATH))
|
williamr@2
|
169 |
|
williamr@2
|
170 |
#if !( defined (__MVS__) || defined (_STLP_HAS_NATIVE_FLOAT_ABS))
|
williamr@2
|
171 |
inline long double abs (long double __x) { return _STLP_DO_ABS(long double)((double)__x); }
|
williamr@2
|
172 |
#endif
|
williamr@2
|
173 |
inline long double acos (long double __x) { return _STLP_DO_ACOS(long double)(__x); }
|
williamr@2
|
174 |
inline long double asin (long double __x) { return _STLP_DO_ASIN(long double)(__x); }
|
williamr@2
|
175 |
inline long double atan (long double __x) { return _STLP_DO_ATAN(long double)(__x); }
|
williamr@2
|
176 |
inline long double atan2(long double __x, long double __y) { return _STLP_DO_ATAN2(long double)(__x, __y); }
|
williamr@2
|
177 |
inline long double ceil (long double __x) { return _STLP_DO_CEIL(long double)(__x); }
|
williamr@2
|
178 |
inline long double cos (long double __x) { return _STLP_DO_COS(long double)(__x); }
|
williamr@2
|
179 |
inline long double cosh (long double __x) { return _STLP_DO_COSH(long double)(__x); }
|
williamr@2
|
180 |
inline long double exp (long double __x) { return _STLP_DO_EXP(long double)(__x); }
|
williamr@2
|
181 |
inline long double fabs (long double __x) { return _STLP_DO_ABS(long double)(__x); }
|
williamr@2
|
182 |
inline long double floor(long double __x) { return _STLP_DO_FLOOR(long double)(__x); }
|
williamr@2
|
183 |
inline long double fmod (long double __x, long double __y) { return _STLP_DO_FMOD(long double)(__x, __y); }
|
williamr@2
|
184 |
inline long double frexp(long double __x, int* __y) { return _STLP_DO_FREXP(long double)(__x, __y); }
|
williamr@2
|
185 |
inline long double ldexp(long double __x, int __y) { return _STLP_DO_LDEXP(long double)(__x, __y); }
|
williamr@2
|
186 |
// fbp : long double versions are not available
|
williamr@2
|
187 |
inline long double modf (long double __x, long double* __y) {
|
williamr@2
|
188 |
double __dd[2];
|
williamr@2
|
189 |
double __res = _STLP_DO_MODF(double)((double)__x, __dd);
|
williamr@2
|
190 |
__y[0] = (long double)__dd[0] ; __y[1] = (long double)__dd[1];
|
williamr@2
|
191 |
return (long double)__res;
|
williamr@2
|
192 |
}
|
williamr@2
|
193 |
inline long double log (long double __x) { return _STLP_DO_LOG(long double)(__x); }
|
williamr@2
|
194 |
inline long double log10(long double __x) { return _STLP_DO_LOG10(long double)(__x); }
|
williamr@2
|
195 |
inline long double pow (long double __x, long double __y) { return _STLP_DO_POW(long double)(__x, __y); }
|
williamr@2
|
196 |
inline long double pow (long double __x, int __y) { return _STLP_DO_POW(long double)(__x, __y); }
|
williamr@2
|
197 |
inline long double sin (long double __x) { return _STLP_DO_SIN(long double)(__x); }
|
williamr@2
|
198 |
inline long double sinh (long double __x) { return _STLP_DO_SINH(long double)(__x); }
|
williamr@2
|
199 |
inline long double sqrt (long double __x) { return _STLP_DO_SQRT(long double)(__x); }
|
williamr@2
|
200 |
inline long double tan (long double __x) { return _STLP_DO_TAN(long double)(__x); }
|
williamr@2
|
201 |
inline long double tanh (long double __x) { return _STLP_DO_TANH(long double)(__x); }
|
williamr@2
|
202 |
#endif
|
williamr@2
|
203 |
#endif
|
williamr@2
|
204 |
|
williamr@2
|
205 |
_STLP_END_NAMESPACE
|
williamr@2
|
206 |
|
williamr@2
|
207 |
# endif /* NEW_C_HEADERS */
|
williamr@2
|
208 |
# endif /* NEW_C_HEADERS */
|
williamr@2
|
209 |
|
williamr@2
|
210 |
#endif /* CMATH_H */
|