📄 funcs.h
字号:
str += ","; \ t2.prettyPrint(str, format); \ str += ")"; \ } \}; \ \template<typename T> \struct name< complex<T>, T > { \ typedef complex<T> T_numtype1; \ typedef T T_numtype2; \ typedef complex<T> T_numtype; \ \ static inline T_numtype \ apply(T_numtype1 a, T_numtype2 b) \ { return fun(a,b); } \ \ template<typename T1, typename T2> \ static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \ prettyPrintFormat& format, const T1& t1, \ const T2& t2) \ { \ str += #fun; \ str += "("; \ t1.prettyPrint(str, format); \ str += ","; \ t2.prettyPrint(str, format); \ str += ")"; \ } \}; \ \template<typename T> \struct name< T, complex<T> > { \ typedef T T_numtype1; \ typedef complex<T> T_numtype2; \ typedef complex<T> T_numtype; \ \ static inline T_numtype \ apply(T_numtype1 a, T_numtype2 b) \ { return fun(a,b); } \ \ template<typename T1, typename T2> \ static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \ prettyPrintFormat& format, const T1& t1, \ const T2& t2) \ { \ str += #fun; \ str += "("; \ t1.prettyPrint(str, format); \ str += ","; \ t2.prettyPrint(str, format); \ str += ")"; \ } \};#ifdef BZ_HAVE_COMPLEX_MATH1BZ_DEFINE_BINARY_CFUNC(Fn_pow,BZ_CMATHFN_SCOPE(pow))#endif/* Binary functions that apply only to T and return complex<T> */ #define BZ_DEFINE_BINARY_FUNC_CRET(name,fun) \template<typename T_numtype1, typename T_numtype2> \struct name; \ \template<typename T> \struct name<T, T> { \ typedef T T_numtype1; \ typedef T T_numtype2; \ typedef complex<T> T_numtype; \ \ static inline T_numtype \ apply(T_numtype1 a, T_numtype2 b) \ { return fun(a,b); } \ \ template<typename T1, typename T2> \ static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \ prettyPrintFormat& format, const T1& t1, \ const T2& t2) \ { \ str += #fun; \ str += "("; \ t1.prettyPrint(str, format); \ str += ","; \ t2.prettyPrint(str, format); \ str += ")"; \ } \};#ifdef BZ_HAVE_COMPLEX_FCNSBZ_DEFINE_BINARY_FUNC_CRET(Fn_polar,BZ_CMATHFN_SCOPE(polar))#endif #endif // BZ_HAVE_COMPLEX /* Ternary functions that return type based on type promotion */ #define BZ_DEFINE_TERNARY_FUNC(name,fun) \template <typename P_numtype1, typename P_numtype2, \ typename P_numtype3> \struct name { \ typedef BZ_PROMOTE(P_numtype1, \ BZ_PROMOTE(P_numtype2,P_numtype3)) T_numtype; \ \ static inline T_numtype \ apply(P_numtype1 x, P_numtype2 y, P_numtype3 z) \ { return fun(x,y,z); } \ \ template <typename T1, typename T2, typename T3> \ static void prettyPrint(BZ_STD_SCOPE(string) &str, \ prettyPrintFormat& format, \ const T1& a,const T2& b, const T3& c) \ { \ str += #fun; \ str += "("; \ a.prettyPrint(str,format); \ str += ","; \ b.prettyPrint(str,format); \ str += ","; \ c.prettyPrint(str,format); \ str += ")"; \ } \};/* Ternary functions that return a specified type */ #define BZ_DEFINE_TERNARY_FUNC_RET(name,fun,ret) \template <typename P_numtype1, typename P_numtype2, \ typename P_numtype3> \struct name { \ typedef ret T_numtype; \ \ static inline T_numtype \ apply(P_numtype1 x, P_numtype2 y, P_numtype3 z) \ { return fun(x,y,z); } \ \ template <typename T1, typename T2, typename T3> \ static void prettyPrint(BZ_STD_SCOPE(string) &str, \ prettyPrintFormat& format, \ const T1& a,const T2& b, const T3& c) \ { \ str += #fun; \ str += "("; \ a.prettyPrint(str,format); \ str += ","; \ b.prettyPrint(str,format); \ str += ","; \ c.prettyPrint(str,format); \ str += ")"; \ } \}; /* These functions don't quite fit the usual patterns */ // abs() Absolute valuetemplate<typename T_numtype1>struct Fn_abs;// abs(int)template<>struct Fn_abs< int > { typedef int T_numtype1; typedef int T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_MATHFN_SCOPE(abs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};// abs(long)template<>struct Fn_abs< long int > { typedef long int T_numtype1; typedef long int T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_MATHFN_SCOPE(labs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};// abs(float)template<>struct Fn_abs< float > { typedef float T_numtype1; typedef float T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_MATHFN_SCOPE(fabs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};// abs(double)template<>struct Fn_abs< double > { typedef double T_numtype1; typedef double T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_MATHFN_SCOPE(fabs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};// abs(long double)template<>struct Fn_abs< long double > { typedef long double T_numtype1; typedef long double T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_MATHFN_SCOPE(fabs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};#ifdef BZ_HAVE_COMPLEX_FCNS// abs(complex<T>)template<typename T>struct Fn_abs< complex<T> > { typedef complex<T> T_numtype1; typedef T T_numtype; static inline T_numtype apply(T_numtype1 a) { return BZ_CMATHFN_SCOPE(abs)(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "abs"; str += "("; t1.prettyPrint(str, format); str += ")"; }};#endif // BZ_HAVE_COMPLEX_FCNS#ifdef BZ_HAVE_IEEE_MATH// isnan() Nonzero if NaNS or NaNQtemplate<typename T_numtype1>struct Fn_isnan { typedef int T_numtype; static inline T_numtype apply(T_numtype1 a) {#ifdef BZ_ISNAN_IN_NAMESPACE_STD return BZ_STD_SCOPE(isnan)(a);#else return BZ_IEEEMATHFN_SCOPE(isnan)(a);#endif } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += "isnan"; str += "("; t1.prettyPrint(str, format); str += ")"; }};#endif // BZ_HAVE_IEEE_MATH// Blitz cast() functiontemplate<typename T_numtype1, typename T_cast>struct Cast { typedef T_cast T_numtype; static inline T_numtype apply(T_numtype1 a) { return T_numtype(a); } template<typename T1> static inline void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format, const T1& t1) { str += BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_cast); str += "("; t1.prettyPrint(str, format); str += ")"; }};BZ_NAMESPACE_END#endif // BZ_FUNCS_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -