williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 1999
|
williamr@4
|
3 |
* Boris Fomitchev
|
williamr@4
|
4 |
*
|
williamr@4
|
5 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
6 |
* or implied. Any use is at your own risk.
|
williamr@4
|
7 |
*
|
williamr@4
|
8 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
9 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
10 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
11 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
12 |
* modified is included with the above copyright notice.
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
*/
|
williamr@4
|
15 |
|
williamr@4
|
16 |
#ifndef _STLP_INTERNAL_CMATH
|
williamr@4
|
17 |
#define _STLP_INTERNAL_CMATH
|
williamr@4
|
18 |
|
williamr@4
|
19 |
/* gcc do not like when a using directive appear after a function
|
williamr@4
|
20 |
* declaration. cmath have abs overloads and cstdlib a using directive
|
williamr@4
|
21 |
* so cstdlib has to be included first.
|
williamr@4
|
22 |
*/
|
williamr@4
|
23 |
#if defined (__GNUC__) && defined (_STLP_USE_NEW_C_HEADERS)
|
williamr@4
|
24 |
# include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
|
williamr@4
|
25 |
#endif
|
williamr@4
|
26 |
|
williamr@4
|
27 |
#if defined (_STLP_USE_NEW_C_HEADERS)
|
williamr@4
|
28 |
# if defined (_STLP_HAS_NO_NAMESPACES) && !defined (exception)
|
williamr@4
|
29 |
# define exception __math_exception
|
williamr@4
|
30 |
# endif
|
williamr@4
|
31 |
# include _STLP_NATIVE_CPP_C_HEADER(cmath)
|
williamr@4
|
32 |
# if defined (_STLP_HAS_NO_NAMESPACES)
|
williamr@4
|
33 |
# undef exception
|
williamr@4
|
34 |
# endif
|
williamr@4
|
35 |
#else
|
williamr@4
|
36 |
# include <math.h>
|
williamr@4
|
37 |
#endif
|
williamr@4
|
38 |
|
williamr@4
|
39 |
#if (defined (__SUNPRO_CC) && (__SUNPRO_CC > 0x500)) || \
|
williamr@4
|
40 |
!(defined (__IBMCPP__) && (__IBMCPP__ >= 500) || !(defined(__HP_aCC) && (__HP_aCC >= 30000) ))
|
williamr@4
|
41 |
# ifndef _STLP_HAS_NO_NAMESPACES
|
williamr@4
|
42 |
namespace std {
|
williamr@4
|
43 |
# endif
|
williamr@4
|
44 |
extern "C" double hypot(double x, double y);
|
williamr@4
|
45 |
# ifndef _STLP_HAS_NO_NAMESPACES
|
williamr@4
|
46 |
}
|
williamr@4
|
47 |
# endif
|
williamr@4
|
48 |
|
williamr@4
|
49 |
#endif
|
williamr@4
|
50 |
|
williamr@4
|
51 |
#if defined (__sun) && defined (__GNUC__)
|
williamr@4
|
52 |
extern "C" {
|
williamr@4
|
53 |
float __cosf(float v);
|
williamr@4
|
54 |
float __sinf(float v);
|
williamr@4
|
55 |
float __atan2f(float, float);
|
williamr@4
|
56 |
float __coshf(float v);
|
williamr@4
|
57 |
float __sinhf(float v);
|
williamr@4
|
58 |
float __sqrtf(float v);
|
williamr@4
|
59 |
float __expf(float v);
|
williamr@4
|
60 |
float __logf(float v);
|
williamr@4
|
61 |
float __log10f(float v);
|
williamr@4
|
62 |
|
williamr@4
|
63 |
long double __cosl(long double v);
|
williamr@4
|
64 |
long double __sinl(long double v);
|
williamr@4
|
65 |
long double __atan2l(long double, long double);
|
williamr@4
|
66 |
long double __coshl(long double v);
|
williamr@4
|
67 |
long double __sinhl(long double v);
|
williamr@4
|
68 |
long double __sqrtl(long double v);
|
williamr@4
|
69 |
long double __expl(long double v);
|
williamr@4
|
70 |
long double __logl(long double v);
|
williamr@4
|
71 |
long double __log10l(long double v);
|
williamr@4
|
72 |
}
|
williamr@4
|
73 |
|
williamr@4
|
74 |
extern "C" {
|
williamr@4
|
75 |
inline float cosf(float v) { return __cosf(v); }
|
williamr@4
|
76 |
inline float sinf(float v) { return __sinf(v); }
|
williamr@4
|
77 |
inline float atan2f(float v1, float v2) { return __atan2f(v1,v2); }
|
williamr@4
|
78 |
inline float coshf(float v) { return __coshf(v); }
|
williamr@4
|
79 |
inline float sinhf(float v) { return __sinhf(v); }
|
williamr@4
|
80 |
inline float sqrtf(float v) { return __sqrtf(v); }
|
williamr@4
|
81 |
inline float expf(float v) { return __expf(v); }
|
williamr@4
|
82 |
inline float logf(float v) { return __logf(v); }
|
williamr@4
|
83 |
inline float log10f(float v) { return __log10f(v); }
|
williamr@4
|
84 |
|
williamr@4
|
85 |
inline long double cosl(long double v) { return __cosl(v); }
|
williamr@4
|
86 |
inline long double sinl(long double v) { return __sinl(v); }
|
williamr@4
|
87 |
inline long double atan2l(long double v1, long double v2) { return __atan2l(v1,v2); }
|
williamr@4
|
88 |
inline long double coshl(long double v) { return __coshl(v); }
|
williamr@4
|
89 |
inline long double sinhl(long double v) { return __sinhl(v); }
|
williamr@4
|
90 |
inline long double sqrtl(long double v) { return __sqrtl(v); }
|
williamr@4
|
91 |
inline long double expl(long double v) { return __expl(v); }
|
williamr@4
|
92 |
inline long double logl(long double v) { return __logl(v); }
|
williamr@4
|
93 |
inline long double log10l(long double v) { return __log10l(v); }
|
williamr@4
|
94 |
}
|
williamr@4
|
95 |
#endif // __sun && __GNUC__
|
williamr@4
|
96 |
|
williamr@4
|
97 |
#if defined (__sun)
|
williamr@4
|
98 |
extern "C" {
|
williamr@4
|
99 |
extern float __acosf(float);
|
williamr@4
|
100 |
extern float __asinf(float);
|
williamr@4
|
101 |
extern float __atanf(float);
|
williamr@4
|
102 |
extern float __atan2f(float, float);
|
williamr@4
|
103 |
extern float __ceilf(float);
|
williamr@4
|
104 |
extern float __cosf(float);
|
williamr@4
|
105 |
extern float __coshf(float);
|
williamr@4
|
106 |
extern float __expf(float);
|
williamr@4
|
107 |
extern float __fabsf(float);
|
williamr@4
|
108 |
extern float __floorf(float);
|
williamr@4
|
109 |
extern float __fmodf(float, float);
|
williamr@4
|
110 |
extern float __frexpf(float, int *);
|
williamr@4
|
111 |
extern float __ldexpf(float, int);
|
williamr@4
|
112 |
extern float __logf(float);
|
williamr@4
|
113 |
extern float __log10f(float);
|
williamr@4
|
114 |
extern float __modff(float, float *);
|
williamr@4
|
115 |
extern float __powf(float, float);
|
williamr@4
|
116 |
extern float __sinf(float);
|
williamr@4
|
117 |
extern float __sinhf(float);
|
williamr@4
|
118 |
extern float __sqrtf(float);
|
williamr@4
|
119 |
extern float __tanf(float);
|
williamr@4
|
120 |
extern float __tanhf(float);
|
williamr@4
|
121 |
|
williamr@4
|
122 |
extern long double __acosl(long double);
|
williamr@4
|
123 |
extern long double __asinl(long double);
|
williamr@4
|
124 |
extern long double __atanl(long double);
|
williamr@4
|
125 |
extern long double __atan2l(long double, long double);
|
williamr@4
|
126 |
extern long double __ceill(long double);
|
williamr@4
|
127 |
extern long double __cosl(long double);
|
williamr@4
|
128 |
extern long double __coshl(long double);
|
williamr@4
|
129 |
extern long double __expl(long double);
|
williamr@4
|
130 |
extern long double __fabsl(long double);
|
williamr@4
|
131 |
extern long double __floorl(long double);
|
williamr@4
|
132 |
extern long double __fmodl(long double, long double);
|
williamr@4
|
133 |
extern long double __frexpl(long double, int *);
|
williamr@4
|
134 |
extern long double __ldexpl(long double, int);
|
williamr@4
|
135 |
extern long double __logl(long double);
|
williamr@4
|
136 |
extern long double __log10l(long double);
|
williamr@4
|
137 |
extern long double __modfl(long double, long double *);
|
williamr@4
|
138 |
extern long double __powl(long double, long double);
|
williamr@4
|
139 |
extern long double __sinl(long double);
|
williamr@4
|
140 |
extern long double __sinhl(long double);
|
williamr@4
|
141 |
extern long double __sqrtl(long double);
|
williamr@4
|
142 |
extern long double __tanl(long double);
|
williamr@4
|
143 |
extern long double __tanhl(long double);
|
williamr@4
|
144 |
}
|
williamr@4
|
145 |
#endif
|
williamr@4
|
146 |
|
williamr@4
|
147 |
#if defined (__BORLANDC__)
|
williamr@4
|
148 |
# define _STLP_CMATH_FUNC_NAMESPACE _STLP_VENDOR_CSTD
|
williamr@4
|
149 |
#else
|
williamr@4
|
150 |
# define _STLP_CMATH_FUNC_NAMESPACE
|
williamr@4
|
151 |
#endif
|
williamr@4
|
152 |
|
williamr@4
|
153 |
#if !defined (__sun) || defined (__GNUC__)
|
williamr@4
|
154 |
# define _STLP_MATH_INLINE(float_type, func, cfunc) \
|
williamr@4
|
155 |
inline float_type func (float_type x) { return _STLP_CMATH_FUNC_NAMESPACE::cfunc(x); }
|
williamr@4
|
156 |
# define _STLP_MATH_INLINE2(float_type, type, func, cfunc) \
|
williamr@4
|
157 |
inline float_type func (float_type x, type y) { return _STLP_CMATH_FUNC_NAMESPACE::cfunc(x, y); }
|
williamr@4
|
158 |
# define _STLP_MATH_INLINE_D(float_type, func, cfunc)
|
williamr@4
|
159 |
# define _STLP_MATH_INLINE2_D(float_type, type, func, cfunc)
|
williamr@4
|
160 |
#else
|
williamr@4
|
161 |
# ifdef __SUNPRO_CC
|
williamr@4
|
162 |
# define _STLP_MATH_INLINE(float_type, func, cfunc) \
|
williamr@4
|
163 |
inline float_type func (float_type x) { return _STLP_VENDOR_CSTD::__##cfunc(x); }
|
williamr@4
|
164 |
# define _STLP_MATH_INLINE_D(float_type, func, cfunc) \
|
williamr@4
|
165 |
inline float_type func (float_type x) { return _STLP_VENDOR_CSTD::cfunc(x); }
|
williamr@4
|
166 |
# define _STLP_MATH_INLINE2(float_type, type, func, cfunc) \
|
williamr@4
|
167 |
inline float_type func (float_type x, type y) { return _STLP_VENDOR_CSTD::__##cfunc(x,y); }
|
williamr@4
|
168 |
# define _STLP_MATH_INLINE2_D(float_type, type, func, cfunc) \
|
williamr@4
|
169 |
inline float_type func (float_type x, type y) { return _STLP_VENDOR_CSTD::cfunc(x,y); }
|
williamr@4
|
170 |
# else
|
williamr@4
|
171 |
# error Unknown compiler for the Sun platform
|
williamr@4
|
172 |
# endif
|
williamr@4
|
173 |
#endif
|
williamr@4
|
174 |
|
williamr@4
|
175 |
/** macros to define math functions
|
williamr@4
|
176 |
These macros (having an X somewhere in the name) forward to the C library's
|
williamr@4
|
177 |
double functions but cast the arguments and return values to the given type. */
|
williamr@4
|
178 |
|
williamr@4
|
179 |
#define _STLP_MATH_INLINEX(__type,func,cfunc) \
|
williamr@4
|
180 |
inline __type func (__type x) \
|
williamr@4
|
181 |
{ return __STATIC_CAST(__type, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x)); }
|
williamr@4
|
182 |
#define _STLP_MATH_INLINE2X(__type1,__type2,func,cfunc) \
|
williamr@4
|
183 |
inline __type1 func (__type1 x, __type2 y) \
|
williamr@4
|
184 |
{ return __STATIC_CAST(__type1, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x, y)); }
|
williamr@4
|
185 |
#define _STLP_MATH_INLINE2PX(__type,func,cfunc) \
|
williamr@4
|
186 |
inline __type func (__type x, __type *y) { \
|
williamr@4
|
187 |
double tmp1, tmp2; \
|
williamr@4
|
188 |
tmp1 = _STLP_CMATH_FUNC_NAMESPACE::cfunc(__STATIC_CAST(double, x), &tmp2); \
|
williamr@4
|
189 |
*y = __STATIC_CAST(__type, tmp2); \
|
williamr@4
|
190 |
return __STATIC_CAST(__type, tmp1); \
|
williamr@4
|
191 |
}
|
williamr@4
|
192 |
#define _STLP_MATH_INLINE2XX(__type,func,cfunc) \
|
williamr@4
|
193 |
inline __type func (__type x, __type y) \
|
williamr@4
|
194 |
{ return __STATIC_CAST(__type, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x, (double)y)); }
|
williamr@4
|
195 |
|
williamr@4
|
196 |
|
williamr@4
|
197 |
/** rough characterization of compiler and native C library
|
williamr@4
|
198 |
For the compiler, it can either support long double or not. If it doesn't, the
|
williamr@4
|
199 |
macro _STLP_NO_LONG_DOUBLE is not defined and we don't define any long double
|
williamr@4
|
200 |
overloads.
|
williamr@4
|
201 |
For the native C library the question is whether it has variants with an 'f'
|
williamr@4
|
202 |
suffix (for float as opposed to double) or an 'l' suffix (for long double). If
|
williamr@4
|
203 |
the float variants are missing, _STLP_NO_VENDOR_MATH_F is defined, when the
|
williamr@4
|
204 |
long double variants are missing, _STLP_NO_VENDOR_MATH_L is defined. Of course
|
williamr@4
|
205 |
the latter doesn't make sense anyway when the compiler already has no long
|
williamr@4
|
206 |
double support.
|
williamr@4
|
207 |
|
williamr@4
|
208 |
Those two traits determine a) which overloads get defined and b) how they are
|
williamr@4
|
209 |
defined.
|
williamr@4
|
210 |
|
williamr@4
|
211 |
Meaning of suffixes:
|
williamr@4
|
212 |
"" : function returning and taking a float_type
|
williamr@4
|
213 |
"2" : function returning a float_type and taking to float_types
|
williamr@4
|
214 |
"2P" : function returning a float_type and taking a float_type and a float_type*
|
williamr@4
|
215 |
"2PI": function returning a float_type and taking a float_type and an int*
|
williamr@4
|
216 |
"2I" : function returning a float_type and taking a float_Type and an int
|
williamr@4
|
217 |
*/
|
williamr@4
|
218 |
|
williamr@4
|
219 |
#if !defined (_STLP_NO_LONG_DOUBLE) && !defined (_STLP_NO_VENDOR_MATH_L) && !defined (_STLP_NO_VENDOR_MATH_F)
|
williamr@4
|
220 |
// long double support and both e.g. sinl(long double) and sinf(float)
|
williamr@4
|
221 |
// This is the default for a correct and complete native library.
|
williamr@4
|
222 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
223 |
_STLP_MATH_INLINE(float,func,cf##f) \
|
williamr@4
|
224 |
_STLP_MATH_INLINE_D(double,func,cf) \
|
williamr@4
|
225 |
_STLP_MATH_INLINE(long double,func,cf##l)
|
williamr@4
|
226 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
227 |
_STLP_MATH_INLINE2(float,float,func,cf##f) \
|
williamr@4
|
228 |
_STLP_MATH_INLINE2_D(double,double,func,cf) \
|
williamr@4
|
229 |
_STLP_MATH_INLINE2(long double,long double,func,cf##l)
|
williamr@4
|
230 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
231 |
_STLP_MATH_INLINE2(float,float *,func,cf##f) \
|
williamr@4
|
232 |
_STLP_MATH_INLINE2_D(double,double *,func,cf) \
|
williamr@4
|
233 |
_STLP_MATH_INLINE2(long double,long double *,func,cf##l)
|
williamr@4
|
234 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
235 |
_STLP_MATH_INLINE2(float,int *,func,cf##f) \
|
williamr@4
|
236 |
_STLP_MATH_INLINE2_D(double,int *,func,cf) \
|
williamr@4
|
237 |
_STLP_MATH_INLINE2(long double,int *,func,cf##l)
|
williamr@4
|
238 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
239 |
_STLP_MATH_INLINE2(float,int,func,cf##f) \
|
williamr@4
|
240 |
_STLP_MATH_INLINE2_D(double,int,func,cf) \
|
williamr@4
|
241 |
_STLP_MATH_INLINE2(long double,int,func,cf##l)
|
williamr@4
|
242 |
#else
|
williamr@4
|
243 |
# if !defined (_STLP_NO_LONG_DOUBLE)
|
williamr@4
|
244 |
# if !defined (_STLP_NO_VENDOR_MATH_F)
|
williamr@4
|
245 |
// long double support and e.g. sinf(float) but not e.g. sinl(long double)
|
williamr@4
|
246 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
247 |
_STLP_MATH_INLINE(float,func,cf##f) \
|
williamr@4
|
248 |
_STLP_MATH_INLINEX(long double,func,cf)
|
williamr@4
|
249 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
250 |
_STLP_MATH_INLINE2(float,float,func,cf##f) \
|
williamr@4
|
251 |
_STLP_MATH_INLINE2XX(long double,func,cf)
|
williamr@4
|
252 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
253 |
_STLP_MATH_INLINE2(float,float *,func,cf##f) \
|
williamr@4
|
254 |
_STLP_MATH_INLINE2PX(long double,func,cf)
|
williamr@4
|
255 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
256 |
_STLP_MATH_INLINE2(float,int *,func,cf##f) \
|
williamr@4
|
257 |
_STLP_MATH_INLINE2X(long double,int *,func,cf)
|
williamr@4
|
258 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
259 |
_STLP_MATH_INLINE2(float,int,func,cf##f) \
|
williamr@4
|
260 |
_STLP_MATH_INLINE2X(long double,int,func,cf)
|
williamr@4
|
261 |
# elif !defined (_STLP_NO_VENDOR_MATH_L)
|
williamr@4
|
262 |
// long double support and e.g. sinl(long double) but not e.g. sinf(float)
|
williamr@4
|
263 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
264 |
_STLP_MATH_INLINEX(float,func,cf) \
|
williamr@4
|
265 |
_STLP_MATH_INLINE(long double,func,cf##l)
|
williamr@4
|
266 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
267 |
_STLP_MATH_INLINE2XX(float,func,cf) \
|
williamr@4
|
268 |
_STLP_MATH_INLINE2(long double,long double,func,cf##l)
|
williamr@4
|
269 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
270 |
_STLP_MATH_INLINE2PX(float,func,cf) \
|
williamr@4
|
271 |
_STLP_MATH_INLINE2(long double,long double *,func,cf##l)
|
williamr@4
|
272 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
273 |
_STLP_MATH_INLINE2X(float,int *,func,cf) \
|
williamr@4
|
274 |
_STLP_MATH_INLINE2(long double,int *,func,cf##l)
|
williamr@4
|
275 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
276 |
_STLP_MATH_INLINE2X(float,int,func,cf) \
|
williamr@4
|
277 |
_STLP_MATH_INLINE2(long double,int,func,cf##l)
|
williamr@4
|
278 |
# else
|
williamr@4
|
279 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
280 |
_STLP_MATH_INLINEX(float,func,cf) \
|
williamr@4
|
281 |
_STLP_MATH_INLINEX(long double,func,cf)
|
williamr@4
|
282 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
283 |
_STLP_MATH_INLINE2XX(float,func,cf) \
|
williamr@4
|
284 |
_STLP_MATH_INLINE2XX(long double,func,cf)
|
williamr@4
|
285 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
286 |
_STLP_MATH_INLINE2PX(float,func,cf) \
|
williamr@4
|
287 |
_STLP_MATH_INLINE2PX(long double,func,cf)
|
williamr@4
|
288 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
289 |
_STLP_MATH_INLINE2X(float,int *,func,cf) \
|
williamr@4
|
290 |
_STLP_MATH_INLINE2X(long double,int *,func,cf)
|
williamr@4
|
291 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
292 |
_STLP_MATH_INLINE2X(float,int,func,cf) \
|
williamr@4
|
293 |
_STLP_MATH_INLINE2X(long double,int,func,cf)
|
williamr@4
|
294 |
# endif
|
williamr@4
|
295 |
# else
|
williamr@4
|
296 |
# if !defined (_STLP_NO_VENDOR_MATH_F)
|
williamr@4
|
297 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
298 |
_STLP_MATH_INLINE(float,func,cf##f)
|
williamr@4
|
299 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
300 |
_STLP_MATH_INLINE2(float,float,func,cf##f)
|
williamr@4
|
301 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
302 |
_STLP_MATH_INLINE2(float,float *,func,cf##f)
|
williamr@4
|
303 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
304 |
_STLP_MATH_INLINE2(float,int *,func,cf##f)
|
williamr@4
|
305 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
306 |
_STLP_MATH_INLINE2(float,int,func,cf##f)
|
williamr@4
|
307 |
# else // _STLP_NO_VENDOR_MATH_F
|
williamr@4
|
308 |
// neither long double support nor e.g. sinf(float) functions
|
williamr@4
|
309 |
# define _STLP_DEF_MATH_INLINE(func,cf) \
|
williamr@4
|
310 |
_STLP_MATH_INLINEX(float,func,cf)
|
williamr@4
|
311 |
# define _STLP_DEF_MATH_INLINE2(func,cf) \
|
williamr@4
|
312 |
_STLP_MATH_INLINE2XX(float,func,cf)
|
williamr@4
|
313 |
# define _STLP_DEF_MATH_INLINE2P(func,cf) \
|
williamr@4
|
314 |
_STLP_MATH_INLINE2PX(float,func,cf)
|
williamr@4
|
315 |
# define _STLP_DEF_MATH_INLINE2PI(func,cf) \
|
williamr@4
|
316 |
_STLP_MATH_INLINE2X(float,int *,func,cf)
|
williamr@4
|
317 |
# define _STLP_DEF_MATH_INLINE2I(func,cf) \
|
williamr@4
|
318 |
_STLP_MATH_INLINE2X(float,int,func,cf)
|
williamr@4
|
319 |
# endif // _STLP_NO_VENDOR_MATH_F
|
williamr@4
|
320 |
# endif
|
williamr@4
|
321 |
#endif
|
williamr@4
|
322 |
|
williamr@4
|
323 |
#if defined (_STLP_WCE) || \
|
williamr@4
|
324 |
(defined(_STLP_MSVC) && (_STLP_MSVC <= 1300) && defined (_MSC_EXTENSIONS) /* && !defined(_STLP_WCE_NET) */)
|
williamr@4
|
325 |
/*
|
williamr@4
|
326 |
* dums: VC6 has all the required C++ functions but only define them if
|
williamr@4
|
327 |
* _MSC_EXTENSIONS is not defined (a bug?). STLport just do the same
|
williamr@4
|
328 |
* thing also when _MSC_EXTENSIONS is defined.
|
williamr@4
|
329 |
* TODO: above check (_STLP_MSVC <= 1300) also catches VC7.0, is that intended?
|
williamr@4
|
330 |
*/
|
williamr@4
|
331 |
//We have to tell the compilers that abs, acos ... math functions are not intrinsic
|
williamr@4
|
332 |
//otherwise we have Internal Compiler Error in release mode...
|
williamr@4
|
333 |
# pragma warning(push)
|
williamr@4
|
334 |
# pragma warning(disable: 4162) // no function with C linkage found
|
williamr@4
|
335 |
# pragma warning(disable: 4163) // not available as an intrinsic function
|
williamr@4
|
336 |
# pragma function (abs, acos, asin, atan, atan2, cos, cosh, exp, fabs, fmod, log, log10, sin, sinh, sqrt, tan, tanh)
|
williamr@4
|
337 |
# if defined (_STLP_WCE)
|
williamr@4
|
338 |
# pragma function (ceil, floor)
|
williamr@4
|
339 |
# endif
|
williamr@4
|
340 |
# define _STLP_RESTORE_FUNCTION_INTRINSIC
|
williamr@4
|
341 |
#endif // _STLP_MSVC && _STLP_MSVC <= 1300 && !_STLP_WCE && _MSC_EXTENSIONS
|
williamr@4
|
342 |
|
williamr@4
|
343 |
#if defined (__BORLANDC__) && defined (_STLP_USE_NEW_C_HEADERS)
|
williamr@4
|
344 |
/* In this config Borland native lib only define functions in std namespace.
|
williamr@4
|
345 |
* In order to have all overloads in STLport namespace we need to add the
|
williamr@4
|
346 |
* double overload in global namespace. We do not use a using statement to avoid
|
williamr@4
|
347 |
* import of invalid overload.
|
williamr@4
|
348 |
*/
|
williamr@4
|
349 |
# define _STLP_DMATH_INLINE(func) _STLP_MATH_INLINE(double, func, func)
|
williamr@4
|
350 |
# define _STLP_DMATH_INLINE2(func) _STLP_MATH_INLINE2(double, double, func, func)
|
williamr@4
|
351 |
|
williamr@4
|
352 |
_STLP_DMATH_INLINE(acos)
|
williamr@4
|
353 |
_STLP_DMATH_INLINE(asin)
|
williamr@4
|
354 |
_STLP_DMATH_INLINE(atan)
|
williamr@4
|
355 |
_STLP_DMATH_INLINE2(atan2)
|
williamr@4
|
356 |
_STLP_DMATH_INLINE(ceil)
|
williamr@4
|
357 |
_STLP_DMATH_INLINE(cos)
|
williamr@4
|
358 |
_STLP_DMATH_INLINE(cosh)
|
williamr@4
|
359 |
_STLP_DMATH_INLINE(exp)
|
williamr@4
|
360 |
_STLP_DMATH_INLINE(fabs)
|
williamr@4
|
361 |
_STLP_DMATH_INLINE(floor)
|
williamr@4
|
362 |
_STLP_DMATH_INLINE2(fmod)
|
williamr@4
|
363 |
_STLP_MATH_INLINE2X(double, int*, frexp, frexp)
|
williamr@4
|
364 |
_STLP_MATH_INLINE2X(double, int, ldexp, ldexp)
|
williamr@4
|
365 |
_STLP_DMATH_INLINE(log)
|
williamr@4
|
366 |
_STLP_DMATH_INLINE(log10)
|
williamr@4
|
367 |
_STLP_MATH_INLINE2PX(double, modf, modf)
|
williamr@4
|
368 |
_STLP_DMATH_INLINE(sin)
|
williamr@4
|
369 |
_STLP_DMATH_INLINE(sinh)
|
williamr@4
|
370 |
_STLP_DMATH_INLINE(sqrt)
|
williamr@4
|
371 |
_STLP_DMATH_INLINE(tan)
|
williamr@4
|
372 |
_STLP_DMATH_INLINE(tanh)
|
williamr@4
|
373 |
_STLP_DMATH_INLINE2(pow)
|
williamr@4
|
374 |
_STLP_DMATH_INLINE2(hypot)
|
williamr@4
|
375 |
|
williamr@4
|
376 |
# undef _STLP_DMATH_INLINE
|
williamr@4
|
377 |
# undef _STLP_DMATH_INLINE2
|
williamr@4
|
378 |
#endif
|
williamr@4
|
379 |
|
williamr@4
|
380 |
#if defined (__DMC__)
|
williamr@4
|
381 |
# if defined (fabs)
|
williamr@4
|
382 |
inline double __stlp_fabs(double __x) { return fabs(__x); }
|
williamr@4
|
383 |
# undef fabs
|
williamr@4
|
384 |
inline double fabs(double __x) { return __stlp_fabs(__x); }
|
williamr@4
|
385 |
# endif
|
williamr@4
|
386 |
# if defined (cos)
|
williamr@4
|
387 |
inline double __stlp_cos(double __x) { return cos(__x); }
|
williamr@4
|
388 |
# undef cos
|
williamr@4
|
389 |
inline double cos(double __x) { return __stlp_cos(__x); }
|
williamr@4
|
390 |
# endif
|
williamr@4
|
391 |
# if defined (sin)
|
williamr@4
|
392 |
inline double __stlp_sin(double __x) { return sin(__x); }
|
williamr@4
|
393 |
# undef sin
|
williamr@4
|
394 |
inline double sin(double __x) { return __stlp_sin(__x); }
|
williamr@4
|
395 |
# endif
|
williamr@4
|
396 |
# if defined (sqrt)
|
williamr@4
|
397 |
inline double __stlp_sqrt(double __x) { return sqrt(__x); }
|
williamr@4
|
398 |
# undef sqrt
|
williamr@4
|
399 |
inline double sqrt(double __x) { return __stlp_sqrt(__x); }
|
williamr@4
|
400 |
# endif
|
williamr@4
|
401 |
# if defined (ldexp)
|
williamr@4
|
402 |
inline double __stlp_ldexp(double __x, int __y) { return ldexp(__x, __y); }
|
williamr@4
|
403 |
# undef ldexp
|
williamr@4
|
404 |
inline double ldexp(double __x, int __y) { return __stlp_ldexp(__x, __y); }
|
williamr@4
|
405 |
# endif
|
williamr@4
|
406 |
#endif
|
williamr@4
|
407 |
|
williamr@4
|
408 |
/* MSVC native lib starting with .Net 2003 has already all math functions
|
williamr@4
|
409 |
* in global namespace.
|
williamr@4
|
410 |
* HP-UX native lib has math functions in the global namespace.
|
williamr@4
|
411 |
*/
|
williamr@4
|
412 |
#if (!defined (_STLP_MSVC_LIB) || (_STLP_MSVC_LIB < 1310) || defined(UNDER_CE)) && \
|
williamr@4
|
413 |
(!defined (__HP_aCC) || (__HP_aCC < 30000))
|
williamr@4
|
414 |
inline double abs(double __x)
|
williamr@4
|
415 |
{ return ::fabs(__x); }
|
williamr@4
|
416 |
# if !defined (__MVS__)
|
williamr@4
|
417 |
_STLP_DEF_MATH_INLINE(abs, fabs)
|
williamr@4
|
418 |
# else // __MVS__ has native long double abs?
|
williamr@4
|
419 |
inline float abs(float __x) { return ::fabsf(__x); }
|
williamr@4
|
420 |
# endif
|
williamr@4
|
421 |
|
williamr@4
|
422 |
_STLP_DEF_MATH_INLINE(acos, acos)
|
williamr@4
|
423 |
_STLP_DEF_MATH_INLINE(asin, asin)
|
williamr@4
|
424 |
_STLP_DEF_MATH_INLINE(atan, atan)
|
williamr@4
|
425 |
_STLP_DEF_MATH_INLINE2(atan2, atan2)
|
williamr@4
|
426 |
_STLP_DEF_MATH_INLINE(ceil, ceil)
|
williamr@4
|
427 |
_STLP_DEF_MATH_INLINE(cos, cos)
|
williamr@4
|
428 |
_STLP_DEF_MATH_INLINE(cosh, cosh)
|
williamr@4
|
429 |
_STLP_DEF_MATH_INLINE(exp, exp)
|
williamr@4
|
430 |
_STLP_DEF_MATH_INLINE(fabs, fabs)
|
williamr@4
|
431 |
_STLP_DEF_MATH_INLINE(floor, floor)
|
williamr@4
|
432 |
_STLP_DEF_MATH_INLINE2(fmod, fmod)
|
williamr@4
|
433 |
_STLP_DEF_MATH_INLINE2PI(frexp, frexp)
|
williamr@4
|
434 |
_STLP_DEF_MATH_INLINE2I(ldexp, ldexp)
|
williamr@4
|
435 |
_STLP_DEF_MATH_INLINE(log, log)
|
williamr@4
|
436 |
_STLP_DEF_MATH_INLINE(log10, log10)
|
williamr@4
|
437 |
_STLP_DEF_MATH_INLINE2P(modf, modf)
|
williamr@4
|
438 |
_STLP_DEF_MATH_INLINE(sin, sin)
|
williamr@4
|
439 |
_STLP_DEF_MATH_INLINE(sinh, sinh)
|
williamr@4
|
440 |
_STLP_DEF_MATH_INLINE(sqrt, sqrt)
|
williamr@4
|
441 |
_STLP_DEF_MATH_INLINE(tan, tan)
|
williamr@4
|
442 |
_STLP_DEF_MATH_INLINE(tanh, tanh)
|
williamr@4
|
443 |
_STLP_DEF_MATH_INLINE2(pow, pow)
|
williamr@4
|
444 |
|
williamr@4
|
445 |
# if !defined(_STLP_MSVC) /* || (_STLP_MSVC > 1300) */ || defined(_STLP_WCE) || !defined (_MSC_EXTENSIONS) /* && !defined(_STLP_WCE_NET) */
|
williamr@4
|
446 |
# ifndef _STLP_NO_VENDOR_MATH_F
|
williamr@4
|
447 |
# ifndef __sun
|
williamr@4
|
448 |
inline float pow(float __x, int __y) { return _STLP_CMATH_FUNC_NAMESPACE::powf(__x, __STATIC_CAST(float,__y)); }
|
williamr@4
|
449 |
# else
|
williamr@4
|
450 |
inline float pow(float __x, int __y) { return ::__powf(__x, __STATIC_CAST(float,__y)); }
|
williamr@4
|
451 |
# endif
|
williamr@4
|
452 |
# else
|
williamr@4
|
453 |
inline float pow(float __x, int __y) { return __STATIC_CAST(float, _STLP_CMATH_FUNC_NAMESPACE::pow(__x, __STATIC_CAST(float,__y))); }
|
williamr@4
|
454 |
# endif
|
williamr@4
|
455 |
inline double pow(double __x, int __y) { return _STLP_CMATH_FUNC_NAMESPACE::pow(__x, __STATIC_CAST(double,__y)); }
|
williamr@4
|
456 |
# if !defined (_STLP_NO_LONG_DOUBLE)
|
williamr@4
|
457 |
# if !defined(_STLP_NO_VENDOR_MATH_L)
|
williamr@4
|
458 |
# ifndef __sun
|
williamr@4
|
459 |
inline long double pow(long double __x, int __y) { return _STLP_CMATH_FUNC_NAMESPACE::powl(__x, __STATIC_CAST(long double,__y)); }
|
williamr@4
|
460 |
# else
|
williamr@4
|
461 |
# ifndef __SUNPRO_CC
|
williamr@4
|
462 |
inline long double pow(long double __x, int __y) { return ::__powl(__x, __STATIC_CAST(long double,__y)); }
|
williamr@4
|
463 |
# else
|
williamr@4
|
464 |
inline long double pow(long double __x, int __y) { return _STLP_VENDOR_CSTD::__powl(__x, __STATIC_CAST(long double,__y)); }
|
williamr@4
|
465 |
# endif
|
williamr@4
|
466 |
# endif
|
williamr@4
|
467 |
# else
|
williamr@4
|
468 |
inline long double pow(long double __x, int __y) { return __STATIC_CAST(long double, _STLP_CMATH_FUNC_NAMESPACE::pow(__x, __STATIC_CAST(long double,__y))); }
|
williamr@4
|
469 |
# endif
|
williamr@4
|
470 |
# endif
|
williamr@4
|
471 |
# else
|
williamr@4
|
472 |
//The MS native pow version has a bugged overload so it is not imported
|
williamr@4
|
473 |
//in the STLport namespace.
|
williamr@4
|
474 |
//Here is the bugged version:
|
williamr@4
|
475 |
//inline double pow(int __x, int __y) { return (_Pow_int(__x, __y)); }
|
williamr@4
|
476 |
inline double pow(double __x, int __y) { return (_Pow_int(__x, __y)); }
|
williamr@4
|
477 |
inline float pow(float __x, int __y) { return (_Pow_int(__x, __y)); }
|
williamr@4
|
478 |
inline long double pow(long double __x, int __y) { return (_Pow_int(__x, __y)); }
|
williamr@4
|
479 |
# endif
|
williamr@4
|
480 |
#endif
|
williamr@4
|
481 |
|
williamr@4
|
482 |
#if (defined (_STLP_MSVC) && !defined (_STLP_WCE)) || defined (__ICL) || defined (__sun)
|
williamr@4
|
483 |
# if defined (_STLP_MSVC) && (_STLP_MSVC >= 1400)
|
williamr@4
|
484 |
# pragma warning (push)
|
williamr@4
|
485 |
# pragma warning (disable : 4996) // hypot is deprecated.
|
williamr@4
|
486 |
# endif
|
williamr@4
|
487 |
_STLP_MATH_INLINE2XX(float, hypot, hypot)
|
williamr@4
|
488 |
inline long double hypot(long double x, long double y) { return sqrt(x * x + y * y); }
|
williamr@4
|
489 |
# if defined (_STLP_MSVC) && (_STLP_MSVC >= 1400)
|
williamr@4
|
490 |
# pragma warning (pop)
|
williamr@4
|
491 |
# endif
|
williamr@4
|
492 |
#else
|
williamr@4
|
493 |
# if defined (_STLP_USE_UCLIBC)
|
williamr@4
|
494 |
inline double hypot(double x, double y) { return sqrt(x * x + y * y); }
|
williamr@4
|
495 |
_STLP_DEF_MATH_INLINE2(hypot, hypot)
|
williamr@4
|
496 |
# elif defined (_STLP_WCE)
|
williamr@4
|
497 |
/* CE has a double _hypot(double,double) which we use */
|
williamr@4
|
498 |
inline double hypot(double __x, double __y) { return _hypot(__x,__y); }
|
williamr@4
|
499 |
_STLP_DEF_MATH_INLINE2(hypot, _hypot)
|
williamr@4
|
500 |
# endif
|
williamr@4
|
501 |
#endif
|
williamr@4
|
502 |
|
williamr@4
|
503 |
#if defined (_STLP_RESTORE_FUNCTION_INTRINSIC)
|
williamr@4
|
504 |
//restoration of the default intrinsic status of those functions:
|
williamr@4
|
505 |
# pragma intrinsic (abs, acos, asin, atan, atan2, cos, cosh, exp, fabs, fmod, log, log10, sin, sinh, sqrt, tan, tanh)
|
williamr@4
|
506 |
# if defined (_STLP_WCE)
|
williamr@4
|
507 |
# pragma intrinsic (ceil, floor)
|
williamr@4
|
508 |
# endif
|
williamr@4
|
509 |
# pragma warning(pop)
|
williamr@4
|
510 |
# undef _STLP_RESTORE_FUNCTION_INTRINSIC
|
williamr@4
|
511 |
#endif // _STLP_MSVC && _STLP_MSVC <= 1300 && !_STLP_WCE && _MSC_EXTENSIONS
|
williamr@4
|
512 |
|
williamr@4
|
513 |
/* C++ Standard is unclear about several call to 'using ::func' if new overloads
|
williamr@4
|
514 |
* of ::func appears between 2 successive 'using' calls. To avoid this potential
|
williamr@4
|
515 |
* problem we provide all abs overload before the 'using' call.
|
williamr@4
|
516 |
* Beware: This header inclusion has to be after all abs overload of this file.
|
williamr@4
|
517 |
* The first 'using ::abs' call is going to be in the other header.
|
williamr@4
|
518 |
*/
|
williamr@4
|
519 |
#ifndef _STLP_INTERNAL_CSTDLIB
|
williamr@4
|
520 |
# include <stl/_cstdlib.h>
|
williamr@4
|
521 |
#endif
|
williamr@4
|
522 |
|
williamr@4
|
523 |
#if defined (_STLP_IMPORT_VENDOR_CSTD) && !defined (_STLP_NO_CSTD_FUNCTION_IMPORTS)
|
williamr@4
|
524 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
525 |
using ::abs;
|
williamr@4
|
526 |
using ::acos;
|
williamr@4
|
527 |
using ::asin;
|
williamr@4
|
528 |
using ::atan;
|
williamr@4
|
529 |
using ::atan2;
|
williamr@4
|
530 |
using ::ceil;
|
williamr@4
|
531 |
using ::cos;
|
williamr@4
|
532 |
using ::cosh;
|
williamr@4
|
533 |
using ::exp;
|
williamr@4
|
534 |
using ::fabs;
|
williamr@4
|
535 |
using ::floor;
|
williamr@4
|
536 |
using ::fmod;
|
williamr@4
|
537 |
using ::frexp;
|
williamr@4
|
538 |
using ::hypot;
|
williamr@4
|
539 |
using ::ldexp;
|
williamr@4
|
540 |
using ::log;
|
williamr@4
|
541 |
using ::log10;
|
williamr@4
|
542 |
using ::modf;
|
williamr@4
|
543 |
using ::pow;
|
williamr@4
|
544 |
using ::sin;
|
williamr@4
|
545 |
using ::sinh;
|
williamr@4
|
546 |
using ::sqrt;
|
williamr@4
|
547 |
using ::tan;
|
williamr@4
|
548 |
using ::tanh;
|
williamr@4
|
549 |
_STLP_END_NAMESPACE
|
williamr@4
|
550 |
# if defined (__BORLANDC__) && (__BORLANDC__ >= 0x560)
|
williamr@4
|
551 |
using _STLP_VENDOR_CSTD::_ecvt;
|
williamr@4
|
552 |
using _STLP_VENDOR_CSTD::_fcvt;
|
williamr@4
|
553 |
# endif
|
williamr@4
|
554 |
#endif
|
williamr@4
|
555 |
|
williamr@4
|
556 |
#endif /* _STLP_INTERNAL_CMATH */
|
williamr@4
|
557 |
|
williamr@4
|
558 |
// Local Variables:
|
williamr@4
|
559 |
// mode:C++
|
williamr@4
|
560 |
// End:
|