williamr@2: /* williamr@2: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. williamr@2: * williamr@2: * Copyright (c) 1999 williamr@2: * Boris Fomitchev williamr@2: * williamr@2: * This material is provided "as is", with absolutely no warranty expressed williamr@2: * or implied. Any use is at your own risk. williamr@2: * williamr@2: * Permission to use or copy this software for any purpose is hereby granted williamr@2: * without fee, provided the above notices are retained on all copies. williamr@2: * Permission to modify the code and to distribute modified code is granted, williamr@2: * provided the above notices are retained, and a notice that the code was williamr@2: * modified is included with the above copyright notice. williamr@2: * williamr@2: */ williamr@2: williamr@2: #ifndef _STLP_CMATH_H_HEADER williamr@2: # define _STLP_CMATH_H_HEADER williamr@2: williamr@2: # include williamr@2: williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: # if defined (_STLP_SAME_FUNCTION_NAME_RESOLUTION_BUG) && (! defined (_STLP_VXWORKS_TORNADO)) williamr@2: williamr@2: // this proxy is needed for some compilers to resolve problems williamr@2: // calling sqrt() from within sqrt(), etc. williamr@2: template williamr@2: struct _STL_math_proxy { williamr@2: static inline _Tp _do_abs(const _Tp& __x) { return _STLP_VENDOR_CSTD::fabs(__x); } williamr@2: static inline _Tp _do_acos(const _Tp& __x) { return _STLP_VENDOR_CSTD::acos(__x); } williamr@2: static inline _Tp _do_asin(const _Tp& __x) { return _STLP_VENDOR_CSTD::asin(__x); } williamr@2: static inline _Tp _do_atan(const _Tp& __x) { return _STLP_VENDOR_CSTD::atan(__x); } williamr@2: static inline _Tp _do_atan2(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::atan2(__x, __y); } williamr@2: static inline _Tp _do_cos(const _Tp& __x) { return _STLP_VENDOR_CSTD::cos(__x); } williamr@2: static inline _Tp _do_cosh(const _Tp& __x) { return _STLP_VENDOR_CSTD::cosh(__x); } williamr@2: static inline _Tp _do_floor(const _Tp& __x) { return _STLP_VENDOR_CSTD::floor(__x); } williamr@2: static inline _Tp _do_ceil(const _Tp& __x) { return _STLP_VENDOR_CSTD::ceil(__x); } williamr@2: static inline _Tp _do_fmod(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::fmod(__x, __y); } williamr@2: static inline _Tp _do_frexp(const _Tp& __x, int* __y) { return _STLP_VENDOR_CSTD::frexp(__x, __y); } williamr@2: static inline _Tp _do_ldexp(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::ldexp(__x, __y); } williamr@2: static inline _Tp _do_modf(const _Tp& __x, double* __y) { return _STLP_VENDOR_CSTD::modf(__x, __y); } williamr@2: static inline _Tp _do_log(const _Tp& __x) { return _STLP_VENDOR_CSTD::log(__x); } williamr@2: static inline _Tp _do_log10(const _Tp& __x) { return _STLP_VENDOR_CSTD::log10(__x); } williamr@2: static inline _Tp _do_pow(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); } williamr@2: static inline _Tp _do_pow(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); } williamr@2: static inline _Tp _do_sin(const _Tp& __x) { return _STLP_VENDOR_CSTD::sin(__x); } williamr@2: static inline _Tp _do_sinh(const _Tp& __x) { return _STLP_VENDOR_CSTD::sinh(__x); } williamr@2: williamr@2: static inline _Tp _do_sqrt(const _Tp& __x) { return _STLP_VENDOR_CSTD::sqrt(__x); } williamr@2: static inline _Tp _do_tan(const _Tp& __x) { return _STLP_VENDOR_CSTD::tan(__x); } williamr@2: static inline _Tp _do_tanh(const _Tp& __x) { return _STLP_VENDOR_CSTD::tanh(__x); } williamr@2: static inline _Tp _do_exp(const _Tp& __x) { return _STLP_VENDOR_CSTD::exp(__x); } williamr@2: static inline _Tp _do_hypot(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::hypot(__x, __y); } williamr@2: }; williamr@2: williamr@2: # define _STLP_DO_ABS(_Tp) _STL_math_proxy<_Tp>::_do_abs williamr@2: # define _STLP_DO_ACOS(_Tp) _STL_math_proxy<_Tp>::_do_acos williamr@2: # define _STLP_DO_ASIN(_Tp) _STL_math_proxy<_Tp>::_do_asin williamr@2: # define _STLP_DO_ATAN(_Tp) _STL_math_proxy<_Tp>::_do_atan williamr@2: # define _STLP_DO_ATAN2(_Tp) _STL_math_proxy<_Tp>::_do_atan2 williamr@2: # define _STLP_DO_COS(_Tp) _STL_math_proxy<_Tp>::_do_cos williamr@2: # define _STLP_DO_COSH(_Tp) _STL_math_proxy<_Tp>::_do_cosh williamr@2: # define _STLP_DO_FLOOR(_Tp) _STL_math_proxy<_Tp>::_do_floor williamr@2: # define _STLP_DO_CEIL(_Tp) _STL_math_proxy<_Tp>::_do_ceil williamr@2: # define _STLP_DO_FMOD(_Tp) _STL_math_proxy<_Tp>::_do_fmod williamr@2: # define _STLP_DO_FREXP(_Tp) _STL_math_proxy<_Tp>::_do_frexp williamr@2: # define _STLP_DO_LDEXP(_Tp) _STL_math_proxy<_Tp>::_do_ldexp williamr@2: # define _STLP_DO_MODF(_Tp) _STL_math_proxy<_Tp>::_do_modf williamr@2: # define _STLP_DO_LOG(_Tp) _STL_math_proxy<_Tp>::_do_log williamr@2: # define _STLP_DO_LOG10(_Tp) _STL_math_proxy<_Tp>::_do_log10 williamr@2: # define _STLP_DO_POW(_Tp) _STL_math_proxy<_Tp>::_do_pow williamr@2: # define _STLP_DO_SIN(_Tp) _STL_math_proxy<_Tp>::_do_sin williamr@2: # define _STLP_DO_SINH(_Tp) _STL_math_proxy<_Tp>::_do_sinh williamr@2: # define _STLP_DO_SQRT(_Tp) _STL_math_proxy<_Tp>::_do_sqrt williamr@2: # define _STLP_DO_TAN(_Tp) _STL_math_proxy<_Tp>::_do_tan williamr@2: # define _STLP_DO_TANH(_Tp) _STL_math_proxy<_Tp>::_do_tanh williamr@2: # define _STLP_DO_EXP(_Tp) _STL_math_proxy<_Tp>::_do_exp williamr@2: # define _STLP_DO_HYPOT(_Tp) _STL_math_proxy<_Tp>::_do_hypot williamr@2: # else williamr@2: # define _STLP_DO_ABS(_Tp) _STLP_VENDOR_CSTD::fabs williamr@2: # define _STLP_DO_ACOS(_Tp) _STLP_VENDOR_CSTD::acos williamr@2: # define _STLP_DO_ASIN(_Tp) _STLP_VENDOR_CSTD::asin williamr@2: # define _STLP_DO_ATAN(_Tp) _STLP_VENDOR_CSTD::atan williamr@2: # define _STLP_DO_ATAN2(_Tp) _STLP_VENDOR_CSTD::atan2 williamr@2: # define _STLP_DO_COS(_Tp) _STLP_VENDOR_CSTD::cos williamr@2: # define _STLP_DO_COSH(_Tp) _STLP_VENDOR_CSTD::cosh williamr@2: # define _STLP_DO_FLOOR(_Tp) _STLP_VENDOR_CSTD::floor williamr@2: # define _STLP_DO_CEIL(_Tp) _STLP_VENDOR_CSTD::ceil williamr@2: # define _STLP_DO_FMOD(_Tp) _STLP_VENDOR_CSTD::fmod williamr@2: # define _STLP_DO_FREXP(_Tp) _STLP_VENDOR_CSTD::frexp williamr@2: # define _STLP_DO_LDEXP(_Tp) _STLP_VENDOR_CSTD::ldexp williamr@2: # define _STLP_DO_MODF(_Tp) _STLP_VENDOR_CSTD::modf williamr@2: # define _STLP_DO_LOG(_Tp) _STLP_VENDOR_CSTD::log williamr@2: # define _STLP_DO_LOG10(_Tp) _STLP_VENDOR_CSTD::log10 williamr@2: # define _STLP_DO_POW(_Tp) _STLP_VENDOR_CSTD::pow williamr@2: # define _STLP_DO_SIN(_Tp) _STLP_VENDOR_CSTD::sin williamr@2: # define _STLP_DO_SINH(_Tp) _STLP_VENDOR_CSTD::sinh williamr@2: # define _STLP_DO_SQRT(_Tp) _STLP_VENDOR_CSTD::sqrt williamr@2: # define _STLP_DO_TAN(_Tp) _STLP_VENDOR_CSTD::tan williamr@2: # define _STLP_DO_TANH(_Tp) _STLP_VENDOR_CSTD::tanh williamr@2: # define _STLP_DO_EXP(_Tp) _STLP_VENDOR_CSTD::exp williamr@2: # define _STLP_DO_HYPOT(_Tp) ::hypot williamr@2: # endif williamr@2: williamr@2: _STLP_END_NAMESPACE williamr@2: williamr@2: # if (defined (_STLP_HAS_NO_NEW_C_HEADERS) || defined(_STLP_MSVC) || defined (__ICL)) && !defined (_STLP_HAS_NO_NAMESPACES) williamr@2: williamr@2: #if (! defined (_STLP_USE_NEW_C_HEADERS)) && ! defined (_STLP_VXWORKS_TORNADO) williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: # ifndef _STLP_HAS_NATIVE_FLOAT_ABS williamr@2: inline double abs(double __x) { return _STLP_DO_ABS(double)(__x); } williamr@2: inline float abs (float __x) { return _STLP_DO_ABS(float)(__x); } williamr@2: # endif williamr@2: williamr@2: #if ( defined (__SYMBIAN32__) || defined (__WINS__)) williamr@2: inline double pow(double __x, int __y) { return _STLP_DO_POW(double)(__x, __y); } williamr@2: inline float acos (float __x) { return _STLP_DO_ACOS(float)(__x); } williamr@2: inline float asin (float __x) { return _STLP_DO_ASIN(float)(__x); } williamr@2: inline float atan (float __x) { return _STLP_DO_ATAN(float)(__x); } williamr@2: inline float atan2(float __x, float __y) { return _STLP_DO_ATAN2(float)(__x, __y); } williamr@2: inline float ceil (float __x) { return _STLP_DO_CEIL(float)(__x); } williamr@2: inline float cos (float __x) { return _STLP_DO_COS(float)(__x); } williamr@2: inline float cosh (float __x) { return _STLP_DO_COSH(float)(__x); } williamr@2: inline float exp (float __x) { return _STLP_DO_EXP(float)(__x); } williamr@2: # ifdef _STLP_USE_NAMESPACES williamr@2: inline float fabs (float __x) { return _STLP_DO_ABS(float)(__x); } williamr@2: # endif williamr@2: inline float floor(float __x) { return _STLP_DO_FLOOR(float)(__x); } williamr@2: inline float fmod (float __x, float __y) { return _STLP_DO_FMOD(float)(__x, __y); } williamr@2: inline float frexp(float __x, int* __y) { return _STLP_DO_FREXP(float)(__x, __y); } williamr@2: inline float ldexp(float __x, int __y) { return _STLP_DO_LDEXP(float)(__x, __y); } williamr@2: // fbp : float versions are not always available williamr@2: #if !defined(_STLP_VENDOR_LONG_DOUBLE_MATH) //*ty 11/25/2001 - williamr@2: inline float modf (float __x, float* __y) { williamr@2: #ifndef __SYMBIAN32__ williamr@2: double __dd[2]; williamr@2: double __res = _STLP_DO_MODF(double)((double)__x, __dd); williamr@2: __y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1]; williamr@2: return (float)__res; williamr@2: #else williamr@2: float f = modff(__x, __y); williamr@2: return f; williamr@2: #endif williamr@2: } williamr@2: #else //*ty 11/25/2001 - i.e. for apple SCpp williamr@2: inline float modf (float __x, float* __y) { williamr@2: long double __dd[2]; williamr@2: long double __res = _STLP_DO_MODF(long double)((long double)__x, __dd); williamr@2: __y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1]; williamr@2: return (float)__res; williamr@2: } williamr@2: #endif //*ty 11/25/2001 - williamr@2: williamr@2: inline float log (float __x) { return _STLP_DO_LOG(float)(__x); } williamr@2: inline float log10(float __x) { return _STLP_DO_LOG10(float)(__x); } williamr@2: inline float pow (float __x, float __y) { return _STLP_DO_POW(float)(__x, __y); } williamr@2: inline float pow (float __x, int __y) { return _STLP_DO_POW(float)(__x, __y); } williamr@2: inline float sin (float __x) { return _STLP_DO_SIN(float)(__x); } williamr@2: inline float sinh (float __x) { return _STLP_DO_SINH(float)(__x); } williamr@2: inline float sqrt (float __x) { return _STLP_DO_SQRT(float)(__x); } williamr@2: inline float tan (float __x) { return _STLP_DO_TAN(float)(__x); } williamr@2: inline float tanh (float __x) { return _STLP_DO_TANH(float)(__x); } williamr@2: williamr@2: # if ! (defined (_STLP_NO_LONG_DOUBLE) || defined(_STLP_VENDOR_LONG_DOUBLE_MATH)) williamr@2: williamr@2: #if !( defined (__MVS__) || defined (_STLP_HAS_NATIVE_FLOAT_ABS)) williamr@2: inline long double abs (long double __x) { return _STLP_DO_ABS(long double)((double)__x); } williamr@2: #endif williamr@2: inline long double acos (long double __x) { return _STLP_DO_ACOS(long double)(__x); } williamr@2: inline long double asin (long double __x) { return _STLP_DO_ASIN(long double)(__x); } williamr@2: inline long double atan (long double __x) { return _STLP_DO_ATAN(long double)(__x); } williamr@2: inline long double atan2(long double __x, long double __y) { return _STLP_DO_ATAN2(long double)(__x, __y); } williamr@2: inline long double ceil (long double __x) { return _STLP_DO_CEIL(long double)(__x); } williamr@2: inline long double cos (long double __x) { return _STLP_DO_COS(long double)(__x); } williamr@2: inline long double cosh (long double __x) { return _STLP_DO_COSH(long double)(__x); } williamr@2: inline long double exp (long double __x) { return _STLP_DO_EXP(long double)(__x); } williamr@2: inline long double fabs (long double __x) { return _STLP_DO_ABS(long double)(__x); } williamr@2: inline long double floor(long double __x) { return _STLP_DO_FLOOR(long double)(__x); } williamr@2: inline long double fmod (long double __x, long double __y) { return _STLP_DO_FMOD(long double)(__x, __y); } williamr@2: inline long double frexp(long double __x, int* __y) { return _STLP_DO_FREXP(long double)(__x, __y); } williamr@2: inline long double ldexp(long double __x, int __y) { return _STLP_DO_LDEXP(long double)(__x, __y); } williamr@2: // fbp : long double versions are not available williamr@2: inline long double modf (long double __x, long double* __y) { williamr@2: double __dd[2]; williamr@2: double __res = _STLP_DO_MODF(double)((double)__x, __dd); williamr@2: __y[0] = (long double)__dd[0] ; __y[1] = (long double)__dd[1]; williamr@2: return (long double)__res; williamr@2: } williamr@2: inline long double log (long double __x) { return _STLP_DO_LOG(long double)(__x); } williamr@2: inline long double log10(long double __x) { return _STLP_DO_LOG10(long double)(__x); } williamr@2: inline long double pow (long double __x, long double __y) { return _STLP_DO_POW(long double)(__x, __y); } williamr@2: inline long double pow (long double __x, int __y) { return _STLP_DO_POW(long double)(__x, __y); } williamr@2: inline long double sin (long double __x) { return _STLP_DO_SIN(long double)(__x); } williamr@2: inline long double sinh (long double __x) { return _STLP_DO_SINH(long double)(__x); } williamr@2: inline long double sqrt (long double __x) { return _STLP_DO_SQRT(long double)(__x); } williamr@2: inline long double tan (long double __x) { return _STLP_DO_TAN(long double)(__x); } williamr@2: inline long double tanh (long double __x) { return _STLP_DO_TANH(long double)(__x); } williamr@2: #endif williamr@2: #endif williamr@2: williamr@2: _STLP_END_NAMESPACE williamr@2: williamr@2: # endif /* NEW_C_HEADERS */ williamr@2: # endif /* NEW_C_HEADERS */ williamr@2: williamr@2: #endif /* CMATH_H */