Commit 3268f2b4 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

fix: Bug 26172 - Расчет функции производится если комплексное число имеет некорректный формат

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58538 954022d7-b5bf-4e40-9824-e11837661b57
parent 7f9e90d5
...@@ -644,7 +644,7 @@ Complex.prototype = { ...@@ -644,7 +644,7 @@ Complex.prototype = {
return new cError( cErrorType.not_numeric ); return new cError( cErrorType.not_numeric );
} }
switch ( pStr.pStr[0] ) { switch ( pStr.pStr[0]+"" ) {
case '-': // imag part follows case '-': // imag part follows
case '+': case '+':
{ {
...@@ -677,7 +677,7 @@ Complex.prototype = { ...@@ -677,7 +677,7 @@ Complex.prototype = {
return this; return this;
} }
break; break;
case 0: // only real-part case "undefined": // only real-part
this.real = f.f; this.real = f.f;
this.img = 0.0; this.img = 0.0;
return this; return this;
...@@ -686,22 +686,22 @@ Complex.prototype = { ...@@ -686,22 +686,22 @@ Complex.prototype = {
}, },
ParseDouble:function ( rp, rRet ) { ParseDouble:function ( rp, rRet ) {
function IsNum( c ) { function isnum( c ) {
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
function IsComma( c ) { function iscomma( c ) {
return c == '.' || c == ','; return c == '.' || c == ',';
} }
function IsExpStart( c ) { function isexpstart( c ) {
return c == 'e' || c == 'E'; return c == 'e' || c == 'E';
} }
function IsImagUnit( c ) { function isimagunit( c ) {
return c == 'i' || c == 'j'; return c == 'i' || c == 'j';
} }
...@@ -712,16 +712,16 @@ Complex.prototype = { ...@@ -712,16 +712,16 @@ Complex.prototype = {
nMaxExp = 307, nMaxExp = 307,
nDigCnt = 18, // max. number of digits to read in, rest doesn't matter nDigCnt = 18, // max. number of digits to read in, rest doesn't matter
State = { State = {
S_End:0, end:0,
S_Sign:1, sign:1,
S_IntStart:2, intstart:2,
S_Int:3, int:3,
S_IgnoreIntDigs:4, ignoreintdigs:4,
S_Frac:5, frac:5,
S_IgnoreFracDigs:6, ignorefracdigs:6,
S_ExpSign:7, expsign:7,
S_Exp:8 exp:8
}, eS = State.S_Sign, }, eS = State.sign,
bNegNum = false, bNegNum = false,
bNegExp = false, bNegExp = false,
p = rp.pStr, c, i = 0; p = rp.pStr, c, i = 0;
...@@ -729,36 +729,36 @@ Complex.prototype = { ...@@ -729,36 +729,36 @@ Complex.prototype = {
while ( eS ) { while ( eS ) {
c = p[i]; c = p[i];
switch ( eS ) { switch ( eS ) {
case State.S_Sign: case State.sign:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
fInt = parseFloat( c ); fInt = parseFloat( c );
nDigCnt--; nDigCnt--;
eS = State.S_Int; eS = State.int;
} }
else if ( c == '-' ) { else if ( c == '-' ) {
bNegNum = true; bNegNum = true;
eS = State.S_IntStart; eS = State.intstart;
} }
else if ( c == '+' ) { else if ( c == '+' ) {
eS = State.S_IntStart; eS = State.intstart;
} }
else if ( IsComma( c ) ) { else if ( iscomma( c ) ) {
eS = State.S_Frac; eS = State.frac;
} }
else { else {
return false; return false;
} }
break; break;
case State.S_IntStart: case State.intstart:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
fInt = parseFloat( c ); fInt = parseFloat( c );
nDigCnt--; nDigCnt--;
eS = State.S_Int; eS = State.int;
} }
else if ( IsComma( c ) ) { else if ( iscomma( c ) ) {
eS = State.S_Frac; eS = State.frac;
} }
else if ( IsImagUnit( c ) ) { else if ( isimagunit( c ) ) {
rRet.f = 0.0; rRet.f = 0.0;
return true; return true;
} }
...@@ -766,80 +766,80 @@ Complex.prototype = { ...@@ -766,80 +766,80 @@ Complex.prototype = {
return false; return false;
} }
break; break;
case State.S_Int: case State.int:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
fInt *= 10.0; fInt *= 10.0;
fInt += parseFloat( c ); fInt += parseFloat( c );
nDigCnt--; nDigCnt--;
if ( !nDigCnt ) { if ( !nDigCnt ) {
eS = State.S_IgnoreIntDigs; eS = State.ignoreintdigs;
} }
} }
else if ( IsComma( c ) ) { else if ( iscomma( c ) ) {
eS = State.S_Frac; eS = State.frac;
} }
else if ( IsExpStart( c ) ) { else if ( isexpstart( c ) ) {
eS = State.S_ExpSign; eS = State.expsign;
} }
else { else {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_IgnoreIntDigs: case State.ignoreintdigs:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
nExp++; nExp++;
} // just multiply num with 10... ;-) } // just multiply num with 10... ;-)
else if ( IsComma( c ) ) { else if ( iscomma( c ) ) {
eS = State.S_Frac; eS = State.frac;
} }
else if ( IsExpStart( c ) ) { else if ( isexpstart( c ) ) {
eS = State.S_ExpSign; eS = State.expsign;
} }
else { else {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_Frac: case State.frac:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
fFrac += parseFloat( c ) * fMult; fFrac += parseFloat( c ) * fMult;
nDigCnt--; nDigCnt--;
if ( nDigCnt ) { if ( nDigCnt ) {
fMult *= 0.1; fMult *= 0.1;
} }
else { else {
eS = State.S_IgnoreFracDigs; eS = State.ignorefracdigs;
} }
} }
else if ( IsExpStart( c ) ) { else if ( isexpstart( c ) ) {
eS = State.S_ExpSign; eS = State.expsign;
} }
else { else {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_IgnoreFracDigs: case State.ignorefracdigs:
if ( IsExpStart( c ) ) { if ( isexpstart( c ) ) {
eS = State.S_ExpSign; eS = State.expsign;
} }
else if ( !IsNum( c ) ) { else if ( !isnum( c ) ) {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_ExpSign: case State.expsign:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
nExp = parseFloat( c ); nExp = parseFloat( c );
eS = State.S_Exp; eS = State.exp;
} }
else if ( c == '-' ) { else if ( c == '-' ) {
bNegExp = true; bNegExp = true;
eS = State.S_Exp; eS = State.exp;
} }
else if ( c != '+' ) { else if ( c != '+' ) {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_Exp: case State.exp:
if ( IsNum( c ) ) { if ( isnum( c ) ) {
nExp *= 10; nExp *= 10;
nExp += parseFloat( c ); nExp += parseFloat( c );
if ( nExp > nMaxExp ) { if ( nExp > nMaxExp ) {
...@@ -847,10 +847,10 @@ Complex.prototype = { ...@@ -847,10 +847,10 @@ Complex.prototype = {
} }
} }
else { else {
eS = State.S_End; eS = State.end;
} }
break; break;
case State.S_End: // to avoid compiler warning case State.end: // to avoid compiler warning
break; // loop exits anyway break; // loop exits anyway
} }
......
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