home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _cmath.h < prev    next >
C/C++ Source or Header  |  2002-01-18  |  12KB  |  209 lines

  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_CMATH_H_HEADER
  17. # define _STLP_CMATH_H_HEADER
  18.  
  19.  
  20.  
  21. _STLP_BEGIN_NAMESPACE
  22.  
  23. # ifdef _STLP_SAME_FUNCTION_NAME_RESOLUTION_BUG
  24.  
  25. // this proxy is needed for some compilers to resolve problems
  26. // calling sqrt() from within sqrt(), etc.
  27. template <class _Tp>
  28. struct _STL_math_proxy {
  29.   static inline _Tp _do_abs(const _Tp& __x)     { return _STLP_VENDOR_CSTD::fabs(__x); } 
  30.   static inline _Tp _do_acos(const _Tp& __x)    { return _STLP_VENDOR_CSTD::acos(__x); } 
  31.   static inline _Tp _do_asin(const _Tp& __x)    { return _STLP_VENDOR_CSTD::asin(__x); } 
  32.   static inline _Tp _do_atan(const _Tp& __x)    { return _STLP_VENDOR_CSTD::atan(__x); } 
  33.   static inline _Tp _do_atan2(const _Tp& __x, const _Tp& __y)  { return _STLP_VENDOR_CSTD::atan2(__x, __y); } 
  34.   static inline _Tp _do_cos(const _Tp& __x)     { return _STLP_VENDOR_CSTD::cos(__x); } 
  35.   static inline _Tp _do_cosh(const _Tp& __x)    { return _STLP_VENDOR_CSTD::cosh(__x); } 
  36.   static inline _Tp _do_floor(const _Tp& __x)    { return _STLP_VENDOR_CSTD::floor(__x); } 
  37.   static inline _Tp _do_ceil(const _Tp& __x)    { return _STLP_VENDOR_CSTD::ceil(__x); } 
  38.   static inline _Tp _do_fmod(const _Tp& __x, const _Tp& __y)    { return _STLP_VENDOR_CSTD::fmod(__x, __y); } 
  39.   static inline _Tp _do_frexp(const _Tp& __x, int* __y)    { return _STLP_VENDOR_CSTD::frexp(__x, __y); } 
  40.   static inline _Tp _do_ldexp(const _Tp& __x, int __y)    { return _STLP_VENDOR_CSTD::ldexp(__x, __y); } 
  41.   static inline _Tp _do_modf(const _Tp& __x, double* __y) { return _STLP_VENDOR_CSTD::modf(__x, __y); }
  42.   static inline _Tp _do_log(const _Tp& __x)     { return _STLP_VENDOR_CSTD::log(__x); } 
  43.   static inline _Tp _do_log10(const _Tp& __x)   { return _STLP_VENDOR_CSTD::log10(__x); } 
  44.   static inline _Tp _do_pow(const _Tp& __x, const _Tp& __y)    { return _STLP_VENDOR_CSTD::pow(__x, __y); } 
  45.   static inline _Tp _do_pow(const _Tp& __x, int __y)    { return _STLP_VENDOR_CSTD::pow(__x, __y); } 
  46.   static inline _Tp _do_sin(const _Tp& __x)     { return _STLP_VENDOR_CSTD::sin(__x); } 
  47.   static inline _Tp _do_sinh(const _Tp& __x)    { return _STLP_VENDOR_CSTD::sinh(__x); } 
  48.  
  49.   static inline _Tp _do_sqrt(const _Tp& __x)    { return _STLP_VENDOR_CSTD::sqrt(__x); } 
  50.   static inline _Tp _do_tan(const _Tp& __x)     { return _STLP_VENDOR_CSTD::tan(__x); } 
  51.   static inline _Tp _do_tanh(const _Tp& __x)    { return _STLP_VENDOR_CSTD::tanh(__x); } 
  52.   static inline _Tp _do_exp(const _Tp& __x)     { return _STLP_VENDOR_CSTD::exp(__x); } 
  53.   static inline _Tp _do_hypot(const _Tp& __x, const _Tp& __y)   { return _STLP_VENDOR_CSTD::hypot(__x, __y); } 
  54. };
  55.  
  56. #  define _STLP_DO_ABS(_Tp)   _STL_math_proxy<_Tp>::_do_abs
  57. #  define _STLP_DO_ACOS(_Tp)  _STL_math_proxy<_Tp>::_do_acos
  58. #  define _STLP_DO_ASIN(_Tp)  _STL_math_proxy<_Tp>::_do_asin
  59. #  define _STLP_DO_ATAN(_Tp)  _STL_math_proxy<_Tp>::_do_atan
  60. #  define _STLP_DO_ATAN2(_Tp) _STL_math_proxy<_Tp>::_do_atan2
  61. #  define _STLP_DO_COS(_Tp)   _STL_math_proxy<_Tp>::_do_cos
  62. #  define _STLP_DO_COSH(_Tp)  _STL_math_proxy<_Tp>::_do_cosh
  63. #  define _STLP_DO_FLOOR(_Tp) _STL_math_proxy<_Tp>::_do_floor
  64. #  define _STLP_DO_CEIL(_Tp) _STL_math_proxy<_Tp>::_do_ceil
  65. #  define _STLP_DO_FMOD(_Tp) _STL_math_proxy<_Tp>::_do_fmod
  66. #  define _STLP_DO_FREXP(_Tp) _STL_math_proxy<_Tp>::_do_frexp
  67. #  define _STLP_DO_LDEXP(_Tp) _STL_math_proxy<_Tp>::_do_ldexp
  68. #  define _STLP_DO_MODF(_Tp) _STL_math_proxy<_Tp>::_do_modf
  69. #  define _STLP_DO_LOG(_Tp)   _STL_math_proxy<_Tp>::_do_log
  70. #  define _STLP_DO_LOG10(_Tp) _STL_math_proxy<_Tp>::_do_log10
  71. #  define _STLP_DO_POW(_Tp)   _STL_math_proxy<_Tp>::_do_pow
  72. #  define _STLP_DO_SIN(_Tp)   _STL_math_proxy<_Tp>::_do_sin
  73. #  define _STLP_DO_SINH(_Tp)  _STL_math_proxy<_Tp>::_do_sinh
  74. #  define _STLP_DO_SQRT(_Tp)  _STL_math_proxy<_Tp>::_do_sqrt
  75. #  define _STLP_DO_TAN(_Tp)   _STL_math_proxy<_Tp>::_do_tan
  76. #  define _STLP_DO_TANH(_Tp)  _STL_math_proxy<_Tp>::_do_tanh
  77. #  define _STLP_DO_EXP(_Tp)   _STL_math_proxy<_Tp>::_do_exp
  78. #  define _STLP_DO_HYPOT(_Tp) _STL_math_proxy<_Tp>::_do_hypot
  79. # else
  80.  
  81. #  define _STLP_DO_ABS(_Tp)   _STLP_VENDOR_CSTD::fabs
  82. #  define _STLP_DO_ACOS(_Tp)  _STLP_VENDOR_CSTD::acos
  83. #  define _STLP_DO_ASIN(_Tp)  _STLP_VENDOR_CSTD::asin
  84. #  define _STLP_DO_ATAN(_Tp)  _STLP_VENDOR_CSTD::atan
  85. #  define _STLP_DO_ATAN2(_Tp) _STLP_VENDOR_CSTD::atan2
  86. #  define _STLP_DO_COS(_Tp)   _STLP_VENDOR_CSTD::cos
  87. #  define _STLP_DO_COSH(_Tp)  _STLP_VENDOR_CSTD::cosh
  88. #  define _STLP_DO_FLOOR(_Tp)  _STLP_VENDOR_CSTD::floor
  89. #  define _STLP_DO_CEIL(_Tp)   _STLP_VENDOR_CSTD::ceil
  90. #  define _STLP_DO_FMOD(_Tp)   _STLP_VENDOR_CSTD::fmod
  91. #  define _STLP_DO_FREXP(_Tp) _STLP_VENDOR_CSTD::frexp
  92. #  define _STLP_DO_LDEXP(_Tp) _STLP_VENDOR_CSTD::ldexp
  93. #  define _STLP_DO_MODF(_Tp) _STLP_VENDOR_CSTD::modf
  94. #  define _STLP_DO_LOG(_Tp)   _STLP_VENDOR_CSTD::log
  95. #  define _STLP_DO_LOG10(_Tp) _STLP_VENDOR_CSTD::log10
  96. #  define _STLP_DO_POW(_Tp)   _STLP_VENDOR_CSTD::pow
  97. #  define _STLP_DO_SIN(_Tp)   _STLP_VENDOR_CSTD::sin
  98. #  define _STLP_DO_SINH(_Tp)  _STLP_VENDOR_CSTD::sinh
  99. #  define _STLP_DO_SQRT(_Tp)  _STLP_VENDOR_CSTD::sqrt
  100. #  define _STLP_DO_TAN(_Tp)   _STLP_VENDOR_CSTD::tan
  101. #  define _STLP_DO_TANH(_Tp)  _STLP_VENDOR_CSTD::tanh
  102. #  define _STLP_DO_EXP(_Tp)   _STLP_VENDOR_CSTD::exp
  103. # if defined (__GNUC__) || defined ( __IBMCPP__ ) || defined (__SUNPRO_CC)
  104. #  define _STLP_DO_HYPOT(_Tp) ::hypot
  105. # else
  106. #  define _STLP_DO_HYPOT(_Tp) _STLP_VENDOR_CSTD::hypot
  107. # endif
  108.  
  109. # endif
  110.  
  111. _STLP_END_NAMESPACE
  112.  
  113. # if defined (_STLP_HAS_NO_NEW_C_HEADERS) || defined(_STLP_MSVC) || defined (__ICL)
  114.  
  115. #if ! defined (_STLP_USE_NEW_C_HEADERS) 
  116.  
  117. _STLP_BEGIN_NAMESPACE
  118.  
  119. #  ifndef _STLP_HAS_NATIVE_FLOAT_ABS
  120. inline double abs(double __x)                 { return _STLP_DO_ABS(double)(__x); }
  121. inline float abs (float __x)                  { return _STLP_DO_ABS(float)(__x); }
  122. #  endif
  123.  
  124. inline double pow(double __x, int __y)        { return _STLP_DO_POW(double)(__x, __y); }
  125. inline float acos (float __x)                 { return _STLP_DO_ACOS(float)(__x); }
  126. inline float asin (float __x)                 { return _STLP_DO_ASIN(float)(__x); }
  127. inline float atan (float __x)                 { return _STLP_DO_ATAN(float)(__x); }
  128. inline float atan2(float __x, float __y)      { return _STLP_DO_ATAN2(float)(__x, __y); }
  129. inline float ceil (float __x)                 { return _STLP_DO_CEIL(float)(__x); }
  130. inline float cos (float __x)                  { return _STLP_DO_COS(float)(__x); }
  131. inline float cosh (float __x)                 { return _STLP_DO_COSH(float)(__x); }
  132. inline float exp (float __x)                  { return _STLP_DO_EXP(float)(__x); }
  133. # ifdef _STLP_USE_NAMESPACES
  134. inline float fabs (float __x)                 { return _STLP_DO_ABS(float)(__x); }
  135. # endif
  136. inline float floor(float __x)                 { return _STLP_DO_FLOOR(float)(__x); }
  137. inline float fmod (float __x, float __y)      { return _STLP_DO_FMOD(float)(__x, __y); }
  138. inline float frexp(float __x, int* __y)       { return _STLP_DO_FREXP(float)(__x, __y); }
  139. inline float ldexp(float __x, int __y)        { return _STLP_DO_LDEXP(float)(__x, __y); }
  140. // fbp : float versions are not always available
  141. #if !defined(_STLP_VENDOR_LONG_DOUBLE_MATH)        //*ty 11/25/2001 - 
  142. inline float modf (float __x, float* __y)     { 
  143.   double __dd[2]; 
  144.   double __res = _STLP_DO_MODF(double)((double)__x, __dd); 
  145.   __y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1]; 
  146.   return (float)__res; 
  147. }
  148. #else        //*ty 11/25/2001 - i.e. for apple SCpp
  149. inline float modf (float __x, float* __y)     { 
  150.   long double __dd[2]; 
  151.   long double __res = _STLP_DO_MODF(long double)((long double)__x, __dd); 
  152.   __y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1]; 
  153.   return (float)__res; 
  154. }
  155. #endif        //*ty 11/25/2001 - 
  156.  
  157. inline float log (float __x)                  { return _STLP_DO_LOG(float)(__x); }
  158. inline float log10(float __x)                 { return _STLP_DO_LOG10(float)(__x); }
  159. inline float pow (float __x, float __y)       { return _STLP_DO_POW(float)(__x, __y); }
  160. inline float pow (float __x, int __y)         { return _STLP_DO_POW(float)(__x, __y); }
  161. inline float sin (float __x)                  { return _STLP_DO_SIN(float)(__x); }
  162. inline float sinh (float __x)                 { return _STLP_DO_SINH(float)(__x); }
  163. inline float sqrt (float __x)                 { return _STLP_DO_SQRT(float)(__x); }
  164. inline float tan (float __x)                  { return _STLP_DO_TAN(float)(__x); }
  165. inline float tanh (float __x)                 { return _STLP_DO_TANH(float)(__x); }
  166.  
  167. #  if ! (defined  (_STLP_NO_LONG_DOUBLE) || defined(_STLP_VENDOR_LONG_DOUBLE_MATH))
  168.  
  169. #if !defined (__MVS__)
  170. inline long double abs (long double __x)                  { return _STLP_DO_ABS(long double)((double)__x); }
  171. #endif
  172. inline long double acos (long double __x)                 { return _STLP_DO_ACOS(long double)(__x); }
  173. inline long double asin (long double __x)                 { return _STLP_DO_ASIN(long double)(__x); }
  174. inline long double atan (long double __x)                 { return _STLP_DO_ATAN(long double)(__x); }
  175. inline long double atan2(long double __x, long double __y)      { return _STLP_DO_ATAN2(long double)(__x, __y); }
  176. inline long double ceil (long double __x)                 { return _STLP_DO_CEIL(long double)(__x); }
  177. inline long double cos (long double __x)                  { return _STLP_DO_COS(long double)(__x); }
  178. inline long double cosh (long double __x)                 { return _STLP_DO_COSH(long double)(__x); }
  179. inline long double exp (long double __x)                  { return _STLP_DO_EXP(long double)(__x); }
  180. inline long double fabs (long double __x)                 { return _STLP_DO_ABS(long double)(__x); }
  181. inline long double floor(long double __x)                 { return _STLP_DO_FLOOR(long double)(__x); }
  182. inline long double fmod (long double __x, long double __y)      { return _STLP_DO_FMOD(long double)(__x, __y); }
  183. inline long double frexp(long double __x, int* __y)       { return _STLP_DO_FREXP(long double)(__x, __y); }
  184. inline long double ldexp(long double __x, int __y)        { return _STLP_DO_LDEXP(long double)(__x, __y); }
  185. // fbp : long double versions are not available
  186. inline long double modf (long double __x, long double* __y)     { 
  187.   double __dd[2]; 
  188.   double __res = _STLP_DO_MODF(double)((double)__x, __dd); 
  189.   __y[0] = (long double)__dd[0] ; __y[1] = (long double)__dd[1]; 
  190.   return (long double)__res; 
  191. }
  192. inline long double log (long double __x)                  { return _STLP_DO_LOG(long double)(__x); }
  193. inline long double log10(long double __x)                 { return _STLP_DO_LOG10(long double)(__x); }
  194. inline long double pow (long double __x, long double __y)       { return _STLP_DO_POW(long double)(__x, __y); }
  195. inline long double pow (long double __x, int __y)         { return _STLP_DO_POW(long double)(__x, __y); }
  196. inline long double sin (long double __x)                  { return _STLP_DO_SIN(long double)(__x); }
  197. inline long double sinh (long double __x)                 { return _STLP_DO_SINH(long double)(__x); }
  198. inline long double sqrt (long double __x)                 { return _STLP_DO_SQRT(long double)(__x); }
  199. inline long double tan (long double __x)                  { return _STLP_DO_TAN(long double)(__x); }
  200. inline long double tanh (long double __x)                 { return _STLP_DO_TANH(long double)(__x); }
  201. #  endif
  202.  
  203. _STLP_END_NAMESPACE
  204.  
  205. # endif /* NEW_C_HEADERS */
  206. # endif /* NEW_C_HEADERS */
  207.  
  208. #endif /* CMATH_H */
  209.