src/thirdparty/mathexpr/mathexpr.cpp File Reference

#include "mathexpr.h"
#include "defs.h"

Include dependency graph for mathexpr.cpp:

Go to the source code of this file.

Functions

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 ROperation &op, const float v)
int operator== (const ROperation &op1, const ROperation &op2)
int operator!= (const ROperation &op1, const ROperation &op2)
ROperation operator, (const ROperation &op1, const ROperation &op2)
ROperation operator+ (const ROperation &op1, const ROperation &op2)
ROperation operator- (const ROperation &op1, const ROperation &op2)
ROperation operator * (const ROperation &op1, const ROperation &op2)
ROperation operator/ (const ROperation &op1, const ROperation &op2)
ROperation operator^ (const ROperation &op1, const ROperation &op2)
ROperation sqrt (const ROperation &op)
ROperation abs (const ROperation &op)
ROperation sin (const ROperation &op)
ROperation cos (const ROperation &op)
ROperation tan (const ROperation &op)
ROperation log (const ROperation &op)
ROperation exp (const ROperation &op)
ROperation acos (const ROperation &op)
ROperation asin (const ROperation &op)
ROperation atan (const ROperation &op)
ROperation ApplyOperator (int n, ROperation **pops, ROperation(*func)(const ROperation &, const ROperation &))
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, ROperator op)
void SimplifyStr (char *&s)
int max (int a, int b)
int IsVar (const char *s, int n, int nvar, PRVar *ppvar)
int IsFunction (const char *s, int n)
int IsFunction (const char *s, int n, int nfunc, PRFunction *ppfunc)
signed char IsFunction (ROperator op)
void IsolateVars (char *&s, int nvar, PRVar *ppvar, int nfunc, PRFunction *ppfunc)
void IsolateNumbers (char *&s, int nvar, RVar **ppvar, int nfunc, RFunction **ppfunc)
int operator== (const RVar &var1, const RVar &var2)
int operator== (const RFunction &f1, const RFunction &f2)
char * ValToStr (float x)
void Addition (float *&p)
void Soustraction (float *&p)
void Multiplication (float *&p)
void Division (float *&p)
void Puissance (float *&p)
void RacineN (float *&p)
void Puiss10 (float *&p)
void ArcTangente2 (float *&p)
void NextVal (float *&)
void RFunc (float *&)
void JuxtF (float *&)
void Absolu (float *&p)
void Oppose (float *&p)
void ArcSinus (float *&p)
void ArcCosinus (float *&p)
void ArcTangente (float *&p)
void Logarithme (float *&p)
void Exponentielle (float *&p)
void Sinus (float *&p)
void Tangente (float *&p)
void Cosinus (float *&p)
void Racine (float *&p)
void FonctionError (float *&p)
void ApplyRFunc (PRFunction rf, float *&p)
void BCDouble (pfoncld *&pf, pfoncld *pf1, pfoncld *pf2, float **&pv, float **pv1, float **pv2, float *&pp, float *pp1, float *pp2, RFunction **&prf, RFunction **prf1, RFunction **prf2, pfoncld f)
void BCSimple (pfoncld *&pf, pfoncld *pf1, float **&pv, float **pv1, float *&pp, float *pp1, RFunction **&prf, RFunction **prf1, pfoncld f)
void BCFun (pfoncld *&pf, pfoncld *pf1, float **&pv, float **pv1, float *&pp, float *pp1, RFunction **&prf, RFunction **prf1, PRFunction rf)

Variables

const float sqrtmaxfloat = sqrt(DBL_MAX)
const float sqrtminfloat = sqrt(DBL_MIN)
const float inveps = .1/DBL_EPSILON


Function Documentation

ROperation abs ( const ROperation op  ) 

Definition at line 326 of file mathexpr.cpp.

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

Referenced by exponent(), tString::RemoveSubStr(), and gWallRim::RenderReal().

00327 {ROperation rop;rop.op=Abs;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Absolu ( float *&  p  ) 

Definition at line 1048 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01048 {*p=((*p==ErrVal)?ErrVal:fabs(*p));}

Here is the caller graph for this function:

ROperation acos ( const ROperation op  ) 

Definition at line 338 of file mathexpr.cpp.

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

Referenced by robust_acos().

00339 {ROperation rop;rop.op=Acos;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Addition ( float *&  p  ) 

Definition at line 1005 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01006 {if(*p==ErrVal||fabs(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01007     if(*(--p)==ErrVal||fabs(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01008     *p+=(*(p+1));}

Here is the caller graph for this function:

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

Definition at line 345 of file mathexpr.cpp.

References ROperation::ApplyOperator, and ErrVal.

00346 {
00347     if(n<=0)return ErrVal;
00348     if(n==1)return *pops[0];
00349     if(n==2)return (*func)(*pops[0],*pops[1]);
00350     return (*func)(*pops[0],ApplyOperator(n-1,pops+1,func));
00351 }

void ApplyRFunc ( PRFunction  rf,
float *&  p 
) [inline]

Definition at line 1069 of file mathexpr.cpp.

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

Referenced by COperation::Val(), and ROperation::Val().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void ArcCosinus ( float *&  p  ) 

Definition at line 1052 of file mathexpr.cpp.

References ROperation::acos, and ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01053 {*p=((*p==ErrVal||fabs(*p)>1)?ErrVal:acos(*p));}

Here is the caller graph for this function:

void ArcSinus ( float *&  p  ) 

Definition at line 1050 of file mathexpr.cpp.

References ROperation::asin, and ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01051 {*p=((*p==ErrVal||fabs(*p)>1)?ErrVal:asin(*p));}

Here is the caller graph for this function:

void ArcTangente ( float *&  p  ) 

Definition at line 1054 of file mathexpr.cpp.

References ROperation::atan, and ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

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

Here is the caller graph for this function:

void ArcTangente2 ( float *&  p  ) 

Definition at line 1041 of file mathexpr.cpp.

References ErrVal.

Referenced by ROperation::BuildCode().

01042 {if(*p==ErrVal||fabs(*p)>inveps){*(--p)=ErrVal;return;};
01043     if(*(--p)==ErrVal||fabs(*p)>inveps){*p=ErrVal;return;};
01044     *p=(*p||*(p+1)?atan2(*p,*(p+1)):ErrVal);}

Here is the caller graph for this function:

ROperation asin ( const ROperation op  ) 

Definition at line 340 of file mathexpr.cpp.

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

00341 {ROperation rop;rop.op=Asin;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

ROperation atan ( const ROperation op  ) 

Definition at line 342 of file mathexpr.cpp.

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

Referenced by rViewport::UpDownFOV().

00343 {ROperation rop;rop.op=Atan;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1082 of file mathexpr.cpp.

References ErrVal, and NULL.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01087 {
01088     pfoncld*pf3,*pf4=pf1;long n1,n2;
01089     for(n1=0;*pf4!=NULL;pf4++,n1++);for(n2=0,pf4=pf2;*pf4!=NULL;pf4++,n2++);
01090     pf=new pfoncld[n1+n2+2];
01091     for(pf3=pf,pf4=pf1;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01092     for(pf4=pf2;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01093     *pf3++=f;*pf3=NULL;//delete[]pf1,pf2;
01094     float**pv3,**pv4=pv1;
01095     for(n1=0;*pv4!=NULL;pv4++,n1++);for(n2=0,pv4=pv2;*pv4!=NULL;pv4++,n2++);
01096     pv=new float*[n1+n2+1];
01097     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01098     for(pv4=pv2;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01099     *pv3=NULL;//delete[]pv1,pv2;
01100     float*pp3,*pp4=pp1;
01101     for(n1=0;*pp4!=ErrVal;pp4++,n1++);for(n2=0,pp4=pp2;*pp4!=ErrVal;pp4++,n2++);
01102     pp=new float[n1+n2+1];  // Really need to add and not to take max(n1,n2) in case of Juxt operator
01103     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01104     for(pp4=pp2;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01105     *pp3=ErrVal;//delete[]pp1,pp2;
01106     PRFunction*prf3,*prf4=prf1;
01107     for(n1=0;*prf4!=NULL;prf4++,n1++);for(n2=0,prf4=prf2;*prf4!=NULL;prf4++,n2++);
01108     prf=new PRFunction[n1+n2+1];
01109     for(prf3=prf,prf4=prf1;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01110     for(prf4=prf2;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01111     *prf3=NULL;//delete[]prf1,prf2;
01112 }

Here is the caller graph for this function:

void BCFun ( pfoncld *&  pf,
pfoncld *  pf1,
float **&  pv,
float **  pv1,
float *&  pp,
float *  pp1,
RFunction **&  prf,
RFunction **  prf1,
PRFunction  rf 
)

Definition at line 1139 of file mathexpr.cpp.

References ErrVal, NULL, and RFunc().

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01141 {
01142     pfoncld*pf3,*pf4=pf1;long n;
01143     for(n=0;*pf4!=NULL;pf4++,n++);
01144     pf=new pfoncld[n+2];
01145     for(pf4=pf1,pf3=pf;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01146     *pf3++=&RFunc;*pf3=NULL;//delete[]pf1;
01147     float**pv3,**pv4=pv1;
01148     for(n=0;*pv4!=NULL;pv4++,n++);
01149     pv=new float*[n+1];
01150     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01151     *pv3=NULL;//delete[]pv1;
01152     float*pp3,*pp4=pp1;
01153     for(n=0;*pp4!=ErrVal;pp4++,n++);
01154     pp=new float[n+1];
01155     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01156     *pp3=ErrVal;//delete[]pp1;
01157     PRFunction*prf3,*prf4=prf1;
01158     for(n=0;*prf4!=NULL;prf4++,n++);
01159     prf=new PRFunction[n+2];
01160     for(prf4=prf1,prf3=prf;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01161     *prf3++=rf;*prf3=NULL;//delete[]pf1;
01162 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1114 of file mathexpr.cpp.

References ErrVal, and NULL.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01116 {
01117     pfoncld*pf3,*pf4=pf1;long n;
01118     for(n=0;*pf4!=NULL;pf4++,n++);
01119     pf=new pfoncld[n+2];
01120     for(pf4=pf1,pf3=pf;*pf4!=NULL;pf3++,pf4++)*pf3=*pf4;
01121     *pf3++=f;*pf3=NULL;//delete[]pf1;
01122     float**pv3,**pv4=pv1;
01123     for(n=0;*pv4!=NULL;pv4++,n++);
01124     pv=new float*[n+1];
01125     for(pv3=pv,pv4=pv1;*pv4!=NULL;pv3++,pv4++)*pv3=*pv4;
01126     *pv3=NULL;//delete[]pv1;
01127     float*pp3,*pp4=pp1;
01128     for(n=0;*pp4!=ErrVal;pp4++,n++);
01129     pp=new float[n+1];
01130     for(pp3=pp,pp4=pp1;*pp4!=ErrVal;pp3++,pp4++)*pp3=0;
01131     *pp3=ErrVal;//delete[]pp1;
01132     RFunction**prf3,**prf4=prf1;
01133     for(n=0;*prf4!=NULL;prf4++,n++);
01134     prf=new RFunction*[n+1];
01135     for(prf3=prf,prf4=prf1;*prf4!=NULL;prf3++,prf4++)*prf3=*prf4;
01136     *prf3=NULL;//delete[]prf1;
01137 }

Here is the caller graph for this function:

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

Definition at line 59 of file mathexpr.cpp.

Referenced by COperation::COperation(), IsFunction(), IsolateVars(), IsVar(), and ROperation::ROperation().

00060 {if(n<0||n>=(int)strlen(s)||n+(int)strlen(s2)>(int)strlen(s))return 0;
00061     int i;
00062     for(i=0;s2[i];i++)if(s[i+n]!=s2[i])return 0;
00063     return 1;
00064 }

Here is the caller graph for this function:

char* CopyStr ( const char *  s  ) 

Definition at line 38 of file mathexpr.cpp.

Referenced by CFunction::CFunction(), COperation::COperation(), CVar::CVar(), COperation::Expr(), ROperation::Expr(), CFunction::operator=(), RFunction::operator=(), RFunction::RFunction(), ROperation::ROperation(), RVar::RVar(), CFunction::SetName(), RFunction::SetName(), and SimplifyStr().

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

Here is the caller graph for this function:

ROperation cos ( const ROperation op  ) 

Definition at line 330 of file mathexpr.cpp.

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

Referenced by cWidget::Map::ClipperCircle::Begin(), cosf(), eCamera::nextDirIfGlancing(), paint_sr_lowerSky(), zShapeCircle::render(), gZone::Render(), gCycle::Render(), zShapeCircle::render2d(), gZone::Render2D(), cWidget::NeedleGauge::RenderGraph(), tan(), and gZone::Timestep().

00331 {ROperation rop;rop.op=Cos;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Cosinus ( float *&  p  ) 

Definition at line 1064 of file mathexpr.cpp.

References ROperation::cos, and ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01065 {*p=((*p==ErrVal||fabs(*p)>inveps)?ErrVal:cos(*p));}

Here is the caller graph for this function:

void DelStr ( char *&  s,
int  n 
)

Definition at line 66 of file mathexpr.cpp.

Referenced by SupprSpaces().

00067 {char*s1=new char[strlen(s)];
00068     int i;
00069     for(i=0;i<n;i++)s1[i]=s[i];
00070     for(i=n;s[i+1];i++)s1[i]=s[i+1];
00071     s1[i]=0;
00072     delete[]s;s=s1;
00073 }

Here is the caller graph for this function:

void Division ( float *&  p  ) 

Definition at line 1019 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01020 {if(fabs(*p)<sqrtminfloat||*p==ErrVal||fabs(*p)>sqrtmaxfloat)
01021     {*(--p)=ErrVal;return;};
01022     if(fabs(*(--p))<sqrtminfloat)*p=0;else if(*p==ErrVal||fabs(*p)>sqrtmaxfloat)
01023     {*p=ErrVal;return;};
01024     *p/=(*(p+1));}

Here is the caller graph for this function:

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

Definition at line 52 of file mathexpr.cpp.

Referenced by COperation::ContainVar(), ROperation::ContainVar(), COperation::COperation(), operator==(), and ROperation::ROperation().

00053 {if(strlen(s)!=strlen(s2))return 0;
00054     int i;
00055     for(i=0;s[i];i++)if(s[i]!=s2[i])return 0;
00056     return 1;
00057 }

Here is the caller graph for this function:

ROperation exp ( const ROperation op  ) 

Definition at line 336 of file mathexpr.cpp.

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

Referenced by gCycleMovement::ApplyAcceleration(), expf(), gAIPlayer::gAIPlayer(), nMessage::operator<<(), eCamera::Timestep(), and gCycleMovement::TimestepCore().

00337 {ROperation rop;rop.op=Exp;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Exponentielle ( float *&  p  ) 

Definition at line 1058 of file mathexpr.cpp.

References ErrVal, and ROperation::exp.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

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

Here is the caller graph for this function:

void FonctionError ( float *&  p  ) 

Definition at line 1068 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01068 {*p=ErrVal;}

Here is the caller graph for this function:

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

Definition at line 42 of file mathexpr.cpp.

Referenced by COperation::COperation(), IsolateNumbers(), IsolateVars(), and ROperation::ROperation().

00042                                             : deletes the old string
00043 {if(n<0||n>(int)strlen(s))return;
00044     char*s1=new char[strlen(s)+2];
00045     int i;
00046     for(i=0;i<n;i++)s1[i]=s[i];
00047     s1[n]=c;for(i=n+1;s[i-1];i++)s1[i]=s[i-1];
00048     s1[i]=0;
00049     delete[]s;s=s1;
00050 }

Here is the caller graph for this function:

signed char IsFunction ( ROperator  op  ) 

Definition at line 498 of file mathexpr.cpp.

References Abs, Acos, Asin, Atan, Cos, Exp, Ln, Opp, Sin, Sqrt, and Tg.

00499 {return (op==Exp||op==Abs||op==Sin||op==Cos||op==Tg||op==Ln||
00500              op==Atan||op==Asin||op==Acos||op==Atan||op==Sqrt||op==Opp);
00501 }

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

Definition at line 485 of file mathexpr.cpp.

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

00490 {
00491     int l=IsFunction(s,n);
00492     if(l)return l;
00493     int i;l=0;
00494     for(i=0;i<nfunc;i++)if(CompStr(s,n,ppfunc[i]->name))l=max(l,strlen(ppfunc[i]->name));
00495     return l;
00496 }

Here is the call graph for this function:

int IsFunction ( const char *  s,
int  n 
)

Definition at line 472 of file mathexpr.cpp.

References CompStr().

Referenced by COperation::COperation(), COperation::Expr(), ROperation::Expr(), IsFunction(), IsolateNumbers(), IsolateVars(), and ROperation::ROperation().

00473 {
00474     if(CompStr(s,n,"sin")||CompStr(s,n,"cos")||CompStr(s,n,"exp")
00475             ||CompStr(s,n,"tan")||CompStr(s,n,"log")||CompStr(s,n,"atg")
00476             ||CompStr(s,n,"abs"))return 3;
00477     if(CompStr(s,n,"tg")||CompStr(s,n,"ln"))return 2;
00478     if(CompStr(s,n,"sqrt")||CompStr(s,n,"asin")||CompStr(s,n,"atan")||
00479             CompStr(s,n,"acos"))return 4;
00480     if(CompStr(s,n,"arcsin")||CompStr(s,n,"arccos")||CompStr(s,n,"arctan"))return 6;
00481     if(CompStr(s,n,"arctg"))return 5;
00482     return 0;
00483 }

Here is the call graph for this function:

Here is the caller graph for this function:

signed char IsNumeric ( char  c  ) 

Definition at line 383 of file mathexpr.cpp.

Referenced by IsolateNumbers(), and IsTNumeric().

00384 {if(c!='0'&&c!='1'&&c!='2'&&c!='3'&&c!='4'
00385         &&c!='5'&&c!='6'&&c!='7'&&c!='8'&&c!='9'&&c!='.')return 0;
00386     return 1;
00387 }

Here is the caller graph for this function:

void IsolateNumbers ( char *&  s,
int  nvar,
RVar **  ppvar,
int  nfunc,
RFunction **  ppfunc 
)

Definition at line 515 of file mathexpr.cpp.

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

Referenced by COperation::COperation(), and ROperation::ROperation().

00516 {
00517     int i,i2,ind=0,t1,t2;
00518     //initialize i2 to fix a wrong compiler warning
00519     i2=42;
00520     for(i=0;s[i];i++){
00521         if(ind&&!IsNumeric(s[i])){ind=0;InsStr(s,i2,'(');i++;InsStr(s,i,')');continue;};
00522         t1=IsVar(s,i,nvar,ppvar);t2=IsFunction(s,i,nfunc,ppfunc);
00523         if(t1||t2){i+=max(t1,t2)-1;continue;};
00524         if(s[i]=='('){i=SearchCorOpenbracket(s,i);if(i==-1)return;continue;};
00525         if(!ind&&IsNumeric(s[i])){i2=i;ind=1;};
00526     };
00527     if(ind)InsStr(s,i2,'(');i++;InsStr(s,i,')');
00528 }

Here is the call graph for this function:

Here is the caller graph for this function:

void IsolateVars ( char *&  s,
int  nvar,
PRVar ppvar,
int  nfunc,
PRFunction ppfunc 
)

Definition at line 503 of file mathexpr.cpp.

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

Referenced by COperation::COperation(), and ROperation::ROperation().

00504 {
00505     int i,j;
00506     i=0;
00507     for(i=0;s[i];i++){
00508         if(s[i]=='('){i=SearchCorOpenbracket(s,i);if(i==-1)return;continue;};
00509         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))){
00510             InsStr(s,i,'(');InsStr(s,i+j+1,')');i+=j+1;continue;};
00511         if(IsFunction(s,i,nfunc,ppfunc)){i+=IsFunction(s,i,nfunc,ppfunc)-1;if(!s[i])return;continue;};
00512     };
00513 }

Here is the call graph for this function:

Here is the caller graph for this function:

signed char IsTNumeric ( char *  s  ) 

Definition at line 389 of file mathexpr.cpp.

References IsNumeric().

Referenced by COperation::COperation(), and ROperation::ROperation().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 464 of file mathexpr.cpp.

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

Referenced by COperation::COperation(), IsolateNumbers(), IsolateVars(), and ROperation::ROperation().

00465 {
00466     if(n<0||n>(int)strlen(s))return 0;
00467     int i;int l=0;
00468     for(i=0;i<nvar;i++)if(CompStr(s,n,(*(ppvar+i))->name))l=max(l,strlen((*(ppvar+i))->name));
00469     return l;
00470 }

Here is the call graph for this function:

Here is the caller graph for this function:

void JuxtF ( float *&   ) 

Definition at line 1047 of file mathexpr.cpp.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01047 {}

Here is the caller graph for this function:

ROperation log ( const ROperation op  ) 

Definition at line 334 of file mathexpr.cpp.

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

Referenced by acos(), asin(), atan(), and logf().

00335 {ROperation rop;rop.op=Ln;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Logarithme ( float *&  p  ) 

Definition at line 1056 of file mathexpr.cpp.

References ErrVal, and ROperation::log.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01057 {*p=((*p==ErrVal||*p<=0)?ErrVal:log(*p));}

Here is the caller graph for this function:

int max ( int  a,
int  b 
)

Definition at line 462 of file mathexpr.cpp.

Referenced by do_chat(), cWidget::Map::DrawRimWalls(), eTeam::Enforce(), gCycleMemoryEntry::gCycleMemoryEntry(), zSelector::getAllValid(), eFace::Insideness(), IsFunction(), IsolateNumbers(), IsVar(), gCycle::PassEdge(), eTeam::Ranking(), ePlayerNetID::Ranking(), eTeam::RankingGraph(), cWidget::Rectangle::Render(), cWidget::BarGauge::Render(), nBasicNetworkSystem::Select(), test_max_a(), and test_max_b().

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

Here is the caller graph for this function:

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

Definition at line 25 of file mathexpr.cpp.

Referenced by COperation::COperation(), and ROperation::ROperation().

00026 {
00027     if(i1<0||i2>=(int)strlen(s)||i1>i2){
00028         char* cp = new char[1];
00029         cp[0] = '\0';
00030         return cp;
00031     }
00032     char*s1=new char[i2-i1+2];
00033     int i;
00034     for(i=i1;i<=i2;i++)s1[i-i1]=s[i];
00035     s1[i2-i1+1]=0;return s1;
00036 }

Here is the caller graph for this function:

void Multiplication ( float *&  p  ) 

Definition at line 1013 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01014 {if(fabs(*p)<sqrtminfloat){*--p=0;return;};
01015     if(*p==ErrVal||fabs(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01016     if(fabs(*(--p))<sqrtminfloat){*p=0;return;};
01017     if(*p==ErrVal||fabs(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01018     *p*=(*(p+1));}

Here is the caller graph for this function:

void NextVal ( float *&   ) 

Definition at line 1045 of file mathexpr.cpp.

Referenced by COperation::BuildCode(), ROperation::BuildCode(), COperation::Val(), and ROperation::Val().

01045 {}

Here is the caller graph for this function:

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

Definition at line 292 of file mathexpr.cpp.

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

00293 {
00294     if(op1.op==Num&&op2.op==Num)return op1.ValC*op2.ValC;
00295     if(op1==0.||op2==0.)return 0.;
00296     if(op1==1.)return op2;if(op2==1.)return op1;
00297     if(op1.op==Opp)return -(*(op1.mmb2)*op2);if(op2.op==Opp)return -(op1**(op2.mmb2));
00298     ROperation resultat;
00299     resultat.op=Mult;resultat.mmb1=new ROperation(op1);
00300     resultat.mmb2=new ROperation(op2);
00301     return resultat;
00302 }

Here is the call graph for this function:

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

Definition at line 239 of file mathexpr.cpp.

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

00240 {
00241     if(op1.op!=op2.op)return 1;
00242     if(op1.op==Var)return(op1.pvar!=op2.pvar);
00243     if(op1.op==Fun)return(!(op1.pfunc==op2.pfunc)); // *op1.pfunc==*op2.pfunc could imply infinite loops in cases of self-dependence
00244     if(op1.op==Num)return(op1.ValC!=op2.ValC);
00245     if(op1.mmb1==NULL&&op2.mmb1!=NULL)return 1;
00246     if(op1.mmb2==NULL&&op2.mmb2!=NULL)return 1;
00247     if(op2.mmb1==NULL&&op1.mmb1!=NULL)return 1;
00248     if(op2.mmb2==NULL&&op1.mmb2!=NULL)return 1;
00249     return(((op1.mmb1!=NULL||op2.mmb1!=NULL)&&(*(op1.mmb1)!=*(op2.mmb1)))||
00250            ((op1.mmb2!=NULL||op2.mmb2!=NULL)&&(*(op1.mmb2)!=*(op2.mmb2))));
00251 }

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

Definition at line 270 of file mathexpr.cpp.

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

00271 {
00272     if(op1.op==Num&&op2.op==Num)return op1.ValC+op2.ValC;
00273     if(op1==0.)return op2;if(op2==0.)return op1;
00274     if(op1.op==Opp)return op2-*(op1.mmb2);if(op2.op==Opp)return op1-*(op2.mmb2);
00275     ROperation resultat;
00276     resultat.op=Add;resultat.mmb1=new ROperation(op1);
00277     resultat.mmb2=new ROperation(op2);
00278     return resultat;
00279 }

Here is the call graph for this function:

ROperation operator, ( const ROperation op1,
const ROperation op2 
)

Definition at line 263 of file mathexpr.cpp.

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

00264 {ROperation resultat;
00265     resultat.op=Juxt;resultat.mmb1=new ROperation(op1);
00266     resultat.mmb2=new ROperation(op2);
00267     return resultat;
00268 }

Here is the call graph for this function:

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

Definition at line 281 of file mathexpr.cpp.

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

00282 {
00283     if(op1.op==Num&&op2.op==Num)return op1.ValC-op2.ValC;
00284     if(op1==0.)return -op2;if(op2==0.)return op1;
00285     if(op1.op==Opp)return -(op2+*(op1.mmb2));if(op2.op==Opp)return op1+*(op2.mmb2);
00286     ROperation resultat;
00287     resultat.op=Sub;resultat.mmb1=new ROperation(op1);
00288     resultat.mmb2=new ROperation(op2);
00289     return resultat;
00290 }

Here is the call graph for this function:

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

Definition at line 304 of file mathexpr.cpp.

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

00305 {if(op1.op==Num&&op2.op==Num)return (op2.ValC?op1.ValC/op2.ValC:ErrVal);
00306     if(op1==0.0)return 0.;if(op2==1.)return op1;if(op2==0.)return ErrVal;
00307     if(op1.op==Opp)return -(*(op1.mmb2)/op2);if(op2.op==Opp)return -(op1/(*(op2.mmb2)));
00308     ROperation resultat;
00309     resultat.op=Div;resultat.mmb1=new ROperation(op1);
00310     resultat.mmb2=new ROperation(op2);
00311     return resultat;
00312 }

Here is the call graph for this function:

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

Definition at line 685 of file mathexpr.cpp.

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

00686 {
00687     if(f1.type!=f2.type)return 0;
00688     if(f1.type==-1)return 1; // Nonfunction==nonfunction
00689     if(f1.type==0)return (f1.pfuncval==f2.pfuncval&&EqStr(f1.name,f2.name));
00690     if(f1.op!=f2.op)return 0;
00691     if(!EqStr(f1.name,f2.name))return 0;
00692     if(f1.nvars!=f2.nvars)return 0;
00693     int i;
00694     for(i=0;i<f1.nvars;i++)if(!(*f1.ppvar[i]==*f2.ppvar[i]))return 0;
00695     return 1;
00696 }

Here is the call graph for this function:

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

Definition at line 681 of file mathexpr.cpp.

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

00682 {return(var1.pval==var2.pval&&EqStr(var1.name,var2.name));
00683 }

Here is the call graph for this function:

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

Definition at line 226 of file mathexpr.cpp.

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

00227 {if(op1.op!=op2.op)return 0;
00228     if(op1.op==Var)return(*(op1.pvar)==*(op2.pvar));
00229     if(op1.op==Fun)return(op1.pfunc==op2.pfunc); // *op1.pfunc==*op2.pfunc could imply infinite loops in cases of self-dependence
00230     if(op1.op==Num)return(op1.ValC==op2.ValC);
00231     if(op1.mmb1==NULL&&op2.mmb1!=NULL)return 0;
00232     if(op1.mmb2==NULL&&op2.mmb2!=NULL)return 0;
00233     if(op2.mmb1==NULL&&op1.mmb1!=NULL)return 0;
00234     if(op2.mmb2==NULL&&op1.mmb2!=NULL)return 0;
00235     return(((op1.mmb1==NULL&&op2.mmb1==NULL)||(*(op1.mmb1)==*(op2.mmb1)))&&
00236            ((op1.mmb2==NULL&&op2.mmb2==NULL)||(*(op1.mmb2)==*(op2.mmb2))));
00237 }

int operator== ( const ROperation op,
const float  v 
)

Definition at line 223 of file mathexpr.cpp.

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

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

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

Definition at line 314 of file mathexpr.cpp.

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

00315 {if(op1==0.)return 0.;
00316     if(op2==0.)return 1.;
00317     if(op2==1.)return op1;
00318     ROperation resultat;
00319     resultat.op=Pow;resultat.mmb1=new ROperation(op1);
00320     resultat.mmb2=new ROperation(op2);
00321     return resultat;
00322 }

Here is the call graph for this function:

void Oppose ( float *&  p  ) 

Definition at line 1049 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

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

Here is the caller graph for this function:

void Puiss10 ( float *&  p  ) 

Definition at line 1035 of file mathexpr.cpp.

References ErrVal, and pow10().

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01036 {if(fabs(*p)<sqrtminfloat){*(--p)=0;return;};
01037     if(*p==ErrVal||fabs(*p)>DBL_MAX_10_EXP){*(--p)=ErrVal;return;};
01038     if(fabs(*(--p))<sqrtminfloat)*p=0;else if(*p==ErrVal||fabs(*p)>sqrtmaxfloat)
01039     {*p=ErrVal;return;};
01040     *p*=pow10(*(p+1));}

Here is the call graph for this function:

Here is the caller graph for this function:

void Puissance ( float *&  p  ) 

Definition at line 1025 of file mathexpr.cpp.

References ErrVal, and ROperation::log.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01026 {float v2=*p--,v1=*p;
01027     if(!v1){*p=0;return;};
01028     if(v2==ErrVal||v1==ErrVal||fabs(v2*log(fabs(v1)))>DBL_MAX_EXP){*p=ErrVal;return;};
01029     *p=((v1>0||!fmod(v2,1))?pow(v1,v2):ErrVal);}

Here is the caller graph for this function:

void Racine ( float *&  p  ) 

Definition at line 1066 of file mathexpr.cpp.

References ErrVal, and ROperation::sqrt.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01067 {*p=((*p==ErrVal||*p>sqrtmaxfloat||*p<0)?ErrVal:sqrt(*p));}

Here is the caller graph for this function:

void RacineN ( float *&  p  ) 

Definition at line 1030 of file mathexpr.cpp.

References ErrVal, and ROperation::log.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01031 {float v2=*p--,v1=*p;
01032     if(v1==ErrVal||v2==ErrVal||!v1||v2*log(fabs(v1))<DBL_MIN_EXP){*p=ErrVal;return;};
01033     if(v2>=0){*p=pow(v2,1/v1);return;};
01034     *p=((fabs(fmod(v1,2))==1)?-pow(-v2,1/v1):ErrVal);}

Here is the caller graph for this function:

void RFunc ( float *&   ) 

Definition at line 1046 of file mathexpr.cpp.

Referenced by BCFun(), COperation::Val(), and ROperation::Val().

01046 {}

Here is the caller graph for this function:

int SearchCorClosebracket ( char *  s,
int  n 
)

Definition at line 403 of file mathexpr.cpp.

References c.

Referenced by SearchOperator().

00404 {if(n<1)return -1;
00405     int i,c=1;
00406     for(i=n-1;i>=0;i--){
00407         if(s[i]==')')c++;else if(s[i]=='(')c--;
00408         if(!c)return i;
00409     };
00410     return -1;
00411 }

Here is the caller graph for this function:

int SearchCorOpenbracket ( char *  s,
int  n 
)

Definition at line 393 of file mathexpr.cpp.

References c.

Referenced by COperation::COperation(), IsolateNumbers(), IsolateVars(), ROperation::ROperation(), and SimplifyStr().

00394 {if(n>=(int)strlen(s)-1)return -1;
00395     int i,c=1;
00396     for(i=n+1;s[i];i++){
00397         if(s[i]=='(')c++;else if(s[i]==')')c--;
00398         if(!c)return i;
00399     };
00400     return -1;
00401 }

Here is the caller graph for this function:

int SearchOperator ( char *  s,
ROperator  op 
)

Definition at line 413 of file mathexpr.cpp.

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

Referenced by COperation::COperation(), and ROperation::ROperation().

00414 {
00415     char opc;
00416     switch(op){
00417 case ErrOp:case Num:case Var:return -1;
00418     case Juxt:opc=',';break;
00419     case Add:opc='+';break;
00420     case Sub:opc='-';break;
00421     case Mult:opc='*';break;
00422     case Div:opc='/';break;
00423     case Pow:opc='^';break;
00424     case NthRoot:opc='#';break;
00425     case E10:opc='E';break;
00426     default:return -1;
00427     };
00428     int i;
00429     for(i=(int)strlen(s)-1;i>=0;i--){
00430         if(s[i]==opc&&(op!=Sub||i&&s[i-1]==')'))return i;
00431     if(s[i]==')'){i=SearchCorClosebracket(s,i);if(i==-1)return -1;};
00432     };
00433     return -1;
00434 }

Here is the call graph for this function:

Here is the caller graph for this function:

void SimplifyStr ( char *&  s  ) 

Definition at line 436 of file mathexpr.cpp.

References CopyStr(), and SearchCorOpenbracket().

Referenced by COperation::COperation(), ROperation::ROperation(), and SimplifyStr().

00436                                     : deletes the old string
00437 {if(!strlen(s))return;
00438     char*s1=s,*s2=s+strlen(s);signed char ind=0;
00439     if(s1[0]=='('&&SearchCorOpenbracket(s1,0)==s2-s1-1){
00440         s1++;s2--;ind=1;}
00441     if(s1==s2)
00442     {
00443         delete[]s;
00444         s=new char[1]; // ISO C++ forbids initialization in array new
00445         s[0]=0;
00446         return;
00447     }
00448     if(s1[0]==' '){ind=1;while(s1[0]==' '&&s1<s2)s1++;}
00449     if(s1==s2)
00450     {
00451         delete[]s;
00452         s=new char[1]; // ISO C++ forbids initialization in array new
00453         s[0]=0;
00454         return;
00455     }
00456     if(*(s2-1)==' '){ind=1;while(s2>s1&&*(s2-1)==' ')s2--;}
00457     *s2=0;
00458     s1=CopyStr(s1);delete[]s;s=s1;
00459     if(ind)SimplifyStr(s);
00460 }

Here is the call graph for this function:

Here is the caller graph for this function:

ROperation sin ( const ROperation op  ) 

Definition at line 328 of file mathexpr.cpp.

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

Referenced by cWidget::Map::ClipperCircle::Begin(), eCamera::nextDirIfGlancing(), paint_sr_lowerSky(), zShapeCircle::render(), gZone::Render(), gCycle::Render(), zShapeCircle::render2d(), gZone::Render2D(), cWidget::NeedleGauge::RenderGraph(), uMenuItem::SetColor(), sinf(), tan(), and gZone::Timestep().

00329 {ROperation rop;rop.op=Sin;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Sinus ( float *&  p  ) 

Definition at line 1060 of file mathexpr.cpp.

References ErrVal, and ROperation::sin.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01061 {*p=((*p==ErrVal||fabs(*p)>inveps)?ErrVal:sin(*p));}

Here is the caller graph for this function:

void Soustraction ( float *&  p  ) 

Definition at line 1009 of file mathexpr.cpp.

References ErrVal.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01010 {if(*p==ErrVal||fabs(*p)>sqrtmaxfloat){*(--p)=ErrVal;return;};
01011     if(*(--p)==ErrVal||fabs(*p)>sqrtmaxfloat){*p=ErrVal;return;};
01012     *p-=(*(p+1));}

Here is the caller graph for this function:

ROperation sqrt ( const ROperation op  ) 

Definition at line 324 of file mathexpr.cpp.

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

Referenced by acos(), eCamera::Act(), ePath::Add(), asin(), atan(), eWall::CalcLen(), gLogo::Display(), Distance(), EdgePenalty(), gAIPlayer::EmergencySurvive(), eHalfEdge::FindPath(), gNetPlayerWall::InitArray(), eCameraSensor::LookAround(), eCamera::MyInit(), gCycle::MyInitAfterCreation(), tCoord::Norm(), Vec3::Norm(), gCycle::ReadSync(), gCycle::Render(), eCamera::Render(), eTimer::Reset(), rotate(), S_BlowHoles(), eChannel::Set3d(), sqrtf(), gAIPlayer::Think(), gAIPlayer::ThinkPath(), gExplosion::Timestep(), eCamera::Timestep(), and gCycle::TimestepCore().

00325 {ROperation rop;rop.op=Sqrt;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void SupprSpaces ( char *&  s  ) 

Definition at line 377 of file mathexpr.cpp.

References DelStr().

Referenced by COperation::COperation(), and ROperation::ROperation().

00378 {
00379     int i;
00380     for(i=0;s[i];i++)if(s[i]==' '||s[i]=='\t'||s[i]=='\n')DelStr(s,i--);
00381 }

Here is the call graph for this function:

Here is the caller graph for this function:

ROperation tan ( const ROperation op  ) 

Definition at line 332 of file mathexpr.cpp.

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

Referenced by rViewport::Perspective(), tanf(), and rViewport::UpDownFOV().

00333 {ROperation rop;rop.op=Tg;rop.mmb2=new ROperation(op);return rop;}

Here is the call graph for this function:

Here is the caller graph for this function:

void Tangente ( float *&  p  ) 

Definition at line 1062 of file mathexpr.cpp.

References ErrVal, and ROperation::tan.

Referenced by COperation::BuildCode(), and ROperation::BuildCode().

01063 {*p=((*p==ErrVal||fabs(*p)>inveps)?ErrVal:tan(*p));}

Here is the caller graph for this function:

char* ValToStr ( float  x  ) 

Definition at line 864 of file mathexpr.cpp.

Referenced by ROperation::Expr().

00865 {
00866     char*s=new char[30];
00867     if(x==(float)3.141592653589793238462643383279L)sprintf(s,"pi");else sprintf(s,"%.16G",x);
00868     return s;
00869 }

Here is the caller graph for this function:


Variable Documentation

const float inveps = .1/DBL_EPSILON

Definition at line 1003 of file mathexpr.cpp.

const float sqrtmaxfloat = sqrt(DBL_MAX)

Definition at line 1001 of file mathexpr.cpp.

const float sqrtminfloat = sqrt(DBL_MIN)

Definition at line 1002 of file mathexpr.cpp.


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