📄 _cmath.h
字号:
/* * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * */#ifndef _STLP_INTERNAL_CMATH#define _STLP_INTERNAL_CMATH/* gcc do not like when a using directive appear after a function * declaration. cmath have abs overloads and cstdlib a using directive * so cstdlib has to be included first. */#if defined (__GNUC__) && defined (_STLP_USE_NEW_C_HEADERS)# if defined (_STLP_HAS_INCLUDE_NEXT)# include_next <cstdlib># else# include _STLP_NATIVE_CPP_C_HEADER(cstdlib)# endif#endif#if defined (_STLP_USE_NEW_C_HEADERS)# if defined (_STLP_HAS_NO_NAMESPACES) && !defined (exception)# define exception __math_exception# endif# if defined (_STLP_HAS_INCLUDE_NEXT)# include_next <cmath># else# include _STLP_NATIVE_CPP_C_HEADER(cmath)# endif# if defined (_STLP_HAS_NO_NAMESPACES)# undef exception# endif#else# include <math.h>#endif#if (defined (__SUNPRO_CC) && (__SUNPRO_CC > 0x500)) || \ !(defined (__IBMCPP__) && (__IBMCPP__ >= 500) || !(defined(__HP_aCC) && (__HP_aCC >= 30000) ))# if !defined(_STLP_HAS_NO_NAMESPACES) && !defined(__SUNPRO_CC)// All the other hypot stuff is going to be at file scope, so follow along here.namespace std {# endifextern "C" double hypot(double x, double y);# if !defined(_STLP_HAS_NO_NAMESPACES) && !defined(__SUNPRO_CC)}# endif#endif#if defined (__sun) && defined (__GNUC__)extern "C" { float __cosf(float v); float __sinf(float v); float __atan2f(float, float); float __coshf(float v); float __sinhf(float v); float __sqrtf(float v); float __expf(float v); float __logf(float v); float __log10f(float v); long double __cosl(long double v); long double __sinl(long double v); long double __atan2l(long double, long double); long double __coshl(long double v); long double __sinhl(long double v); long double __sqrtl(long double v); long double __expl(long double v); long double __logl(long double v); long double __log10l(long double v);}extern "C" { inline float cosf(float v) { return __cosf(v); } inline float sinf(float v) { return __sinf(v); } inline float atan2f(float v1, float v2) { return __atan2f(v1,v2); } inline float coshf(float v) { return __coshf(v); } inline float sinhf(float v) { return __sinhf(v); } inline float sqrtf(float v) { return __sqrtf(v); } inline float expf(float v) { return __expf(v); } inline float logf(float v) { return __logf(v); } inline float log10f(float v) { return __log10f(v); } inline long double cosl(long double v) { return __cosl(v); } inline long double sinl(long double v) { return __sinl(v); } inline long double atan2l(long double v1, long double v2) { return __atan2l(v1,v2); } inline long double coshl(long double v) { return __coshl(v); } inline long double sinhl(long double v) { return __sinhl(v); } inline long double sqrtl(long double v) { return __sqrtl(v); } inline long double expl(long double v) { return __expl(v); } inline long double logl(long double v) { return __logl(v); } inline long double log10l(long double v) { return __log10l(v); }}#endif // __sun && __GNUC__#if defined (__sun)extern "C" {extern float __acosf(float);extern float __asinf(float);extern float __atanf(float);extern float __atan2f(float, float);extern float __ceilf(float);extern float __cosf(float);extern float __coshf(float);extern float __expf(float);extern float __fabsf(float);extern float __floorf(float);extern float __fmodf(float, float);extern float __frexpf(float, int *);extern float __ldexpf(float, int);extern float __logf(float);extern float __log10f(float);extern float __modff(float, float *);extern float __powf(float, float);extern float __sinf(float);extern float __sinhf(float);extern float __sqrtf(float);extern float __tanf(float);extern float __tanhf(float);extern long double __acosl(long double);extern long double __asinl(long double);extern long double __atanl(long double);extern long double __atan2l(long double, long double);extern long double __ceill(long double);extern long double __cosl(long double);extern long double __coshl(long double);extern long double __expl(long double);extern long double __fabsl(long double);extern long double __floorl(long double);extern long double __fmodl(long double, long double);extern long double __frexpl(long double, int *);extern long double __ldexpl(long double, int);extern long double __logl(long double);extern long double __log10l(long double);extern long double __modfl(long double, long double *);extern long double __powl(long double, long double);extern long double __sinl(long double);extern long double __sinhl(long double);extern long double __sqrtl(long double);extern long double __tanl(long double);extern long double __tanhl(long double);}#endif#if defined (__BORLANDC__)# define _STLP_CMATH_FUNC_NAMESPACE _STLP_VENDOR_CSTD#else# define _STLP_CMATH_FUNC_NAMESPACE#endif#if !defined (__sun) || defined (__GNUC__)# define _STLP_MATH_INLINE(float_type, func, cfunc) \ inline float_type func (float_type x) { return _STLP_CMATH_FUNC_NAMESPACE::cfunc(x); }# define _STLP_MATH_INLINE2(float_type, type, func, cfunc) \ inline float_type func (float_type x, type y) { return _STLP_CMATH_FUNC_NAMESPACE::cfunc(x, y); }# define _STLP_MATH_INLINE_D(float_type, func, cfunc)# define _STLP_MATH_INLINE2_D(float_type, type, func, cfunc)#else# ifdef __SUNPRO_CC# define _STLP_MATH_INLINE(float_type, func, cfunc) \ inline float_type func (float_type x) { return _STLP_VENDOR_CSTD::__##cfunc(x); }# define _STLP_MATH_INLINE_D(float_type, func, cfunc) \ inline float_type func (float_type x) { return _STLP_VENDOR_CSTD::cfunc(x); }# define _STLP_MATH_INLINE2(float_type, type, func, cfunc) \ inline float_type func (float_type x, type y) { return _STLP_VENDOR_CSTD::__##cfunc(x,y); }# define _STLP_MATH_INLINE2_D(float_type, type, func, cfunc) \ inline float_type func (float_type x, type y) { return _STLP_VENDOR_CSTD::cfunc(x,y); }# else# error Unknown compiler for the Sun platform# endif#endif/** macros to define math functionsThese macros (having an X somewhere in the name) forward to the C library'sdouble functions but cast the arguments and return values to the given type. */#define _STLP_MATH_INLINEX(__type,func,cfunc) \ inline __type func (__type x) \ { return __STATIC_CAST(__type, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x)); }#define _STLP_MATH_INLINE2X(__type1,__type2,func,cfunc) \ inline __type1 func (__type1 x, __type2 y) \ { return __STATIC_CAST(__type1, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x, y)); }#define _STLP_MATH_INLINE2PX(__type,func,cfunc) \ inline __type func (__type x, __type *y) { \ double tmp1, tmp2; \ tmp1 = _STLP_CMATH_FUNC_NAMESPACE::cfunc(__STATIC_CAST(double, x), &tmp2); \ *y = __STATIC_CAST(__type, tmp2); \ return __STATIC_CAST(__type, tmp1); \ }#define _STLP_MATH_INLINE2XX(__type,func,cfunc) \ inline __type func (__type x, __type y) \ { return __STATIC_CAST(__type, _STLP_CMATH_FUNC_NAMESPACE::cfunc((double)x, (double)y)); }/** rough characterization of compiler and native C libraryFor the compiler, it can either support long double or not. If it doesn't, themacro _STLP_NO_LONG_DOUBLE is not defined and we don't define any long doubleoverloads.For the native C library the question is whether it has variants with an 'f'suffix (for float as opposed to double) or an 'l' suffix (for long double). Ifthe float variants are missing, _STLP_NO_VENDOR_MATH_F is defined, when thelong double variants are missing, _STLP_NO_VENDOR_MATH_L is defined. Of coursethe latter doesn't make sense anyway when the compiler already has no longdouble support.Those two traits determine a) which overloads get defined and b) how they aredefined.Meaning of suffixes:"" : function returning and taking a float_type"2" : function returning a float_type and taking to float_types"2P" : function returning a float_type and taking a float_type and a float_type*"2PI": function returning a float_type and taking a float_type and an int*"2I" : function returning a float_type and taking a float_Type and an int*/#if !defined (_STLP_NO_LONG_DOUBLE) && !defined (_STLP_NO_VENDOR_MATH_L) && !defined (_STLP_NO_VENDOR_MATH_F) // long double support and both e.g. sinl(long double) and sinf(float) // This is the default for a correct and complete native library.# define _STLP_DEF_MATH_INLINE(func,cf) \ _STLP_MATH_INLINE(float,func,cf##f) \ _STLP_MATH_INLINE_D(double,func,cf) \ _STLP_MATH_INLINE(long double,func,cf##l)# define _STLP_DEF_MATH_INLINE2(func,cf) \ _STLP_MATH_INLINE2(float,float,func,cf##f) \ _STLP_MATH_INLINE2_D(double,double,func,cf) \ _STLP_MATH_INLINE2(long double,long double,func,cf##l)# define _STLP_DEF_MATH_INLINE2P(func,cf) \ _STLP_MATH_INLINE2(float,float *,func,cf##f) \ _STLP_MATH_INLINE2_D(double,double *,func,cf) \ _STLP_MATH_INLINE2(long double,long double *,func,cf##l)# define _STLP_DEF_MATH_INLINE2PI(func,cf) \ _STLP_MATH_INLINE2(float,int *,func,cf##f) \ _STLP_MATH_INLINE2_D(double,int *,func,cf) \ _STLP_MATH_INLINE2(long double,int *,func,cf##l)# define _STLP_DEF_MATH_INLINE2I(func,cf) \ _STLP_MATH_INLINE2(float,int,func,cf##f) \ _STLP_MATH_INLINE2_D(double,int,func,cf) \ _STLP_MATH_INLINE2(long double,int,func,cf##l)#else# if !defined (_STLP_NO_LONG_DOUBLE)# if !defined (_STLP_NO_VENDOR_MATH_F) // long double support and e.g. sinf(float) but not e.g. sinl(long double)# define _STLP_DEF_MATH_INLINE(func,cf) \ _STLP_MATH_INLINE(float,func,cf##f) \ _STLP_MATH_INLINEX(long double,func,cf)# define _STLP_DEF_MATH_INLINE2(func,cf) \ _STLP_MATH_INLINE2(float,float,func,cf##f) \ _STLP_MATH_INLINE2XX(long double,func,cf)# define _STLP_DEF_MATH_INLINE2P(func,cf) \ _STLP_MATH_INLINE2(float,float *,func,cf##f) \ _STLP_MATH_INLINE2PX(long double,func,cf)# define _STLP_DEF_MATH_INLINE2PI(func,cf) \ _STLP_MATH_INLINE2(float,int *,func,cf##f) \ _STLP_MATH_INLINE2X(long double,int *,func,cf)# define _STLP_DEF_MATH_INLINE2I(func,cf) \ _STLP_MATH_INLINE2(float,int,func,cf##f) \ _STLP_MATH_INLINE2X(long double,int,func,cf)# elif !defined (_STLP_NO_VENDOR_MATH_L) // long double support and e.g. sinl(long double) but not e.g. sinf(float)# define _STLP_DEF_MATH_INLINE(func,cf) \ _STLP_MATH_INLINEX(float,func,cf) \ _STLP_MATH_INLINE(long double,func,cf##l)# define _STLP_DEF_MATH_INLINE2(func,cf) \ _STLP_MATH_INLINE2XX(float,func,cf) \ _STLP_MATH_INLINE2(long double,long double,func,cf##l)# define _STLP_DEF_MATH_INLINE2P(func,cf) \ _STLP_MATH_INLINE2PX(float,func,cf) \ _STLP_MATH_INLINE2(long double,long double *,func,cf##l)# define _STLP_DEF_MATH_INLINE2PI(func,cf) \ _STLP_MATH_INLINE2X(float,int *,func,cf) \ _STLP_MATH_INLINE2(long double,int *,func,cf##l)# define _STLP_DEF_MATH_INLINE2I(func,cf) \ _STLP_MATH_INLINE2X(float,int,func,cf) \ _STLP_MATH_INLINE2(long double,int,func,cf##l)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -