📄 funcs.h
字号:
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_CFUNC2(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_CFUNC2(Fn_polar,BZ_CMATHFN_SCOPE(polar))#endif #endif // BZ_HAVE_COMPLEX /* Binary functions that return a specified type */ #define BZ_DEFINE_BINARY_FUNC_RET(name,fun,ret) \template<typename T_numtype1, typename T_numtype2> \struct name { \ typedef ret 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_SYSTEM_V_MATHBZ_DEFINE_BINARY_FUNC_RET(Fn_unordered,BZ_IEEEMATHFN_SCOPE(unordered),int)#endif /* 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 isnan // Some platforms define isnan as a macro, which causes the // BZ_IEEEMATHFN_SCOPE macro to break. return 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 + -