src/thirdparty/mathexpr/mathexpr_c.cpp File Reference

#include "mathexpr_c.h"

Include dependency graph for mathexpr_c.cpp:

Go to the source code of this file.

Functions

double_complex tan (double_complex z)
double_complex acos (double_complex z)
double_complex asin (double_complex z)
double_complex atan (double_complex z)
char * MidStr (const char *s, int i1, int i2)
char * CopyStr (const char *s)
void InsStr (char *&s, int n, char c)
signed char EqStr (const char *s, const char *s2)
signed char CompStr (const char *s, int n, const char *s2)
void DelStr (char *&s, int n)
int operator== (const COperation &op, const double v)
int operator== (const COperation &op, const double_complex v)
int operator== (const COperation &op1, const COperation &op2)
int operator!= (const COperation &op1, const COperation &op2)
COperation operator, (const COperation &op1, const COperation &op2)
COperation operator+ (const COperation &op1, const COperation &op2)
COperation operator- (const COperation &op1, const COperation &op2)
COperation operator * (const COperation &op1, const COperation &op2)
COperation operator/ (const COperation &op1, const COperation &op2)
COperation operator^ (const COperation &op1, const COperation &op2)
COperation real (const COperation &op)
COperation imag (const COperation &op)
COperation conj (const COperation &op)
COperation arg (const COperation &op)
COperation sqrt (const COperation &op)
COperation abs (const COperation &op)
COperation sin (const COperation &op)
COperation cos (const COperation &op)
COperation tan (const COperation &op)
COperation log (const COperation &op)
COperation exp (const COperation &op)
COperation acos (const COperation &op)
COperation asin (const COperation &op)
COperation atan (const COperation &op)
COperation ApplyOperator (int n, COperation **pops, COperation(*func)(const COperation &, const COperation &))
void SupprSpaces (char *&s)
signed char IsNumeric (char c)
signed char IsTNumeric (char *s)
int SearchCorOpenbracket (char *s, int n)
int SearchCorClosebracket (char *s, int n)
int SearchOperator (char *s, COperator op)
void SimplifyStr (char *&s)
int max (int a, int b)
int IsVar (const char *s, int n, int nvar, PCVar *ppvar)
int IsFunction (const char *s, int n)
int IsFunction (const char *s, int n, int nfunc, PCFunction *ppfunc)
signed char IsFunction (COperator op)
void IsolateVars (char *&s, int nvar, PCVar *ppvar, int nfunc, PCFunction *ppfunc)
void IsolateNumbers (char *&s, int nvar, CVar **ppvar, int nfunc, CFunction **ppfunc)
int operator== (const CVar &var1, const CVar &var2)
int operator== (const CFunction &f1, const CFunction &f2)
char * formatreal (double x)
char * formatimag (double x)
char * PrettyPrint (double_complex x)
void Addition (double_complex *&p)
void Soustraction (double_complex *&p)
void Multiplication (double_complex *&p)
void Division (double_complex *&p)
void Puissance (double_complex *&p)
void RacineN (double_complex *&p)
void Puiss10 (double_complex *&p)
void NextVal (double_complex *&)
void RFunc (double_complex *&)
void JuxtF (double_complex *&)
void Absolu (double_complex *&p)
void Oppose (double_complex *&p)
void Reelle (double_complex *&p)
void Imaginaire (double_complex *&p)
void Conjugue (double_complex *&p)
void ArcSinus (double_complex *&p)
void ArcCosinus (double_complex *&p)
void ArcTangente (double_complex *&p)
void Logarithme (double_complex *&p)
void Argument (double_complex *&p)
void Exponentielle (double_complex *&p)
void Sinus (double_complex *&p)
void Tangente (double_complex *&p)
void Cosinus (double_complex *&p)
void Racine (double_complex *&p)
void FonctionError (double_complex *&p)
void ApplyRFunc (PCFunction rf, double_complex *&p)
void BCDouble (pfoncld *&pf, pfoncld *pf1, pfoncld *pf2, double_complex **&pv, double_complex **pv1, double_complex **pv2, double_complex *&pp, double_complex *pp1, double_complex *pp2, CFunction **&prf, CFunction **prf1, CFunction **prf2, pfoncld f)
void BCSimple (pfoncld *&pf, pfoncld *pf1, double_complex **&pv, double_complex **pv1, double_complex *&pp, double_complex *pp1, CFunction **&prf, CFunction **prf1, pfoncld f)
void BCFun (pfoncld *&pf, pfoncld *pf1, double_complex **&pv, double_complex **pv1, double_complex *&pp, double_complex *pp1, CFunction **&prf, CFunction **prf1, PCFunction rf)

Variables

const double sqrtmaxfloat = sqrt(DBL_MAX)
const double sqrtminfloat = sqrt(DBL_MIN)


Function Documentation

COperation abs ( const COperation op  ) 

Definition at line 364 of file mathexpr_c.cpp.

References Abs, COperation::COperation(), COperation::mmb2, and COperation::op.

00365 {COperation rop;rop.op=Abs;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void Absolu ( double_complex *&  p  ) 

Definition at line 1213 of file mathexpr_c.cpp.

References ErrVal.

01213 {*p=((*p==ErrVal)?ErrVal:norm(*p));}

COperation acos ( const COperation op  ) 

Definition at line 376 of file mathexpr_c.cpp.

References Acos, COperation::COperation(), COperation::mmb2, and COperation::op.

00377 {COperation rop;rop.op=Acos;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

double_complex acos ( double_complex  z  ) 

Definition at line 27 of file mathexpr_c.cpp.

References double_complex, log(), and sqrt().

00028 {return -double_complex(0,1)*log(z+double_complex(0,1)*sqrt(double_complex(1,0)-z*z));}

Here is the call graph for this function:

void Addition ( double_complex *&  p  ) 

Definition at line 1176 of file mathexpr_c.cpp.

References ErrVal.

01177 {if(*p==ErrVal||norm(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01178     if(*(--p)==ErrVal||norm(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01179     *p+=(*(p+1));}

COperation ApplyOperator ( int  n,
COperation **  pops,
COperation(*)(const COperation &, const COperation &)  func 
)

Definition at line 383 of file mathexpr_c.cpp.

References COperation::ApplyOperator, and ErrVal.

00384 {
00385     if(n<=0)return ErrVal;
00386     if(n==1)return *pops[0];
00387     if(n==2)return (*func)(*pops[0],*pops[1]);
00388     return (*func)(*pops[0],ApplyOperator(n-1,pops+1,func));
00389 }

void ApplyRFunc ( PCFunction  rf,
double_complex *&  p 
) [inline]

Definition at line 1239 of file mathexpr_c.cpp.

References CFunction::nvars, and CFunction::Val().

01240 {p-=rf->nvars-1;*p=rf->Val(p);}

Here is the call graph for this function:

void ArcCosinus ( double_complex *&  p  ) 

Definition at line 1220 of file mathexpr_c.cpp.

References COperation::acos, double_complex, and ErrVal.

01221 {*p=((*p==ErrVal||*p==double_complex(0,1)||*p==double_complex(0,-1))?ErrVal:acos(*p));}

void ArcSinus ( double_complex *&  p  ) 

Definition at line 1218 of file mathexpr_c.cpp.

References COperation::asin, and ErrVal.

01219 {*p=((*p==ErrVal)?ErrVal:asin(*p));}

void ArcTangente ( double_complex *&  p  ) 

Definition at line 1222 of file mathexpr_c.cpp.

References COperation::atan, and ErrVal.

01223 {*p=((*p==ErrVal)?ErrVal:atan(*p));}

COperation arg ( const COperation op  ) 

Definition at line 360 of file mathexpr_c.cpp.

References Arg, COperation::COperation(), COperation::mmb2, and COperation::op.

Referenced by eFace::FindReplacement().

00361 {COperation rop;rop.op=Arg;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Argument ( double_complex *&  p  ) 

Definition at line 1226 of file mathexpr_c.cpp.

References COperation::arg, and ErrVal.

Referenced by COperation::BuildCode().

01227 {*p=((*p==ErrVal||*p==0.)?ErrVal:arg(*p));}

Here is the caller graph for this function:

COperation asin ( const COperation op  ) 

Definition at line 378 of file mathexpr_c.cpp.

References Asin, COperation::COperation(), COperation::mmb2, and COperation::op.

00379 {COperation rop;rop.op=Asin;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

double_complex asin ( double_complex  z  ) 

Definition at line 29 of file mathexpr_c.cpp.

References double_complex, log(), and sqrt().

00030 {return -double_complex(0,1)*log(double_complex(0,1)*z+sqrt(double_complex(1,0)-z*z));}

Here is the call graph for this function:

COperation atan ( const COperation op  ) 

Definition at line 380 of file mathexpr_c.cpp.

References Atan, COperation::COperation(), COperation::mmb2, and COperation::op.

00381 {COperation rop;rop.op=Atan;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

double_complex atan ( double_complex  z  ) 

Definition at line 31 of file mathexpr_c.cpp.

References double_complex, log(), and sqrt().

00032 {return -double_complex(0,1)*log((double_complex(1,0)+double_complex(0,1)*z)/sqrt(double_complex(1,0)+z*z));}

Here is the call graph for this function:

void BCDouble ( pfoncld *&  pf,
pfoncld *  pf1,
pfoncld *  pf2,
double_complex **&  pv,
double_complex **  pv1,
double_complex **  pv2,
double_complex *&  pp,
double_complex *  pp1,
double_complex *  pp2,
CFunction **&  prf,
CFunction **  prf1,
CFunction **  prf2,
pfoncld  f 
)

Definition at line 1252 of file mathexpr_c.cpp.

References double_complex, ErrVal, and NULL.

01257 {
01258     pfoncld*pf3,*pf4=pf1;long n1,n2;
01259     for(n1=0;*pf4!=NULL;pf4++,n1++);for(n2=0,pf4=pf2;*pf4!=NULL;pf4++,n2++);
01260     pf=new pfoncld[n1+n2+2];
01261     for(pf3=pf,pf4=pf1;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01262     for(pf4=pf2;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01263     *pf3++=f;*pf3=NULL;//delete[]pf1,pf2;
01264     double_complex**pv3,**pv4=pv1;
01265     for(n1=0;*pv4!=NULL;pv4++,n1++);for(n2=0,pv4=pv2;*pv4!=NULL;pv4++,n2++);
01266     pv=new double_complex*[n1+n2+1];
01267     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01268     for(pv4=pv2;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01269     *pv3=NULL;//delete[]pv1,pv2;
01270     double_complex*pp3,*pp4=pp1;
01271     for(n1=0;*pp4!=ErrVal;pp4++,n1++);for(n2=0,pp4=pp2;*pp4!=ErrVal;pp4++,n2++);
01272     pp=new double_complex[n1+n2+1];  // Really need to add and not to take max(n1,n2) in case of Juxt operator
01273     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01274     for(pp4=pp2;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01275     *pp3=ErrVal;//delete[]pp1,pp2;
01276     PCFunction*prf3,*prf4=prf1;
01277     for(n1=0;*prf4!=NULL;prf4++,n1++);for(n2=0,prf4=prf2;*prf4!=NULL;prf4++,n2++);
01278     prf=new PCFunction[n1+n2+1];
01279     for(prf3=prf,prf4=prf1;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01280     for(prf4=prf2;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01281     *prf3=NULL;//delete[]prf1,prf2;
01282 }

void BCFun ( pfoncld *&  pf,
pfoncld *  pf1,
double_complex **&  pv,
double_complex **  pv1,
double_complex *&  pp,
double_complex *  pp1,
CFunction **&  prf,
CFunction **  prf1,
PCFunction  rf 
)

Definition at line 1309 of file mathexpr_c.cpp.

References double_complex, ErrVal, NULL, and RFunc().

01311 {
01312     pfoncld*pf3,*pf4=pf1;long n;
01313     for(n=0;*pf4!=NULL;pf4++,n++);
01314     pf=new pfoncld[n+2];
01315     for(pf4=pf1,pf3=pf;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01316     *pf3++=&RFunc;*pf3=NULL;//delete[]pf1;
01317     double_complex**pv3,**pv4=pv1;
01318     for(n=0;*pv4!=NULL;pv4++,n++);
01319     pv=new double_complex*[n+1];
01320     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01321     *pv3=NULL;//delete[]pv1;
01322     double_complex*pp3,*pp4=pp1;
01323     for(n=0;*pp4!=ErrVal;pp4++,n++);
01324     pp=new double_complex[n+1];
01325     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01326     *pp3=ErrVal;//delete[]pp1;
01327     PCFunction*prf3,*prf4=prf1;
01328     for(n=0;*prf4!=NULL;prf4++,n++);
01329     prf=new PCFunction[n+2];
01330     for(prf4=prf1,prf3=prf;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01331     *prf3++=rf;*prf3=NULL;//delete[]pf1;
01332 }

Here is the call graph for this function:

void BCSimple ( pfoncld *&  pf,
pfoncld *  pf1,
double_complex **&  pv,
double_complex **  pv1,
double_complex *&  pp,
double_complex *  pp1,
CFunction **&  prf,
CFunction **  prf1,
pfoncld  f 
)

Definition at line 1284 of file mathexpr_c.cpp.

References double_complex, ErrVal, and NULL.

01286 {
01287     pfoncld*pf3,*pf4=pf1;long n;
01288     for(n=0;*pf4!=NULL;pf4++,n++);
01289     pf=new pfoncld[n+2];
01290     for(pf4=pf1,pf3=pf;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01291     *pf3++=f;*pf3=NULL;//delete[]pf1;
01292     double_complex**pv3,**pv4=pv1;
01293     for(n=0;*pv4!=NULL;pv4++,n++);
01294     pv=new double_complex*[n+1];
01295     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01296     *pv3=NULL;//delete[]pv1;
01297     double_complex*pp3,*pp4=pp1;
01298     for(n=0;*pp4!=ErrVal;pp4++,n++);
01299     pp=new double_complex[n+1];
01300     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01301     *pp3=ErrVal;//delete[]pp1;
01302     CFunction**prf3,**prf4=prf1;
01303     for(n=0;*prf4!=NULL;prf4++,n++);
01304     prf=new CFunction*[n+1];
01305     for(prf3=prf,prf4=prf1;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01306     *prf3=NULL;//delete[]prf1;
01307 }

signed char CompStr ( const char *  s,
int  n,
const char *  s2 
)

Definition at line 69 of file mathexpr_c.cpp.

00070 {if(n<0||n>=(int)strlen(s)||n+(int)strlen(s2)>(int)strlen(s))return 0;
00071     int i;
00072     for(i=0;s2[i];i++)if(s[i+n]!=s2[i])return 0;
00073     return 1;
00074 }

COperation conj ( const COperation op  ) 

Definition at line 355 of file mathexpr_c.cpp.

References Conj, COperation::conj, COperation::COperation(), COperation::mmb2, Num, COperation::op, and COperation::ValC.

00356 {
00357     if(op.op==Num)return conj(op.ValC);
00358     COperation rop;rop.op=Conj;rop.mmb2=new COperation(op);return rop;
00359 }

Here is the call graph for this function:

void Conjugue ( double_complex *&  p  ) 

Definition at line 1217 of file mathexpr_c.cpp.

References COperation::conj, and ErrVal.

Referenced by COperation::BuildCode().

01217 {*p=((*p==ErrVal)?ErrVal:conj(*p));}

Here is the caller graph for this function:

char* CopyStr ( const char *  s  ) 

Definition at line 48 of file mathexpr_c.cpp.

00049 {char*s1=new char[strlen(s)+1];char*s12=s1;const char*s2=s;
00050     while((*s12++=*s2++));return s1;}

COperation cos ( const COperation op  ) 

Definition at line 368 of file mathexpr_c.cpp.

References COperation::COperation(), Cos, COperation::mmb2, and COperation::op.

00369 {COperation rop;rop.op=Cos;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void Cosinus ( double_complex *&  p  ) 

Definition at line 1234 of file mathexpr_c.cpp.

References COperation::cos, and ErrVal.

01235 {*p=((*p==ErrVal||norm(*p)>DBL_MAX_EXP)?ErrVal:cos(*p));}

void DelStr ( char *&  s,
int  n 
)

Definition at line 76 of file mathexpr_c.cpp.

00077 {char*s1=new char[strlen(s)];
00078     int i;
00079     for(i=0;i<n;i++)s1[i]=s[i];
00080     for(i=n;s[i+1];i++)s1[i]=s[i+1];
00081     s1[i]=0;
00082     delete[]s;s=s1;
00083 }

void Division ( double_complex *&  p  ) 

Definition at line 1190 of file mathexpr_c.cpp.

References ErrVal.

01191 {if(norm(*p)<sqrtminfloat||*p==ErrVal||norm(*p)>sqrtmaxfloat)
01192     {*(--p)=ErrVal;return;};
01193     if(norm(*(--p))<sqrtminfloat)*p=0;else if(*p==ErrVal||norm(*p)>sqrtmaxfloat)
01194     {*p=ErrVal;return;};
01195     *p/=(*(p+1));}

signed char EqStr ( const char *  s,
const char *  s2 
)

Definition at line 62 of file mathexpr_c.cpp.

00063 {if(strlen(s)!=strlen(s2))return 0;
00064     int i;
00065     for(i=0;i<s[i];i++)if(s[i]!=s2[i])return 0;
00066     return 1;
00067 }

COperation exp ( const COperation op  ) 

Definition at line 374 of file mathexpr_c.cpp.

References COperation::COperation(), Exp, COperation::mmb2, and COperation::op.

00375 {COperation rop;rop.op=Exp;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void Exponentielle ( double_complex *&  p  ) 

Definition at line 1228 of file mathexpr_c.cpp.

References ErrVal, and COperation::exp.

01229 {*p=((*p==ErrVal||norm(*p)>DBL_MAX_EXP)?ErrVal:exp(*p));}

void FonctionError ( double_complex *&  p  ) 

Definition at line 1238 of file mathexpr_c.cpp.

References ErrVal.

01238 {*p=ErrVal;}

char* formatimag ( double  x  ) 

Definition at line 998 of file mathexpr_c.cpp.

Referenced by PrettyPrint().

00999 {
01000     char*s=new char[20];
01001     if(x==0)s[0]=0;
01002     else if(x==1)sprintf(s,"i");
01003     else if(x==-1)sprintf(s,"-i");
01004     else if(x==(double)3.141592653589793238462643383279L)sprintf(s,"i pi");
01005     else if(x==(double)(-3.141592653589793238462643383279L))sprintf(s,"-i pi");
01006     else sprintf(s,"%.8g i",x);
01007     return s;
01008 }

Here is the caller graph for this function:

char* formatreal ( double  x  ) 

Definition at line 989 of file mathexpr_c.cpp.

Referenced by PrettyPrint().

00990 {
00991     char*s=new char[20];
00992     if(x==0)s[0]=0;
00993     else if(x==(double)3.141592653589793238462643383279L)sprintf(s,"pi");
00994     else sprintf(s,"%.8g",x);
00995     return s;
00996 }

Here is the caller graph for this function:

COperation imag ( const COperation op  ) 

Definition at line 350 of file mathexpr_c.cpp.

References COperation::COperation(), Imag, COperation::imag, COperation::mmb2, Num, COperation::op, and COperation::ValC.

00351 {
00352     if(op.op==Num)return imag(op.ValC);
00353     COperation rop;rop.op=Imag;rop.mmb2=new COperation(op);return rop;
00354 }

Here is the call graph for this function:

void Imaginaire ( double_complex *&  p  ) 

Definition at line 1216 of file mathexpr_c.cpp.

References ErrVal, and COperation::imag.

Referenced by COperation::BuildCode().

01216 {*p=((*p==ErrVal)?ErrVal:imag(*p));}

Here is the caller graph for this function:

void InsStr ( char *&  s,
int  n,
char  c 
)

Definition at line 52 of file mathexpr_c.cpp.

00052                                             : deletes the old string
00053 {if(n<0||n>(int)strlen(s))return;
00054     char*s1=new char[strlen(s)+2];
00055     int i;
00056     for(i=0;i<n;i++)s1[i]=s[i];
00057     s1[n]=c;for(i=n+1;s[i-1];i++)s1[i]=s[i-1];
00058     s1[i]=0;
00059     delete[]s;s=s1;
00060 }

signed char IsFunction ( COperator  op  ) 

Definition at line 537 of file mathexpr_c.cpp.

References Abs, Acos, Arg, Asin, Atan, Conj, Cos, Exp, Imag, Ln, Opp, Real, Sin, Sqrt, and Tg.

00538 {return (op==Exp||op==Abs||op==Sin||op==Cos||op==Tg||op==Ln
00539              ||op==Atan||op==Asin||op==Acos||op==Atan||op==Sqrt||op==Opp
00540              ||op==Real||op==Imag||op==Conj||op==Arg);
00541 }

int IsFunction ( const char *  s,
int  n,
int  nfunc,
PCFunction ppfunc 
)

Definition at line 524 of file mathexpr_c.cpp.

References CompStr(), IsFunction(), max(), and CFunction::name.

00529 {
00530     int l=IsFunction(s,n);
00531     if(l)return l;
00532     int i;l=0;
00533     for(i=0;i<nfunc;i++)if(CompStr(s,n,ppfunc[i]->name))l=max(l,strlen(ppfunc[i]->name));
00534     return l;
00535 }

Here is the call graph for this function:

int IsFunction ( const char *  s,
int  n 
)

Definition at line 510 of file mathexpr_c.cpp.

References CompStr().

00511 {
00512     if(CompStr(s,n,"sin")||CompStr(s,n,"cos")||CompStr(s,n,"exp")
00513             ||CompStr(s,n,"tan")||CompStr(s,n,"log")||CompStr(s,n,"atg")
00514             ||CompStr(s,n,"arg")||CompStr(s,n,"abs"))return 3;
00515     if(CompStr(s,n,"tg")||CompStr(s,n,"ln"))return 2;
00516     if(CompStr(s,n,"sqrt")||CompStr(s,n,"asin")||CompStr(s,n,"atan")
00517             ||CompStr(s,n,"real")||CompStr(s,n,"conj")
00518             ||CompStr(s,n,"imag")||CompStr(s,n,"acos"))return 4;
00519     if(CompStr(s,n,"arcsin")||CompStr(s,n,"arccos")||CompStr(s,n,"arctan"))return 6;
00520     if(CompStr(s,n,"arctg"))return 5;
00521     return 0;
00522 }

Here is the call graph for this function:

signed char IsNumeric ( char  c  ) 

Definition at line 421 of file mathexpr_c.cpp.

00422 {if(c!='0'&&c!='1'&&c!='2'&&c!='3'&&c!='4'
00423         &&c!='5'&&c!='6'&&c!='7'&&c!='8'&&c!='9'&&c!='.')return 0;
00424     return 1;
00425 }

void IsolateNumbers ( char *&  s,
int  nvar,
CVar **  ppvar,
int  nfunc,
CFunction **  ppfunc 
)

Definition at line 556 of file mathexpr_c.cpp.

References InsStr(), IsFunction(), IsNumeric(), IsVar(), max(), and SearchCorOpenbracket().

00557 {
00558     int i,i2,ind=0,t1,t2;
00559     for(i=0;s[i];i++){
00560         if(ind&&!IsNumeric(s[i])){ind=0;InsStr(s,i2,'(');i++;InsStr(s,i,')');continue;};
00561         t1=IsVar(s,i,nvar,ppvar);t2=IsFunction(s,i,nfunc,ppfunc);
00562         if(t1||t2){i+=max(t1,t2)-1;continue;}
00563         if(s[i]=='('){i=SearchCorOpenbracket(s,i);if(i==-1)return;continue;};
00564         if(!ind&&IsNumeric(s[i])){i2=i;ind=1;};
00565     };
00566     if(ind)InsStr(s,i2,'(');i++;InsStr(s,i,')');
00567 }

Here is the call graph for this function:

void IsolateVars ( char *&  s,
int  nvar,
PCVar ppvar,
int  nfunc,
PCFunction ppfunc 
)

Definition at line 543 of file mathexpr_c.cpp.

References CompStr(), InsStr(), IsFunction(), IsVar(), and SearchCorOpenbracket().

00544 {
00545     int i,j;
00546     i=0;
00547     for(i=0;s[i];i++){
00548         if(s[i]=='('){i=SearchCorOpenbracket(s,i);if(i==-1)return;continue;};
00549         if(((j=IsVar(s,i,nvar,ppvar))>IsFunction(s,i,nfunc,ppfunc))||((CompStr(s,i,"pi")||CompStr(s,i,"PI")||CompStr(s,i,"Pi"))&&(j=2)
00550                 ||(CompStr(s,i,"i")&&(j=1)))){
00551             InsStr(s,i,'(');InsStr(s,i+j+1,')');i+=j+1;continue;};
00552         if(IsFunction(s,i,nfunc,ppfunc)){i+=IsFunction(s,i,nfunc,ppfunc)-1;if(!s[i])return;continue;};
00553     };
00554 }

Here is the call graph for this function:

signed char IsTNumeric ( char *  s  ) 

Definition at line 427 of file mathexpr_c.cpp.

References IsNumeric().

00428 {int i;for(i=0;i<(int)strlen(s);i++)if(!IsNumeric(s[i]))return 0;return 1;
00429 }

Here is the call graph for this function:

int IsVar ( const char *  s,
int  n,
int  nvar,
PCVar ppvar 
)

Definition at line 502 of file mathexpr_c.cpp.

References CompStr(), max(), and CFunction::name.

00503 {
00504     if(n<0||n>(int)strlen(s))return 0;
00505     int i;int l=0;
00506     for(i=0;i<nvar;i++)if(CompStr(s,n,(*(ppvar+i))->name))l=max(l,strlen((*(ppvar+i))->name));
00507     return l;
00508 }

Here is the call graph for this function:

void JuxtF ( double_complex *&   ) 

Definition at line 1212 of file mathexpr_c.cpp.

01212 {}

COperation log ( const COperation op  ) 

Definition at line 372 of file mathexpr_c.cpp.

References COperation::COperation(), Ln, COperation::mmb2, and COperation::op.

00373 {COperation rop;rop.op=Ln;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void Logarithme ( double_complex *&  p  ) 

Definition at line 1224 of file mathexpr_c.cpp.

References ErrVal, and COperation::log.

01225 {*p=((*p==ErrVal||*p==0.)?ErrVal:log(*p));}

int max ( int  a,
int  b 
)

Definition at line 500 of file mathexpr_c.cpp.

00500 {return (a>b?a:b);}

char* MidStr ( const char *  s,
int  i1,
int  i2 
)

Definition at line 35 of file mathexpr_c.cpp.

00036 {
00037     if(i1<0||i2>=(int)strlen(s)||i1>i2){
00038         char* cp = new char[1];
00039         cp[0] = '\0';
00040         return cp;
00041     }
00042     char*s1=new char[i2-i1+2];
00043     int i;
00044     for(i=i1;i<=i2;i++)s1[i-i1]=s[i];
00045     s1[i2-i1+1]=0;return s1;
00046 }

void Multiplication ( double_complex *&  p  ) 

Definition at line 1184 of file mathexpr_c.cpp.

References ErrVal.

01185 {if(norm(*p)<sqrtminfloat){*--p=0;return;};
01186     if(*p==ErrVal||norm(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01187     if(norm(*(--p))<sqrtminfloat){*p=0;return;};
01188     if(*p==ErrVal||norm(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01189     *p*=(*(p+1));}

void NextVal ( double_complex *&   ) 

Definition at line 1210 of file mathexpr_c.cpp.

01210 {}

COperation operator * ( const COperation op1,
const COperation op2 
)

Definition at line 313 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb1, COperation::mmb2, Mult, Num, COperation::op, Opp, and COperation::ValC.

00314 {
00315     if(op1.op==Num&&op2.op==Num)return op1.ValC*op2.ValC;
00316     if(op1==0.||op2==0.)return 0.;
00317     if(op1==1.)return op2;if(op2==1.)return op1;
00318     if(op1.op==Opp)return -(*(op1.mmb2)*op2);if(op2.op==Opp)return -(op1**(op2.mmb2));
00319     COperation resultat;
00320     resultat.op=Mult;resultat.mmb1=new COperation(op1);
00321     resultat.mmb2=new COperation(op2);
00322     return resultat;
00323 }

Here is the call graph for this function:

int operator!= ( const COperation op1,
const COperation op2 
)

Definition at line 260 of file mathexpr_c.cpp.

References Fun, COperation::mmb1, COperation::mmb2, NULL, Num, COperation::op, COperation::pfunc, COperation::pvar, COperation::ValC, and Var.

00261 {
00262     if(op1.op!=op2.op)return 1;
00263     if(op1.op==Var)return(op1.pvar!=op2.pvar);
00264     if(op1.op==Fun)return(!(op1.pfunc==op2.pfunc)); // *op1.pfunc==*op2.pfunc could imply infinite loops in cases of self-dependence
00265     if(op1.op==Num)return(op1.ValC!=op2.ValC);
00266     if(op1.mmb1==NULL&&op2.mmb1!=NULL)return 1;
00267     if(op1.mmb2==NULL&&op2.mmb2!=NULL)return 1;
00268     if(op2.mmb1==NULL&&op1.mmb1!=NULL)return 1;
00269     if(op2.mmb2==NULL&&op1.mmb2!=NULL)return 1;
00270     return(((op1.mmb1!=NULL||op2.mmb1!=NULL)&&(*(op1.mmb1)!=*(op2.mmb1)))||
00271            ((op1.mmb2!=NULL||op2.mmb2!=NULL)&&(*(op1.mmb2)!=*(op2.mmb2))));
00272 }

COperation operator+ ( const COperation op1,
const COperation op2 
)

Definition at line 291 of file mathexpr_c.cpp.

References Add, COperation::COperation(), COperation::mmb2, Num, COperation::op, Opp, and COperation::ValC.

00292 {
00293     if(op1.op==Num&&op2.op==Num)return op1.ValC+op2.ValC;
00294     if(op1==0.)return op2;if(op2==0.)return op1;
00295     if(op1.op==Opp)return op2-*(op1.mmb2);if(op2.op==Opp)return op1-*(op2.mmb2);
00296     COperation resultat;
00297     resultat.op=Add;resultat.mmb1=new COperation(op1);
00298     resultat.mmb2=new COperation(op2);
00299     return resultat;
00300 }

Here is the call graph for this function:

COperation operator, ( const COperation op1,
const COperation op2 
)

Definition at line 284 of file mathexpr_c.cpp.

References COperation::COperation(), Juxt, COperation::mmb1, COperation::mmb2, and COperation::op.

00285 {COperation resultat;
00286     resultat.op=Juxt;resultat.mmb1=new COperation(op1);
00287     resultat.mmb2=new COperation(op2);
00288     return resultat;
00289 }

Here is the call graph for this function:

COperation operator- ( const COperation op1,
const COperation op2 
)

Definition at line 302 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb2, Num, COperation::op, Opp, Sub, and COperation::ValC.

00303 {
00304     if(op1.op==Num&&op2.op==Num)return op1.ValC-op2.ValC;
00305     if(op1==0.)return -op2;if(op2==0.)return op1;
00306     if(op1.op==Opp)return -(op2+*(op1.mmb2));if(op2.op==Opp)return op1+*(op2.mmb2);
00307     COperation resultat;
00308     resultat.op=Sub;resultat.mmb1=new COperation(op1);
00309     resultat.mmb2=new COperation(op2);
00310     return resultat;
00311 }

Here is the call graph for this function:

COperation operator/ ( const COperation op1,
const COperation op2 
)

Definition at line 325 of file mathexpr_c.cpp.

References COperation::COperation(), Div, double_complex, ErrVal, COperation::mmb1, COperation::mmb2, Num, COperation::op, Opp, and COperation::ValC.

00326 {if(op1.op==Num&&op2.op==Num)return (op2.ValC!=double_complex(0,0)?op1.ValC/op2.ValC:ErrVal);
00327     if(op1==0.0)return 0.;if(op2==1.)return op1;if(op2==0.)return ErrVal;
00328     if(op1.op==Opp)return -(*(op1.mmb2)/op2);if(op2.op==Opp)return -(op1/(*(op2.mmb2)));
00329     COperation resultat;
00330     resultat.op=Div;resultat.mmb1=new COperation(op1);
00331     resultat.mmb2=new COperation(op2);
00332     return resultat;
00333 }

Here is the call graph for this function:

int operator== ( const CFunction f1,
const CFunction f2 
)

Definition at line 730 of file mathexpr_c.cpp.

References EqStr(), CFunction::name, CFunction::nvars, CFunction::op, CFunction::ppvar, and CFunction::type.

00731 {
00732     if(f1.type!=f2.type)return 0;
00733     if(f1.type==-1)return 1; // Nonfunction==nonfunction
00734     if(f1.type==0)return (f1.pfuncval==f2.pfuncval&&EqStr(f1.name,f2.name));
00735     if(f1.op!=f2.op)return 0;
00736     if(!EqStr(f1.name,f2.name))return 0;
00737     if(f1.nvars!=f2.nvars)return 0;
00738     int i;
00739     for(i=0;i<f1.nvars;i++)if(!(*f1.ppvar[i]==*f2.ppvar[i]))return 0;
00740     return 1;
00741 }

Here is the call graph for this function:

int operator== ( const CVar var1,
const CVar var2 
)

Definition at line 726 of file mathexpr_c.cpp.

References EqStr(), CVar::name, and CVar::pval.

00727 {return(var1.pval==var2.pval&&EqStr(var1.name,var2.name));
00728 }

Here is the call graph for this function:

int operator== ( const COperation op1,
const COperation op2 
)

Definition at line 247 of file mathexpr_c.cpp.

References Fun, COperation::mmb1, COperation::mmb2, NULL, Num, COperation::op, COperation::pfunc, COperation::pvar, COperation::ValC, and Var.

00248 {if(op1.op!=op2.op)return 0;
00249     if(op1.op==Var)return(*(op1.pvar)==*(op2.pvar));
00250     if(op1.op==Fun)return(op1.pfunc==op2.pfunc); // *op1.pfunc==*op2.pfunc could imply infinite loops in cases of self-dependence
00251     if(op1.op==Num)return(op1.ValC==op2.ValC);
00252     if(op1.mmb1==NULL&&op2.mmb1!=NULL)return 0;
00253     if(op1.mmb2==NULL&&op2.mmb2!=NULL)return 0;
00254     if(op2.mmb1==NULL&&op1.mmb1!=NULL)return 0;
00255     if(op2.mmb2==NULL&&op1.mmb2!=NULL)return 0;
00256     return(((op1.mmb1==NULL&&op2.mmb1==NULL)||(*(op1.mmb1)==*(op2.mmb1)))&&
00257            ((op1.mmb2==NULL&&op2.mmb2==NULL)||(*(op1.mmb2)==*(op2.mmb2))));
00258 }

int operator== ( const COperation op,
const double_complex  v 
)

Definition at line 244 of file mathexpr_c.cpp.

References Num, COperation::op, and COperation::ValC.

00245 {return(op.op==Num&&op.ValC==v);}

int operator== ( const COperation op,
const double  v 
)

Definition at line 241 of file mathexpr_c.cpp.

References Num, COperation::op, and COperation::ValC.

00242 {return(op.op==Num&&op.ValC==v);}

COperation operator^ ( const COperation op1,
const COperation op2 
)

Definition at line 335 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb1, COperation::mmb2, COperation::op, and Pow.

00336 {if(op1==0.)return 0.;
00337     if(op2==0.)return 1.;
00338     if(op2==1.)return op1;
00339     COperation resultat;
00340     resultat.op=Pow;resultat.mmb1=new COperation(op1);
00341     resultat.mmb2=new COperation(op2);
00342     return resultat;
00343 }

Here is the call graph for this function:

void Oppose ( double_complex *&  p  ) 

Definition at line 1214 of file mathexpr_c.cpp.

References ErrVal.

01214 {*p=((*p==ErrVal)?ErrVal:-*p);}

char* PrettyPrint ( double_complex  x  ) 

Definition at line 1010 of file mathexpr_c.cpp.

References double_complex, formatimag(), formatreal(), COperation::imag, and COperation::real.

Referenced by COperation::Expr(), and main().

01011 {
01012     char*s=new char[30],*s1=formatreal(real(x)),*s2=formatimag(imag(x));
01013     if(!strlen(s1)&&!strlen(s2))sprintf(s,"0");
01014     else if(x==double_complex(0,1))sprintf(s,"i");
01015     else if(!strlen(s1))sprintf(s,"(%s)",s2);
01016     else if(!strlen(s2))sprintf(s,"%s",s1);
01017     else if(imag(x)>0)sprintf(s,"(%s+%s)",s1,s2);
01018     else sprintf(s,"(%s%s)",s1,s2);
01019     delete s1, delete s2;
01020     return s;
01021 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Puiss10 ( double_complex *&  p  ) 

Definition at line 1204 of file mathexpr_c.cpp.

References double_complex, and ErrVal.

01205 {if(norm(*p)<sqrtminfloat){*(--p)=0;return;};
01206     if(*p==ErrVal||norm(*p)>DBL_MAX_10_EXP){*(--p)=ErrVal;return;};
01207     if(norm(*(--p))<sqrtminfloat)*p=0;else if(*p==ErrVal||norm(*p)>sqrtmaxfloat)
01208     {*p=ErrVal;return;};
01209     *p*=pow(double_complex(10.),*(p+1));}

void Puissance ( double_complex *&  p  ) 

Definition at line 1196 of file mathexpr_c.cpp.

References double_complex, ErrVal, and COperation::log.

01197 {double_complex v2=*p--,v1=*p;
01198     if(v2==ErrVal||v1==ErrVal||norm(v2)*log(norm(v1))>DBL_MAX_EXP){*p=ErrVal;return;};
01199     *p=(v1==0.?0:pow(v1,v2));}

void Racine ( double_complex *&  p  ) 

Definition at line 1236 of file mathexpr_c.cpp.

References ErrVal, and COperation::sqrt.

01237 {*p=((*p==ErrVal||norm(*p)>sqrtmaxfloat)?ErrVal:sqrt(*p));}

void RacineN ( double_complex *&  p  ) 

Definition at line 1200 of file mathexpr_c.cpp.

References double_complex, ErrVal, and COperation::log.

01201 {double_complex v2=*p--,v1=*p;
01202     if(v1==ErrVal||v2==ErrVal||v1==0.||norm(v2)*log(norm(v1))<DBL_MIN_EXP){*p=ErrVal;return;};
01203     *p=pow(v2,double_complex(1,0)/v1);return;}

COperation real ( const COperation op  ) 

Definition at line 345 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb2, Num, COperation::op, Real, COperation::real, and COperation::ValC.

00346 {
00347     if(op.op==Num)return real(op.ValC);
00348     COperation rop;rop.op=Real;rop.mmb2=new COperation(op);return rop;
00349 }

Here is the call graph for this function:

void Reelle ( double_complex *&  p  ) 

Definition at line 1215 of file mathexpr_c.cpp.

References ErrVal, and COperation::real.

Referenced by COperation::BuildCode().

01215 {*p=((*p==ErrVal)?ErrVal:real(*p));}

Here is the caller graph for this function:

void RFunc ( double_complex *&   ) 

Definition at line 1211 of file mathexpr_c.cpp.

01211 {}

int SearchCorClosebracket ( char *  s,
int  n 
)

Definition at line 441 of file mathexpr_c.cpp.

References c.

00442 {if(n<1)return -1;
00443     int i,c=1;
00444     for(i=n-1;i>=0;i--){
00445         if(s[i]==')')c++;else if(s[i]=='(')c--;
00446         if(!c)return i;
00447     };
00448     return -1;
00449 }

int SearchCorOpenbracket ( char *  s,
int  n 
)

Definition at line 431 of file mathexpr_c.cpp.

References c.

00432 {if(n>=(int)strlen(s)-1)return -1;
00433     int i,c=1;
00434     for(i=n+1;s[i];i++){
00435         if(s[i]=='(')c++;else if(s[i]==')')c--;
00436         if(!c)return i;
00437     };
00438     return -1;
00439 }

int SearchOperator ( char *  s,
COperator  op 
)

Definition at line 451 of file mathexpr_c.cpp.

References Add, Div, E10, ErrOp, Juxt, Mult, NthRoot, Num, Pow, SearchCorClosebracket(), Sub, and Var.

00452 {
00453     char opc;
00454     switch(op){
00455 case ErrOp:case Num:case Var:return -1;
00456     case Juxt:opc=',';break;
00457     case Add:opc='+';break;
00458     case Sub:opc='-';break;
00459     case Mult:opc='*';break;
00460     case Div:opc='/';break;
00461     case Pow:opc='^';break;
00462     case NthRoot:opc='#';break;
00463     case E10:opc='E';break;
00464     default:return -1;
00465     };
00466     int i;
00467     for(i=(int)strlen(s)-1;i>=0;i--){
00468         if(s[i]==opc&&(op!=Sub||i&&s[i-1]==')'))return i;
00469     if(s[i]==')'){i=SearchCorClosebracket(s,i);if(i==-1)return -1;};
00470     };
00471     return -1;
00472 }

Here is the call graph for this function:

void SimplifyStr ( char *&  s  ) 

Definition at line 474 of file mathexpr_c.cpp.

References CopyStr(), SearchCorOpenbracket(), and SimplifyStr().

00474                                     : deletes the old string
00475 {if(!strlen(s))return;
00476     char*s1=s,*s2=s+strlen(s);signed char ind=0;
00477     if(s1[0]=='('&&SearchCorOpenbracket(s1,0)==s2-s1-1){
00478         s1++;s2--;ind=1;}
00479     if(s1==s2)
00480     {
00481         delete[]s;
00482         s=new char[1]; // ISO C++ forbids initialization in array new
00483         s[0]=0;
00484         return;
00485     }
00486     if(s1[0]==' '){ind=1;while(s1[0]==' '&&s1<s2)s1++;}
00487     if(s1==s2)
00488     {
00489         delete[]s;
00490         s=new char[1]; // ISO C++ forbids initialization in array new
00491         s[0]=0;
00492         return;
00493     }
00494     if(*(s2-1)==' '){ind=1;while(s2>s1&&*(s2-1)==' ')s2--;}
00495     *s2=0;
00496     s1=CopyStr(s1);delete[]s;s=s1;
00497     if(ind)SimplifyStr(s);
00498 }

Here is the call graph for this function:

COperation sin ( const COperation op  ) 

Definition at line 366 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb2, COperation::op, and Sin.

00367 {COperation rop;rop.op=Sin;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void Sinus ( double_complex *&  p  ) 

Definition at line 1230 of file mathexpr_c.cpp.

References ErrVal, and COperation::sin.

01231 {*p=((*p==ErrVal||norm(*p)>DBL_MAX_EXP)?ErrVal:sin(*p));}

void Soustraction ( double_complex *&  p  ) 

Definition at line 1180 of file mathexpr_c.cpp.

References ErrVal.

01181 {if(*p==ErrVal||norm(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01182     if(*(--p)==ErrVal||norm(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01183     *p-=(*(p+1));}

COperation sqrt ( const COperation op  ) 

Definition at line 362 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb2, COperation::op, and Sqrt.

00363 {COperation rop;rop.op=Sqrt;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

void SupprSpaces ( char *&  s  ) 

Definition at line 415 of file mathexpr_c.cpp.

References DelStr().

00416 {
00417     int i;
00418     for(i=0;s[i];i++)if(s[i]==' '||s[i]=='\t'||s[i]=='\n')DelStr(s,i--);
00419 }

Here is the call graph for this function:

COperation tan ( const COperation op  ) 

Definition at line 370 of file mathexpr_c.cpp.

References COperation::COperation(), COperation::mmb2, COperation::op, and Tg.

00371 {COperation rop;rop.op=Tg;rop.mmb2=new COperation(op);return rop;}

Here is the call graph for this function:

double_complex tan ( double_complex  z  ) 

Definition at line 25 of file mathexpr_c.cpp.

References cos(), and sin().

00026 {return sin(z)/cos(z);}

Here is the call graph for this function:

void Tangente ( double_complex *&  p  ) 

Definition at line 1232 of file mathexpr_c.cpp.

References ErrVal, and COperation::tan.

01233 {*p=((*p==ErrVal||norm(*p)>DBL_MAX_EXP)?ErrVal:tan(*p));}


Variable Documentation

const double sqrtmaxfloat = sqrt(DBL_MAX)

Definition at line 1173 of file mathexpr_c.cpp.

const double sqrtminfloat = sqrt(DBL_MIN)

Definition at line 1174 of file mathexpr_c.cpp.


Generated on Sat Mar 15 23:09:37 2008 for Armagetron Advanced by  doxygen 1.5.4