00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _MATHEXPR_H
00023 #define _MATHEXPR_H
00024
00025 #include<string.h>
00026 #include<stdio.h>
00027 #include<stdlib.h>
00028 #include<math.h>
00029 #include<float.h>
00030
00031
00032 #define atanl atan
00033 #define asinl asin
00034 #define acosl acos
00035 #define expl exp
00036 #define logl log
00037 #define powl pow
00038 #define pow10l(x) pow(10,x)
00039 #define fabsl fabs
00040 #define cosl cos
00041 #define sinl sin
00042 #define tanl tan
00043 #define fmodl fmod
00044 #define sqrtl sqrt
00045
00046
00047
00048
00049
00050 const float ErrVal=DBL_MAX;
00051
00052
00053
00054 class RVar{
00055 public:
00056 char*name;float*pval;
00057 RVar(){name=NULL;pval=NULL;};
00058 RVar(const RVar&);
00059 RVar(const char*,float*);
00060 ~RVar();
00061 friend int operator==(const RVar&,const RVar&);
00062 };
00063 typedef RVar* PRVar;
00064
00065 enum ROperator{ErrOp,Juxt,Num,Var,Add,Sub,Opp,Mult,Div,Pow,Sqrt,
00066 NthRoot,Abs,Sin,Cos,Tg,Ln,Exp,Acos,Asin,Atan,E10,Fun};
00067
00068 typedef void ((*pfoncld)(float*&));
00069
00070 class ROperation;
00071 typedef ROperation* PROperation;
00072 class RFunction;
00073 typedef RFunction* PRFunction;
00074
00075 class ROperation{
00076 pfoncld*pinstr;float**pvals;float*ppile;RFunction**pfuncpile;
00077 mutable signed char containfuncflag;
00078 void BuildCode();
00079 void Destroy();
00080 public:
00081 ROperator op;
00082 PROperation mmb1,mmb2;
00083 float ValC;const RVar* pvar;float*pvarval;
00084 RFunction* pfunc;
00085 ROperation();
00086 ROperation(const ROperation&);
00087 ROperation(float);
00088 ROperation(const RVar&);
00089 ROperation(char const*sp,int nvarp=0,PRVar*ppvarp=NULL,int nfuncp=0,PRFunction*ppfuncp=NULL);
00090 ~ROperation();
00091 float Val() const;
00092 signed char ContainVar(const RVar&) const;
00093 signed char ContainFunc(const RFunction&) const;
00094 signed char ContainFuncNoRec(const RFunction&) const;
00095 ROperation NthMember(int) const;int NMembers() const;
00096 signed char HasError(const ROperation* =NULL) const;
00097 ROperation& operator=(const ROperation&);
00098 friend int operator==(const ROperation& ,const float);
00099 friend int operator==(const ROperation& ,const ROperation&);
00100 friend int operator!=(const ROperation& ,const ROperation&);
00101 ROperation operator+() const;ROperation operator-() const;
00102 friend ROperation operator,(const ROperation&,const ROperation&);
00103 friend ROperation operator+(const ROperation&,const ROperation&);
00104 friend ROperation operator-(const ROperation&,const ROperation&);
00105 friend ROperation operator*(const ROperation&,const ROperation&);
00106 friend ROperation operator/(const ROperation&,const ROperation&);
00107 friend ROperation operator^(const ROperation&,const ROperation&);
00108 friend ROperation sqrt(const ROperation&);
00109 friend ROperation abs(const ROperation&);
00110 friend ROperation sin(const ROperation&);
00111 friend ROperation cos(const ROperation&);
00112 friend ROperation tan(const ROperation&);
00113 friend ROperation log(const ROperation&);
00114 friend ROperation exp(const ROperation&);
00115 friend ROperation acos(const ROperation&);
00116 friend ROperation asin(const ROperation&);
00117 friend ROperation atan(const ROperation&);
00118 friend ROperation ApplyOperator(int,ROperation**,ROperation (*)(const ROperation&,const ROperation&));
00119 ROperation Diff(const RVar&) const;
00120 char* Expr() const;
00121 ROperation Substitute(const RVar&,const ROperation&) const;
00122 };
00123
00124 class RFunction{
00125 float*buf;
00126 public:
00127 signed char type;
00128 float ((*pfuncval)(float));
00129 ROperation op;int nvars;RVar** ppvar;
00130 char*name;
00131 RFunction();
00132 RFunction(float ((*)(float)));
00133 RFunction(const ROperation& opp,RVar* pvarp);
00134 RFunction(const ROperation& opp,int nvarsp,RVar**ppvarp);
00135 RFunction(const RFunction&);
00136 ~RFunction();
00137 RFunction& operator=(const RFunction&);
00138 void SetName(const char*s);
00139 float Val(float) const;
00140 float Val(float*) const;
00141 friend int operator==(const RFunction&,const RFunction&);
00142 ROperation operator()(const ROperation&);
00143 };
00144
00145
00146 char* MidStr(const char*s,int i1,int i2);
00147 char* CopyStr(const char*s);
00148 char* InsStr(const char*s,int n,char c);
00149 signed char EqStr(const char*s,const char*s2);
00150 signed char CompStr(const char*s,int n,const char*s2);
00151 char* DelStr(const char*s,int n);
00152
00153 #endif