_cmath.h 22 KB

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