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