⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genmathfunc.cpp

📁 A C++ class library for scientific computing
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iostream>#include <string>#include <fstream> #include <iomanip>using namespace std;// abs(i), labs(l)                     Absolute value// acos(d), acosl(ld)                  Inverse cosine// acosh(d)                            Inverse hyperbolic cosine// asin(d), asinl(ld)                  Inverse sine// asinh(d)                            Inverse hyperbolic sine// atan(d), atanl(ld)                  Inverse tangent// atan2(d,d), atan2l(ld,ld)           Inverse tangent// atanh(d)                            Inverse hyperbolic tangent// _class(d)                           Classification of floating-point values// cbrt(x)                             Cube root// ceil(d), ceill(ld)                  Smallest f-int not less than x// cos(d), cosl(ld)                    Cosine// cosh(d), coshl(ld)                  Hyperbolic cosine// copysign(d,d)                       Return 1st arg with same sign as 2nd// drem(x,x)                           IEEE remainder// exp(d), expl(ld)                    Exponential// expm1(d)                            Exp(x)-1     // erf(d), erfl(ld)                    Error function// erfc(d), erfcl(ld)                  Complementary error function// fabs(d), fabsl(ld)                  Floating point absolute value// int finite(d)                       Nonzero if finite// floor(d), floor(ld)                 Largest f-int not greater than x// fmod(d,d), fmodl(ld,ld)             Floating point remainder// frexp(d, int* e)                    Break into mantissa/exponent  (*)// frexpl(ld, int* e)                  Break into mantissa/exponent  (*)// gammaFunc(d)                        Gamma function (** needs special //                                     implementation using lgamma)// hypot(d,d)                          Hypotenuse: sqrt(x*x+y*y)// int ilogb(d)                        Integer unbiased exponent// int isnan(d)                        Nonzero if NaNS or NaNQ// int itrunc(d)                       Truncate and convert to integer// j0(d)                               Bessel function first kind, order 0// j1(d)                               Bessel function first kind, order 1// jn(int, double)                     Bessel function first kind, order i// ldexp(d,i), ldexpl(ld,i)            Compute d * 2^i// lgamma(d), lgammal(ld)              Log absolute gamma// log(d), logl(ld)                    Natural logarithm// logb(d)                             Unbiased exponent (IEEE)// log1p(d)                            Compute log(1 + x)// log10(d), log10l(ld)                Logarithm base 10// modf(d, int* i), modfl(ld, int* i)  Break into integral/fractional part// double nearest(double)              Nearest floating point integer// nextafter(d, d)                     Next representable neighbor of 1st//                                     in direction of 2nd// pow(d,d), powl(ld,ld)               Computes x ^ y// d remainder(d,d)                    IEEE remainder// d rint(d)                           Round to f-integer (depends on mode)// d rsqrt(d)                          Reciprocal square root// d scalb(d,d)                        Return x * (2^y)// sin(d), sinl(ld)                    Sine // sinh(d), sinhl(ld)                  Hyperbolic sine// sqr(x)                              Return x * x// sqrt(d), sqrtl(ld)                  Square root// tan(d), tanl(ld)                    Tangent// tanh(d), tanhl(ld)                  Hyperbolic tangent// trunc(d)                            Nearest f-int in the direction of 0// unsigned uitrunc(d)                 Truncate and convert to unsigned// int unordered(d,d)                  Nonzero if comparison is unordered// y0(d)                               Bessel function 2nd kind, order 0// y1(d)                               Bessel function 2nd kind, order 1// yn(i,d)                             Bessel function 2nd kind, order dofstream ofs;const int ldflag = 1;const int cflag = 2;const int ieeeflag = 3;const int bsdflag = 4;const int cflag1 = 5;const int cflag2 = 6;const int nofuncflag = 7;void one(const char* applicName, const char* specialization, const char* funcName,    const char* returnType, const char* comment, int flag=0, int noCastFlag=0){    if (specialization != 0 && !strlen(specialization))        specialization = 0;    if (returnType != 0 && !strlen(returnType))        returnType = 0;    if (comment != 0 && !strlen(comment))        comment = 0;    ofs << "// " << applicName << "(";    if (specialization)        ofs << specialization;    else        ofs << "P_numtype1";    ofs << ")";    if (comment)        ofs << "    " << comment;    ofs << std::endl;    if (flag == cflag)        ofs << "#ifdef BZ_HAVE_COMPLEX_FCNS" << std::endl;    else if (flag == cflag1)        ofs << "#ifdef BZ_HAVE_COMPLEX_MATH1" << std::endl;    else if (flag == cflag2)        ofs << "#ifdef BZ_HAVE_COMPLEX_MATH2" << std::endl;    else if (flag == ieeeflag)        ofs << "#ifdef BZ_HAVE_IEEE_MATH" << std::endl;    else if (flag == bsdflag)        ofs << "#ifdef BZ_HAVE_SYSTEM_V_MATH" << std::endl;//    else if (flag == ldflag)//        ofs << "#ifdef BZ_LONGDOUBLE128" << std::endl;    if (!specialization)    {        ofs << "template<typename P_numtype1>" << std::endl;    }    else {        ofs << "template<>" << std::endl;    }    ofs << "class _bz_" << applicName;         if (specialization)        ofs << "<" << specialization << ">";    ofs << " : public OneOperandApplicativeTemplatesBase {" << std::endl;    ofs << "public:" << std::endl;    ofs << "    typedef ";    if (specialization)        ofs << specialization;    else         ofs << "P_numtype1";    ofs << " T_numtype1;" << std::endl;    ofs << "    typedef ";    if (returnType)        ofs << returnType;    else if (specialization)        ofs << specialization;    else        ofs << "P_numtype1";    ofs << " T_numtype;" << std::endl;    if (strcmp(applicName,"blitz_isnan") == 0) // Special case nan    {        ofs << std::endl << "    static inline T_numtype apply(T_numtype1 x)"            << std::endl << "    {" << std::endl;        ofs << "#ifdef isnan" << std::endl;        ofs << "        "            << "// Some platforms define isnan as a macro, which causes the"            << std::endl << "        "            << "// BZ_IEEEMATHFN_SCOPE macro to break." << std::endl;        ofs << "        return isnan(x);" << std::endl;        ofs << "#else" << std::endl;        ofs << "        return BZ_IEEEMATHFN_SCOPE(isnan)(x);" << std::endl;        ofs << "#endif" << std::endl << "    }" << std::endl;    }    else     {        ofs << std::endl << "    static inline T_numtype apply(T_numtype1 x)"            << std::endl << "    { return ";        if (noCastFlag == nofuncflag)        {            ofs << funcName;        }        else {        if ((flag == cflag) || (flag == cflag1) || (flag == cflag2))            ofs << "BZ_CMATHFN_SCOPE(";        else if ((flag == ieeeflag) || (flag == bsdflag))            ofs << "BZ_IEEEMATHFN_SCOPE(";        else             ofs << "BZ_MATHFN_SCOPE(";            ofs << funcName << ")(";        if (specialization != 0)            ofs << "(" << specialization << ")";        else if ((returnType)&&(!noCastFlag))            ofs << "(" << returnType << ")";        ofs << "x)";        }        ofs << "; }" << std::endl;    }    ofs << std::endl << "    template<typename T1>" << std::endl        << "    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,"        << std::endl        << "        const T1& a)" << std::endl        << "    {" << std::endl        << "        str += \"" << funcName;      ofs  << "(\";" << std::endl        << "        a.prettyPrint(str,format);" << std::endl        << "        str += \")\";" << std::endl        << "    }" << std::endl        << "};" << std::endl;   if ((flag != ldflag) && (flag != 0))        ofs << "#endif" << std::endl;    ofs << std::endl;}void two(const char* applicName, const char* specialization, const char* funcName,    const char* returnType, const char* comment, int flag=0, int noCastFlag=0){    if (specialization != 0 && !strlen(specialization))        specialization = 0;    if (returnType != 0 && !strlen(returnType))        returnType = 0;    if (comment != 0 && !strlen(comment))        comment = 0;    ofs << "// " << applicName << "(";    if (specialization)        ofs << specialization << ", " << specialization;    else        ofs << "P_numtype1, P_numtype2";    ofs << ")";    if (comment)        ofs << "    " << comment;    ofs << std::endl;    if (flag == cflag)        ofs << "#ifdef BZ_HAVE_COMPLEX_FCNS" << std::endl;    else if (flag == cflag1)        ofs << "#ifdef BZ_HAVE_COMPLEX_MATH1" << std::endl;    else if (flag == cflag2)        ofs << "#ifdef BZ_HAVE_COMPLEX_MATH2" << std::endl;    else if (flag == ieeeflag)        ofs << "#ifdef BZ_HAVE_IEEE_MATH" << std::endl;    else if (flag == bsdflag)        ofs << "#ifdef BZ_HAVE_SYSTEM_V_MATH" << std::endl;//    else if (flag == ldflag)//        ofs << "#ifdef BZ_LONGDOUBLE128" << std::endl;    if (!specialization)    {        ofs << "template<typename P_numtype1, typename P_numtype2>" << std::endl;    }    else {        ofs << "template<>" << std::endl;    }    ofs << "class _bz_" << applicName;    if (specialization)        ofs << "<" << specialization  << ", " << specialization << " >";    ofs << " : public TwoOperandApplicativeTemplatesBase {" << std::endl;    ofs << "public:" << std::endl;    ofs << "    typedef ";    if (specialization)        ofs << specialization;    else        ofs << "P_numtype1";    ofs << " T_numtype1;" << std::endl;    ofs << "    typedef ";    if (specialization)        ofs << specialization;    else        ofs << "P_numtype2";    ofs << " T_numtype2;" << std::endl;    ofs << "    typedef ";    if (returnType)        ofs << returnType;    else if (specialization)        ofs << specialization;    else        ofs << "BZ_PROMOTE(T_numtype1, T_numtype2)";    ofs << " T_numtype;" << std::endl;    ofs << std::endl << "    static inline T_numtype apply(T_numtype1 x, T_numtype2 y)"        << std::endl << "    { return ";    if ((flag == cflag) || (flag == cflag1) || (flag == cflag2))        ofs << "BZ_CMATHFN_SCOPE(";    else if ((flag == ieeeflag) || (flag == bsdflag))        ofs << "BZ_IEEEMATHFN_SCOPE(";    else        ofs << "BZ_MATHFN_SCOPE(";    ofs << funcName << ")(";    if (specialization != 0)        ofs << "(" << specialization << ")";    else if ((returnType) && (!noCastFlag))        ofs << "(" << returnType << ")";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -