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

fixed:

Bug 24881 - Функции VAR/VARA/VARPA выдают нулевой результат если аргументы пустые

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56891 954022d7-b5bf-4e40-9824-e11837661b57
parent dc01c8f5
...@@ -4982,6 +4982,10 @@ cVAR.prototype.Calculate = function ( arg ) { ...@@ -4982,6 +4982,10 @@ cVAR.prototype.Calculate = function ( arg ) {
function _var( x ) { function _var( x ) {
if( x.length < 1 ){
return new cError( cErrorType.division_by_zero );
}
var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0; var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) { for ( var i = 0; i < x.length; i++ ) {
...@@ -5071,6 +5075,10 @@ cVARA.prototype.Calculate = function ( arg ) { ...@@ -5071,6 +5075,10 @@ cVARA.prototype.Calculate = function ( arg ) {
function _var( x ) { function _var( x ) {
if( x.length < 1 ){
return new cError( cErrorType.division_by_zero );
}
var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0; var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) { for ( var i = 0; i < x.length; i++ ) {
...@@ -5109,7 +5117,7 @@ cVARA.prototype.Calculate = function ( arg ) { ...@@ -5109,7 +5117,7 @@ cVARA.prototype.Calculate = function ( arg ) {
else if ( elem instanceof cBool ) { else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() ); arr0.push( elem.tocNumber() );
} }
else { else if ( elem instanceof cString ) {
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} ); } );
...@@ -5122,7 +5130,7 @@ cVARA.prototype.Calculate = function ( arg ) { ...@@ -5122,7 +5130,7 @@ cVARA.prototype.Calculate = function ( arg ) {
else if ( a instanceof cBool ) { else if ( a instanceof cBool ) {
arr0.push( a.tocNumber() ); arr0.push( a.tocNumber() );
} }
else { else if ( a instanceof cString ) {
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} }
...@@ -5134,7 +5142,7 @@ cVARA.prototype.Calculate = function ( arg ) { ...@@ -5134,7 +5142,7 @@ cVARA.prototype.Calculate = function ( arg ) {
else if ( elem instanceof cBool ) { else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() ); arr0.push( elem.tocNumber() );
} }
else { else if ( a instanceof cString ) {
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} ); } );
...@@ -5142,11 +5150,12 @@ cVARA.prototype.Calculate = function ( arg ) { ...@@ -5142,11 +5150,12 @@ cVARA.prototype.Calculate = function ( arg ) {
else if ( arg[j] instanceof cNumber || arg[j] instanceof cBool ) { else if ( arg[j] instanceof cNumber || arg[j] instanceof cBool ) {
arr0.push( arg[j].tocNumber() ); arr0.push( arg[j].tocNumber() );
} }
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) { else if ( arg[j] instanceof cString ){
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
else else if ( arg[j] instanceof cError ){
return this.value = cError( cErrorType.wrong_value_type ) return this.value = cError( cErrorType.wrong_value_type )
}
} }
return this.value = _var( arr0 ); return this.value = _var( arr0 );
...@@ -5180,12 +5189,16 @@ cVARP.prototype.Calculate = function ( arg ) { ...@@ -5180,12 +5189,16 @@ cVARP.prototype.Calculate = function ( arg ) {
function _var( x ) { function _var( x ) {
if( x.length < 1 ){
return new cError( cErrorType.division_by_zero );
}
var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0; var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) { for ( var i = 0; i < x.length; i++ ) {
if ( x[i] instanceof cNumber ) { if ( x[i] instanceof cNumber ) {
_x += x[i].getValue(); _x += x[i].getValue();
tA.push( x[i].getValue() ) tA.push( x[i].getValue() );
xLength++; xLength++;
} }
else if ( x[i] instanceof cError ) { else if ( x[i] instanceof cError ) {
...@@ -5198,11 +5211,11 @@ cVARP.prototype.Calculate = function ( arg ) { ...@@ -5198,11 +5211,11 @@ cVARP.prototype.Calculate = function ( arg ) {
for ( var i = 0; i < x.length; i++ ) { for ( var i = 0; i < x.length; i++ ) {
sumSQRDeltaX += (tA[i] - _x) * (tA[i] - _x) sumSQRDeltaX += (tA[i] - _x) * (tA[i] - _x);
} }
return new cNumber( sumSQRDeltaX / xLength ) return new cNumber( sumSQRDeltaX / xLength );
} }
...@@ -5271,6 +5284,10 @@ cVARPA.prototype.Calculate = function ( arg ) { ...@@ -5271,6 +5284,10 @@ cVARPA.prototype.Calculate = function ( arg ) {
function _var( x ) { function _var( x ) {
if( x.length < 1 ){
return new cError( cErrorType.division_by_zero );
}
var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0; var tA = [], sumSQRDeltaX = 0, _x = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) { for ( var i = 0; i < x.length; i++ ) {
...@@ -5309,7 +5326,7 @@ cVARPA.prototype.Calculate = function ( arg ) { ...@@ -5309,7 +5326,7 @@ cVARPA.prototype.Calculate = function ( arg ) {
else if ( elem instanceof cBool ) { else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() ); arr0.push( elem.tocNumber() );
} }
else { else if ( elem instanceof cString ){
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} ); } );
...@@ -5322,7 +5339,7 @@ cVARPA.prototype.Calculate = function ( arg ) { ...@@ -5322,7 +5339,7 @@ cVARPA.prototype.Calculate = function ( arg ) {
else if ( a instanceof cBool ) { else if ( a instanceof cBool ) {
arr0.push( a.tocNumber() ); arr0.push( a.tocNumber() );
} }
else { else if ( a instanceof cString ){
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} }
...@@ -5334,7 +5351,7 @@ cVARPA.prototype.Calculate = function ( arg ) { ...@@ -5334,7 +5351,7 @@ cVARPA.prototype.Calculate = function ( arg ) {
else if ( elem instanceof cBool ) { else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() ); arr0.push( elem.tocNumber() );
} }
else { else if ( elem instanceof cString ){
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
} ); } );
...@@ -5342,11 +5359,12 @@ cVARPA.prototype.Calculate = function ( arg ) { ...@@ -5342,11 +5359,12 @@ cVARPA.prototype.Calculate = function ( arg ) {
else if ( arg[j] instanceof cNumber || arg[j] instanceof cBool ) { else if ( arg[j] instanceof cNumber || arg[j] instanceof cBool ) {
arr0.push( arg[j].tocNumber() ); arr0.push( arg[j].tocNumber() );
} }
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) { else if ( arg[j] instanceof cString ){
arr0.push( new cNumber( 0 ) ); arr0.push( new cNumber( 0 ) );
} }
else else if ( elem instanceof cError ){
return this.value = cError( cErrorType.wrong_value_type ) return this.value = cError( cErrorType.wrong_value_type )
}
} }
return this.value = _var( arr0 ); return this.value = _var( arr0 );
......
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