Kaydet (Commit) a77223b2 authored tarafından Caolán McNamara's avatar Caolán McNamara

rearrange SwCalc some more

Change-Id: Ib1ffc112ddd006102b29536f7433a3f16bf63a3f
üst 9b2a24b9
...@@ -174,6 +174,7 @@ class SwCalc ...@@ -174,6 +174,7 @@ class SwCalc
SwCalcOper GetToken(); SwCalcOper GetToken();
SwSbxValue Expr(); SwSbxValue Expr();
SwSbxValue Term(); SwSbxValue Term();
SwSbxValue PrimFunc(bool &rChkPow);
SwSbxValue Prim(); SwSbxValue Prim();
SwSbxValue StdFunc(pfCalc pFnc, bool bChkTrig); SwSbxValue StdFunc(pfCalc pFnc, bool bChkTrig);
......
...@@ -1042,36 +1042,34 @@ SwSbxValue SwCalc::StdFunc(pfCalc pFnc, bool bChkTrig) ...@@ -1042,36 +1042,34 @@ SwSbxValue SwCalc::StdFunc(pfCalc pFnc, bool bChkTrig)
return nErg; return nErg;
} }
SwSbxValue SwCalc::Prim() SwSbxValue SwCalc::PrimFunc(bool &rChkPow)
{ {
SwSbxValue nErg; rChkPow = false;
bool bChkPow = false;
switch (m_eCurrOper) switch (m_eCurrOper)
{ {
case CALC_SIN: case CALC_SIN:
nErg = StdFunc(&sin, false); return StdFunc(&sin, false);
break; break;
case CALC_COS: case CALC_COS:
nErg = StdFunc(&cos, false); return StdFunc(&cos, false);
break; break;
case CALC_TAN: case CALC_TAN:
nErg = StdFunc(&tan, false); return StdFunc(&tan, false);
break; break;
case CALC_ATAN: case CALC_ATAN:
nErg = StdFunc(&atan, false); return StdFunc(&atan, false);
break; break;
case CALC_ASIN: case CALC_ASIN:
nErg = StdFunc(&asin, true); return StdFunc(&asin, true);
break; break;
case CALC_ACOS: case CALC_ACOS:
nErg = StdFunc(&acos, true); return StdFunc(&acos, true);
break; break;
case CALC_NOT: case CALC_NOT:
{ {
GetToken(); GetToken();
nErg = Prim(); SwSbxValue nErg = Prim();
if( SbxSTRING == nErg.GetType() ) if( SbxSTRING == nErg.GetType() )
{ {
nErg.PutBool( nErg.GetOUString().isEmpty() ); nErg.PutBool( nErg.GetOUString().isEmpty() );
...@@ -1092,10 +1090,12 @@ SwSbxValue SwCalc::Prim() ...@@ -1092,10 +1090,12 @@ SwSbxValue SwCalc::Prim()
//!! computes a binary NOT //!! computes a binary NOT
nErg.Compute( SbxNOT, nErg ); nErg.Compute( SbxNOT, nErg );
} }
return nErg;
break; break;
} }
case CALC_NUMBER: case CALC_NUMBER:
{ {
SwSbxValue nErg;
if( GetToken() == CALC_PHD ) if( GetToken() == CALC_PHD )
{ {
double aTmp = m_nNumberValue.GetDouble(); double aTmp = m_nNumberValue.GetDouble();
...@@ -1110,12 +1110,14 @@ SwSbxValue SwCalc::Prim() ...@@ -1110,12 +1110,14 @@ SwSbxValue SwCalc::Prim()
else else
{ {
nErg = m_nNumberValue; nErg = m_nNumberValue;
bChkPow = true; rChkPow = true;
} }
return nErg;
break; break;
} }
case CALC_NAME: case CALC_NAME:
{ {
SwSbxValue nErg;
switch(SwCalcOper eOper = GetToken()) switch(SwCalcOper eOper = GetToken())
{ {
case CALC_ASSIGN: case CALC_ASSIGN:
...@@ -1132,19 +1134,24 @@ SwSbxValue SwCalc::Prim() ...@@ -1132,19 +1134,24 @@ SwSbxValue SwCalc::Prim()
if (nErg.IsVoidValue() && (eOper == CALC_LP)) if (nErg.IsVoidValue() && (eOper == CALC_LP))
m_eError = CALC_SYNTAX; m_eError = CALC_SYNTAX;
else else
bChkPow = true; rChkPow = true;
break; break;
} }
return nErg;
break; break;
} }
case CALC_MINUS: case CALC_MINUS:
{
SwSbxValue nErg;
GetToken(); GetToken();
nErg.PutDouble( -(Prim().GetDouble()) ); nErg.PutDouble( -(Prim().GetDouble()) );
return nErg;
break; break;
}
case CALC_LP: case CALC_LP:
{ {
GetToken(); GetToken();
nErg = Expr(); SwSbxValue nErg = Expr();
if( m_eCurrOper != CALC_RP ) if( m_eCurrOper != CALC_RP )
{ {
m_eError = CALC_BRACK; m_eError = CALC_BRACK;
...@@ -1152,46 +1159,64 @@ SwSbxValue SwCalc::Prim() ...@@ -1152,46 +1159,64 @@ SwSbxValue SwCalc::Prim()
else else
{ {
GetToken(); GetToken();
bChkPow = true; // in order for =(7)^2 to work rChkPow = true; // in order for =(7)^2 to work
} }
return nErg;
break; break;
} }
case CALC_MEAN: case CALC_MEAN:
{ {
m_nListPor = 1; m_nListPor = 1;
GetToken(); GetToken();
nErg = Expr(); SwSbxValue nErg = Expr();
double aTmp = nErg.GetDouble(); double aTmp = nErg.GetDouble();
aTmp /= m_nListPor; aTmp /= m_nListPor;
nErg.PutDouble( aTmp ); nErg.PutDouble( aTmp );
return nErg;
break; break;
} }
case CALC_SQRT: case CALC_SQRT:
{ {
GetToken(); GetToken();
nErg = Prim(); SwSbxValue nErg = Prim();
if( nErg.GetDouble() < 0 ) if( nErg.GetDouble() < 0 )
m_eError = CALC_OVERFLOW; m_eError = CALC_OVERFLOW;
else else
nErg.PutDouble( sqrt( nErg.GetDouble() )); nErg.PutDouble( sqrt( nErg.GetDouble() ));
return nErg;
break; break;
} }
case CALC_SUM: case CALC_SUM:
case CALC_DATE: case CALC_DATE:
case CALC_MIN: case CALC_MIN:
case CALC_MAX: case CALC_MAX:
{
GetToken(); GetToken();
nErg = Expr(); SwSbxValue nErg = Expr();
return nErg;
break; break;
}
case CALC_ENDCALC: case CALC_ENDCALC:
{
SwSbxValue nErg;
nErg.Clear(); nErg.Clear();
return nErg;
break; break;
}
default: default:
m_eError = CALC_SYNTAX; m_eError = CALC_SYNTAX;
break; break;
} }
if( bChkPow && m_eCurrOper == CALC_POW ) return SwSbxValue();
}
SwSbxValue SwCalc::Prim()
{
bool bChkPow;
SwSbxValue nErg = PrimFunc(bChkPow);
if (bChkPow && m_eCurrOper == CALC_POW)
{ {
double dleft = nErg.GetDouble(); double dleft = nErg.GetDouble();
GetToken(); GetToken();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment