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

добавлены функции:

AVEDEV, AVERAGEA, AVERAGEIF, BINOMDIST, CONFIDENCE, CORREL, COUNTA, COVAR, CRITBINOM
поправлены:
AVERAGE, MAX, MAXA, MIN, MINA

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48607 954022d7-b5bf-4e40-9824-e11837661b57
parent cf729774
......@@ -7,7 +7,7 @@
sData = data + "";
if ( c_oSerFormat.Signature === sData.substring( 0, c_oSerFormat.Signature.length ) ) {
var sUrlPath = "offlinedocs/";
var wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), null );
var wb = new Workbook( sUrlPath, new Asc.asc_CHandlersList(), {} );
wb.initGlobalObjects();
var oBinaryFileReader = new BinaryFileReader( sUrlPath );
oBinaryFileReader.Read( sData, wb );
......@@ -303,33 +303,64 @@
} )
test( "Test: \"SUM\"", function () {
oParser = new parserFormula( "SUM(S5:T5)", "A1", ws );
ws.getRange2( "S5" ).setValue( "=1" );
ws.getRange2( "S6" ).setValue( "=-1/Fact(2)" );
ws.getRange2( "S7" ).setValue( "=1/Fact(4)" );
ws.getRange2( "S8" ).setValue( "=-1/Fact(6)" );
oParser = new parserFormula( "SUM(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
// strictEqual( oParser.calculate().getValue(), 1-1/Math.fact(2)+1/Math.fact(4)-1/Math.fact(6) );
ok( Math.abs( oParser.calculate().getValue() - (1-1/Math.fact(2)+1/Math.fact(4)-1/Math.fact(6)) ) < dif );
} )
test( "Test: \"MAX\"", function () {
oParser = new parserFormula( "MAX(S5:T5)", "A1", ws );
ws.getRange2( "S5" ).setValue( "=1" );
ws.getRange2( "S6" ).setValue( "=-1/Fact(2)" );
ws.getRange2( "S7" ).setValue( "=1/Fact(4)" );
ws.getRange2( "S8" ).setValue( "=-1/Fact(6)" );
oParser = new parserFormula( "MAX(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
strictEqual( oParser.calculate().getValue(), 1 );
} )
test( "Test: \"MAXA\"", function () {
oParser = new parserFormula( "MAXA(S5:T5)", "A1", ws );
ws.getRange2( "S5" ).setValue( "=1" );
ws.getRange2( "S6" ).setValue( "=-1/Fact(2)" );
ws.getRange2( "S7" ).setValue( "=1/Fact(4)" );
ws.getRange2( "S8" ).setValue( "=-1/Fact(6)" );
oParser = new parserFormula( "MAXA(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
strictEqual( oParser.calculate().getValue(), 1 );
} )
test( "Test: \"MIN\"", function () {
oParser = new parserFormula( "MIN(S5:T5)", "A1", ws );
ws.getRange2( "S5" ).setValue( "=1" );
ws.getRange2( "S6" ).setValue( "=-1/Fact(2)" );
ws.getRange2( "S7" ).setValue( "=1/Fact(4)" );
ws.getRange2( "S8" ).setValue( "=-1/Fact(6)" );
oParser = new parserFormula( "MIN(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
strictEqual( oParser.calculate().getValue(), -1/Math.fact(2) );
} )
test( "Test: \"MINA\"", function () {
oParser = new parserFormula( "MINA(S5:T5)", "A1", ws );
ws.getRange2( "S5" ).setValue( "=1" );
ws.getRange2( "S6" ).setValue( "=-1/Fact(2)" );
ws.getRange2( "S7" ).setValue( "=1/Fact(4)" );
ws.getRange2( "S8" ).setValue( "=-1/Fact(6)" );
oParser = new parserFormula( "MINA(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
strictEqual( oParser.calculate().getValue(), -1/Math.fact(2) );
} )
test( "Test: SUM(S7:S9,{1,2,3})", function () {
......@@ -447,45 +478,6 @@
strictEqual( oParser.calculate().getValue(), "1,234,567" );
} )
test( "Test: \"COUNTIF\"", function () {
ws.getRange2( "A7" ).setValue( "3" );
ws.getRange2( "B7" ).setValue( "10" );
ws.getRange2( "C7" ).setValue( "7" );
ws.getRange2( "D7" ).setValue( "10" );
ws.getRange2( "A8" ).setValue( "apples" );
ws.getRange2( "B8" ).setValue( "oranges" );
ws.getRange2( "C8" ).setValue( "grapes" );
ws.getRange2( "D8" ).setValue( "melons" );
oParser = new parserFormula( "COUNTIF(A7:D7,\"=10\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A7:D7,\">5\")", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A7:D7,\"<>10\")", "C1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*es\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"??a*\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*l*\")", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
} )
test( "Test: \"REPLACE\"", function () {
oParser = new parserFormula( "REPLACE(\"abcdefghijk\",3,4,\"XY\")", "A2", ws );
......@@ -896,10 +888,11 @@
test( "Test: \"STDEV\"", function () {
function stdev() {
var average = 0, sum = 0, res = 0;
var average = 0, res = 0;
for ( var i = 0; i < arguments.length; i++ ) {
average += arguments[i] / arguments.length;
average += arguments[i];
}
average /= arguments.length;
for ( var i = 0; i < arguments.length; i++ ) {
res += (arguments[i] - average) * (arguments[i] - average);
}
......@@ -1470,7 +1463,274 @@
oParser = new parserFormula( "SERIESSUM(PI()/4,1,2,B2:B5)", "B7", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - (Math.PI / 4 - 1 / Math.fact( 3 ) * Math.pow( Math.PI / 4, 3 ) + 1 / Math.fact( 5 ) * Math.pow( Math.PI / 4, 5 ) - 1 / Math.fact( 7 ) * Math.pow( Math.PI / 4, 7 )) ) < dif );
// strictEqual( oParser.calculate().getValue(), Math.PI / 4 - 1 / Math.fact( 3 ) * Math.pow( Math.PI / 4, 3 ) + 1 / Math.fact( 5 ) * Math.pow( Math.PI / 4, 5 ) - 1 / Math.fact( 7 ) * Math.pow( Math.PI / 4, 7 ) );
} )
/*
* Statical Function
* */
test( "Test: \"AVEDEV\"", function () {
oParser = new parserFormula( "AVEDEV(-3.5,1.4,6.9,-4.5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4.075 );
oParser = new parserFormula( "AVEDEV({-3.5,1.4,6.9,-4.5})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4.075 );
oParser = new parserFormula( "AVEDEV(-3.5,1.4,6.9,-4.5,-0.3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.32 );
} )
test( "Test: \"AVERAGE\"", function () {
oParser = new parserFormula( "AVERAGE(1,2,3,4,5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "AVERAGE({1,2;3,4})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2.5 );
oParser = new parserFormula( "AVERAGE({1,2,3,4,5},6,\"7\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "AVERAGE({1,\"2\",TRUE,4})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2.5 );
} )
test( "Test: \"AVERAGEA\"", function () {
ws.getRange2( "E2" ).setValue( "TRUE" );
ws.getRange2( "E3" ).setValue( "FALSE" );
oParser = new parserFormula( "AVERAGEA(10,E1)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 10 );
oParser = new parserFormula( "AVERAGEA(10,E2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5.5 );
oParser = new parserFormula( "AVERAGEA(10,E3)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
} )
test( "Test: \"AVERAGEIF\"", function () {
ws.getRange2( "E2" ).setValue( "10" );
ws.getRange2( "E3" ).setValue( "20" );
ws.getRange2( "E4" ).setValue( "28" );
ws.getRange2( "E5" ).setValue( "30" );
oParser = new parserFormula( "AVERAGEIF(E2:E5,\">15\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 26 );
} )
test( "Test: \"BINOMDIST\"", function () {
function binomCoeff(n,k){
return Math.fact( n ) / (Math.fact( k ) * Math.fact( n - k ));
}
function binomdist(x,n,p){
x= parseInt(x);
n = parseInt(n);
return binomCoeff(n,x)*Math.pow(p,x)*Math.pow(1-p,n-x);
}
oParser = new parserFormula( "BINOMDIST(6,10,0.5,FALSE)", "A1", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - binomdist(6,10,0.5) ) < dif );
oParser = new parserFormula( "BINOMDIST(6,10,0.5,TRUE)", "A1", ws );
ok( oParser.parse() );
ok( Math.abs( oParser.calculate().getValue() - (function(){
var bm = 0;
for(var y = 0; y <= 6; y++){
bm+=binomdist(y,10,0.5)
}
return bm;
})() ) < dif );
oParser = new parserFormula( "BINOMDIST(11,10,0.5,FALSE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
} )
test( "Test: \"CONFIDENCE\"", function () {
oParser = new parserFormula( "CONFIDENCE(0.4,5,12)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.214775614397568 );
oParser = new parserFormula( "CONFIDENCE(0.75,9,7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.083909233527114 );
} )
test( "Test: \"CORREL\"", function () {
oParser = new parserFormula( "CORREL({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,\"f\"})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -0.988112020032211 );
oParser = new parserFormula( "CORREL({1;2;3},{4;5;\"E\"})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "CORREL({1,2},{1,\"e\"})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
} )
test( "Test: \"COUNT\"", function () {
ws.getRange2( "E2" ).setValue( "TRUE" );
oParser = new parserFormula( "COUNT({1,2,3,4,5})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "COUNT(1,2,3,4,5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "COUNT({1,2,3,4,5},6,\"7\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 7 );
oParser = new parserFormula( "COUNT(10,E150)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNT(10,E2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} )
test( "Test: \"COUNTA\"", function () {
ws.getRange2( "E2" ).setValue( "TRUE" );
oParser = new parserFormula( "COUNTA({1,2,3,4,5})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "COUNTA(1,2,3,4,5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 5 );
oParser = new parserFormula( "COUNTA({1,2,3,4,5},6,\"7\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 7 );
oParser = new parserFormula( "COUNTA(10,E150)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNTA(10,E2)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
} )
test( "Test: \"COUNTIF\"", function () {
ws.getRange2( "A7" ).setValue( "3" );
ws.getRange2( "B7" ).setValue( "10" );
ws.getRange2( "C7" ).setValue( "7" );
ws.getRange2( "D7" ).setValue( "10" );
ws.getRange2( "A8" ).setValue( "apples" );
ws.getRange2( "B8" ).setValue( "oranges" );
ws.getRange2( "C8" ).setValue( "grapes" );
ws.getRange2( "D8" ).setValue( "melons" );
oParser = new parserFormula( "COUNTIF(A7:D7,\"=10\")", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A7:D7,\">5\")", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A7:D7,\"<>10\")", "C1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*es\")", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"??a*\")", "B2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "COUNTIF(A8:D8,\"*l*\")", "C2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
} )
test( "Test: \"COVAR\"", function () {
oParser = new parserFormula( "COVAR({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,6.7})", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1.3753740625 );
oParser = new parserFormula( "COVAR({1,2};{4,5})", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.25 );
} )
test( "Test: \"CRITBINOM\"", function () {
oParser = new parserFormula( "CRITBINOM(6,0.5,0.75)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "CRITBINOM(12,0.3,0.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6 );
oParser = new parserFormula( "CRITBINOM(-12,0.3,0.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "CRITBINOM(-12,1.3,0.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "CRITBINOM(-12,-1.3,0.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "CRITBINOM(-12,0,0.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
oParser = new parserFormula( "CRITBINOM(-12,0.3,1.95)", "B1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#NUM!" );
} )
......
......@@ -6,17 +6,17 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Information = {
'groupName' : "Information",
"ERROR.TYPE" :function(){
var r = new cBaseFunction("ERROR.TYPE");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
function typeError(elem){
'groupName':"Information",
"ERROR.TYPE":function () {
var r = new cBaseFunction( "ERROR.TYPE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
function typeError( elem ) {
if ( !(elem instanceof cError) )
return new cError( cErrorType.not_available );
else {
switch (elem.errorType){
switch ( elem.errorType ) {
case cErrorType.null_value:
return new cNumber( 1 );
case cErrorType.division_by_zero:
......@@ -38,23 +38,26 @@ cFormulaFunction.Information = {
}
}
}
var arg0 = arg[0];
if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cArray ){
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cArray ) {
var ret = new cArray();
arg0.foreach(function(elem,r,c){
if(!ret.array[r])
arg0.foreach( function ( elem, r, c ) {
if ( !ret.array[r] )
ret.addRow();
ret.addElement(found_operand)
})
ret.addElement( found_operand )
} )
return this.value = ret;
}
return this.value = typeError(arg0);
return this.value = typeError( arg0 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -62,23 +65,24 @@ cFormulaFunction.Information = {
}
return r;
},
"ISBLANK" :function(){
var r = new cBaseFunction("ISBLANK");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISBLANK":function () {
var r = new cBaseFunction( "ISBLANK" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if ( arg0 instanceof cEmpty)
if ( arg0 instanceof cEmpty )
return this.value = new cBool( true );
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -86,17 +90,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISERR" :function(){
var r = new cBaseFunction("ISERR");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISERR":function () {
var r = new cBaseFunction( "ISERR" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -105,7 +111,7 @@ cFormulaFunction.Information = {
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -113,17 +119,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISERROR" :function(){
var r = new cBaseFunction("ISERROR");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISERROR":function () {
var r = new cBaseFunction( "ISERROR" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -132,7 +140,7 @@ cFormulaFunction.Information = {
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -140,17 +148,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISEVEN" :function(){
var r = new cBaseFunction("ISEVEN");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISEVEN":function () {
var r = new cBaseFunction( "ISEVEN" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -163,7 +173,7 @@ cFormulaFunction.Information = {
else
return this.value = new cBool( (arg0.getValue() & 1) == 0 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(number)"
......@@ -171,17 +181,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISLOGICAL" :function(){
var r = new cBaseFunction("ISLOGICAL");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISLOGICAL":function () {
var r = new cBaseFunction( "ISLOGICAL" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -189,7 +201,7 @@ cFormulaFunction.Information = {
return this.value = new cBool( true );
else return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -197,17 +209,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISNA" :function(){
var r = new cBaseFunction("ISNA");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISNA":function () {
var r = new cBaseFunction( "ISNA" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -216,7 +230,7 @@ cFormulaFunction.Information = {
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -224,25 +238,27 @@ cFormulaFunction.Information = {
}
return r;
},
"ISNONTEXT" :function(){
var r = new cBaseFunction("ISNONTEXT");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISNONTEXT":function () {
var r = new cBaseFunction( "ISNONTEXT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( !(arg0 instanceof cString) )
if ( !(arg0 instanceof cString) )
return this.value = new cBool( true );
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -250,26 +266,28 @@ cFormulaFunction.Information = {
}
return r;
},
"ISNUMBER" :function(){
var r = new cBaseFunction("ISNUMBER");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISNUMBER":function () {
var r = new cBaseFunction( "ISNUMBER" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( arg0 instanceof cNumber )
if ( arg0 instanceof cNumber )
return this.value = new cBool( true );
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -277,17 +295,19 @@ cFormulaFunction.Information = {
}
return r;
},
"ISODD" :function(){
var r = new cBaseFunction("ISODD");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISODD":function () {
var r = new cBaseFunction( "ISODD" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
......@@ -300,7 +320,7 @@ cFormulaFunction.Information = {
else
return this.value = new cBool( (arg0.getValue() & 1) == 1 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(number)"
......@@ -308,16 +328,16 @@ cFormulaFunction.Information = {
}
return r;
},
"ISREF" :function(){
var r = new cBaseFunction("ISREF");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
if ( (arg[0] instanceof cRef || arg[0] instanceof cArea || arg[0] instanceof cArea3D|| arg[0] instanceof cRef3D) && arg[0].isValid && arg[0].isValid() )
"ISREF":function () {
var r = new cBaseFunction( "ISREF" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
if ( (arg[0] instanceof cRef || arg[0] instanceof cArea || arg[0] instanceof cArea3D || arg[0] instanceof cRef3D) && arg[0].isValid && arg[0].isValid() )
return this.value = new cBool( true );
else return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -325,26 +345,28 @@ cFormulaFunction.Information = {
}
return r;
},
"ISTEXT" :function(){
var r = new cBaseFunction("ISTEXT");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"ISTEXT":function () {
var r = new cBaseFunction( "ISTEXT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( arg0 instanceof cString )
if ( arg0 instanceof cString )
return this.value = new cBool( true );
else
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -352,30 +374,32 @@ cFormulaFunction.Information = {
}
return r;
},
"N" :function(){
var r = new cBaseFunction("N");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"N":function () {
var r = new cBaseFunction( "N" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
if ( arg0 instanceof cArray ) {
var arr = new cArray();
arg.foreach(function(elem,r,c){
if( elem instanceof cNumber || elem instanceof cError )
arg.foreach( function ( elem, r, c ) {
if ( elem instanceof cNumber || elem instanceof cError )
arr.array[r][c] = elem;
else if ( elem instanceof cBool )
arr.array[r][c] = elem.tocNumber();
else
arr.array[r][c] = new cNumber( 0 );
})
} )
return this.value = arr;
}else if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
}
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( arg0 instanceof cNumber || arg0 instanceof cError )
if ( arg0 instanceof cNumber || arg0 instanceof cError )
return this.value = arg0;
else if ( arg0 instanceof cBool )
return this.value = arg0.tocNumber();
......@@ -383,23 +407,23 @@ cFormulaFunction.Information = {
return this.value = new cNumber( 0 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
};
}
r.setFormat(r.formatType.noneFormat);
r.setFormat( r.formatType.noneFormat );
return r;
},
"NA" :function(){
var r = new cBaseFunction("NA");
r.setArgumentsMin(0);
r.setArgumentsMax(0);
r.Calculate = function(){
return this.value = new cError(cErrorType.not_available);
"NA":function () {
var r = new cBaseFunction( "NA" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 0 );
r.Calculate = function () {
return this.value = new cError( cErrorType.not_available );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"()"
......@@ -407,30 +431,31 @@ cFormulaFunction.Information = {
}
return r;
},
"TYPE" :function(){
var r = new cBaseFunction("TYPE");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
"TYPE":function () {
var r = new cBaseFunction( "TYPE" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}else if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( arg0 instanceof cNumber )
return this.value = new cNumber ( 1 );
else if( arg0 instanceof cString )
return this.value = new cNumber ( 2 )
else if( arg0 instanceof cBool )
return this.value = new cNumber ( 4 )
else if( arg0 instanceof cError )
return this.value = new cNumber ( 16 )
if ( arg0 instanceof cNumber )
return this.value = new cNumber( 1 );
else if ( arg0 instanceof cString )
return this.value = new cNumber( 2 )
else if ( arg0 instanceof cBool )
return this.value = new cNumber( 4 )
else if ( arg0 instanceof cError )
return this.value = new cNumber( 16 )
else
return this.value = new cNumber( 64 );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value)"
......@@ -440,14 +465,14 @@ cFormulaFunction.Information = {
}
}
/*
здесь вынесены функции, которы по назначению не могут быть использованы в веб редакторах документах.
либо они будут реализованы с усеченным функционалом позже.
"INFO" :function(){
var r = new cBaseFunction("INFO");
return r;
},
"CELL" :function(){
var r = new cBaseFunction("CELL");
return r;
},
здесь вынесены функции, которы по назначению не могут быть использованы в веб редакторах документах.
либо они будут реализованы с усеченным функционалом позже.
"INFO" :function(){
var r = new cBaseFunction("INFO");
return r;
},
"CELL" :function(){
var r = new cBaseFunction("CELL");
return r;
},
*/
\ No newline at end of file
......@@ -6,55 +6,59 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.Logical = {
'groupName' : "Logical",
'AND' : function(){
var r = new cBaseFunction("AND");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
'groupName':"Logical",
'AND':function () {
var r = new cBaseFunction( "AND" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argResult = null;
for (var i = 0; i < arg.length; i++){
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ){
for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) {
var argArr = arg[i].getValue();
for( var j=0; j < argArr.length; j++ ){
if (argArr[j] instanceof cString || argArr[j] instanceof cEmpty) continue;
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cString || argArr[j] instanceof cEmpty ) continue;
else if ( argArr[j] instanceof cError ) return this.value = argArr[j];
else {
if ( argResult == null )
argResult = argArr[j].tocBool();
else
argResult = new cBool ( argResult.value && argArr[j].tocBool().value );
argResult = new cBool( argResult.value && argArr[j].tocBool().value );
if ( argResult.value == false ) return this.value = new cBool( false );
}
}
}
else{
if (arg[i] instanceof cString) return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg[i] instanceof cError ) { return this.value = arg[i]; }
else if( arg[i] instanceof cArray ){
else {
if ( arg[i] instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg[i] instanceof cError ) {
return this.value = arg[i];
}
else if ( arg[i] instanceof cArray ) {
var thas = this;
arg[i].foreach(function(elem){
arg[i].foreach( function ( elem ) {
if ( elem instanceof cError ) {
argResult = elem;
return true;
}
else if (elem instanceof cString || elem instanceof cEmpty) { return; }
else{
else if ( elem instanceof cString || elem instanceof cEmpty ) {
return;
}
else {
if ( argResult == null )
argResult = elem.tocBool();
else
argResult = new cBool ( argResult.value && elem.tocBool().value );
if ( argResult.value == false ){
argResult = new cBool( argResult.value && elem.tocBool().value );
if ( argResult.value == false ) {
return true;
}
}
})
} )
}
else {
if ( argResult == null )
argResult = arg[i].tocBool();
else
argResult = new cBool ( argResult.value && arg[i].tocBool().value );
argResult = new cBool( argResult.value && arg[i].tocBool().value );
if ( argResult.value == false ) return this.value = new cBool( false );
}
}
......@@ -63,7 +67,7 @@ cFormulaFunction.Logical = {
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = argResult;
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(logical1, logical2, ...)"
......@@ -71,14 +75,14 @@ cFormulaFunction.Logical = {
}
return r;
},
'FALSE' : function(){
var r = new cBaseFunction("FALSE");
r.setArgumentsMin(0);
r.setArgumentsMax(0);
r.Calculate = function(){
return this.value = new cBool(false);
'FALSE':function () {
var r = new cBaseFunction( "FALSE" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 0 );
r.Calculate = function () {
return this.value = new cBool( false );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"()"
......@@ -86,41 +90,41 @@ cFormulaFunction.Logical = {
}
return r;
},
'IF' : function(){
var r = new cBaseFunction("IF");
r.setArgumentsMin(1);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'IF':function () {
var r = new cBaseFunction( "IF" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if( arg0 instanceof cArray )
arg0 = arg0.getElement(0);
if( arg1 instanceof cArray )
arg1 = arg1.getElement(0);
if( arg2 instanceof cArray )
arg2 = arg2.getElement(0);
if ( arg0 instanceof cArray )
arg0 = arg0.getElement( 0 );
if ( arg1 instanceof cArray )
arg1 = arg1.getElement( 0 );
if ( arg2 instanceof cArray )
arg2 = arg2.getElement( 0 );
if ( arg0 instanceof cError )
return this.value = arg0;
else{
else {
arg0 = arg0.tocBool();
if( arg0 instanceof cString )
if ( arg0 instanceof cString )
return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg0.value )
return this.value = arg1 ?
arg1 instanceof cEmpty ?
new cNumber(0) :
new cNumber( 0 ) :
arg1 :
new cBool(true) ;
new cBool( true );
else return this.value = arg2 ?
arg2 instanceof cEmpty ?
new cNumber(0) :
new cNumber( 0 ) :
arg2 :
new cBool(false) ;
new cBool( false );
}
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(logical_test, value_if_true, value_if_false)"
......@@ -128,27 +132,27 @@ cFormulaFunction.Logical = {
}
return r;
},
'IFERROR' : function(){
var r = new cBaseFunction("IFERROR");
r.setArgumentsMin(2);
r.setArgumentsMax(2);
r.Calculate = function(arg){
'IFERROR':function () {
var r = new cBaseFunction( "IFERROR" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
arg0 = arg0.getElement(0);
if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
if( arg0 instanceof cRef || arg0 instanceof cRef3D ){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
}
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if (arg0 instanceof cError)
return this.value = arg[1] instanceof cArray ? arg[1].getElement(0) : arg[1];
if ( arg0 instanceof cError )
return this.value = arg[1] instanceof cArray ? arg[1].getElement( 0 ) : arg[1];
else return this.value = arg[0];
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(value, value_if_error)"
......@@ -156,32 +160,32 @@ cFormulaFunction.Logical = {
}
return r;
},
'NOT' : function(){
var r = new cBaseFunction("NOT");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'NOT':function () {
var r = new cBaseFunction( "NOT" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray )
arg0 = arg0.getElement(0);
if ( arg0 instanceof cArray )
arg0 = arg0.getElement( 0 );
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if ( arg0 instanceof cString ){
if ( arg0 instanceof cString ) {
var res = arg0.tocBool();
if( res instanceof cString )
if ( res instanceof cString )
return this.value = new cError( cErrorType.wrong_value_type );
else
return this.value = new cBool( ! res.value );
return this.value = new cBool( !res.value );
}
else if( arg0 instanceof cError )
else if ( arg0 instanceof cError )
return this.value = arg0;
else
return this.value = new cBool( ! arg0.tocBool().value );
return this.value = new cBool( !arg0.tocBool().value );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(logical)"
......@@ -189,52 +193,54 @@ cFormulaFunction.Logical = {
}
return r;
},
'OR' : function(){
var r = new cBaseFunction("OR");
r.setArgumentsMin(1);
r.setArgumentsMax(255);
r.Calculate = function(arg){
'OR':function () {
var r = new cBaseFunction( "OR" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argResult = null;
for (var i = 0; i < arg.length; i++){
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ){
for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) {
var argArr = arg[i].getValue();
for( var j=0; j < argArr.length; j++ ){
if (argArr[j] instanceof cString || argArr[j] instanceof cEmpty) continue;
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cString || argArr[j] instanceof cEmpty ) continue;
else if ( argArr[j] instanceof cError ) return this.value = argArr[j];
else {
if ( argResult == null )
argResult = argArr[j].tocBool();
else
argResult = new cBool ( argResult.value || argArr[j].tocBool().value );
argResult = new cBool( argResult.value || argArr[j].tocBool().value );
if ( argResult.value === true ) return this.value = new cBool( true );
}
}
}
else{
if (arg[i] instanceof cString) return this.value = new cError( cErrorType.wrong_value_type );
else {
if ( arg[i] instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else if ( arg[i] instanceof cError ) return this.value = arg[i];
else if( arg[i] instanceof cArray ){
else if ( arg[i] instanceof cArray ) {
var thas = this;
arg[i].foreach(function(elem){
arg[i].foreach( function ( elem ) {
if ( elem instanceof cError ) {
argResult = elem;
return true;
}
else if (elem instanceof cString || elem instanceof cEmpty) { return; }
else{
else if ( elem instanceof cString || elem instanceof cEmpty ) {
return;
}
else {
if ( argResult == null )
argResult = elem.tocBool();
else
argResult = new cBool ( argResult.value || elem.tocBool().value );
argResult = new cBool( argResult.value || elem.tocBool().value );
}
})
} )
}
else {
if ( argResult == null )
argResult = arg[i].tocBool();
else
argResult = new cBool ( argResult.value || arg[i].tocBool().value );
if ( argResult.value === true ) return this.value = new cBool( true );
argResult = new cBool( argResult.value || arg[i].tocBool().value );
if ( argResult.value === true ) return this.value = new cBool( true );
}
}
}
......@@ -242,7 +248,7 @@ cFormulaFunction.Logical = {
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = argResult;
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"(logical1, logical2, ...)"
......@@ -250,14 +256,14 @@ cFormulaFunction.Logical = {
}
return r;
},
'TRUE' : function(){
var r = new cBaseFunction("TRUE");
r.setArgumentsMin(0);
r.setArgumentsMax(0);
r.Calculate = function(){
return this.value = new cBool(true);
'TRUE':function () {
var r = new cBaseFunction( "TRUE" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 0 );
r.Calculate = function () {
return this.value = new cBool( true );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"()"
......
......@@ -6,62 +6,62 @@
* To change this template use File | Settings | File Templates.
*/
cFormulaFunction.LookupAndReference = {
'groupName' : "LookupAndReference",
'ADDRESS' : function(){
var r = new cBaseFunction("ADDRESS");
r.setArgumentsMin(2);
r.setArgumentsMax(5);
r.Calculate = function(arg){
function _getColumnTitle(col) {
var q = col < 26 ? undefined : Asc.floor(col / 26) - 1;
'groupName':"LookupAndReference",
'ADDRESS':function () {
var r = new cBaseFunction( "ADDRESS" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 5 );
r.Calculate = function ( arg ) {
function _getColumnTitle( col ) {
var q = col < 26 ? undefined : Asc.floor( col / 26 ) - 1;
var r = col % 26;
var text = String.fromCharCode( ("A").charCodeAt(0) + r );
return col < 26 ? text : _getColumnTitle(q) + text;
var text = String.fromCharCode( ("A").charCodeAt( 0 ) + r );
return col < 26 ? text : _getColumnTitle( q ) + text;
}
function _getRowTitle(row) {
function _getRowTitle( row ) {
return "" + (row + 1);
}
var rowNumber = arg[0], colNumber = arg[1],
refType = arg[2] ? arg[2] : new cNumber(1),
A1RefType = arg[3] ? arg[3] : new cBool(true),
refType = arg[2] ? arg[2] : new cNumber( 1 ),
A1RefType = arg[3] ? arg[3] : new cBool( true ),
sheetName = arg[4] ? arg[4] : new cEmpty();
if ( rowNumber instanceof cArea || rowNumber instanceof cArea3D ){
rowNumber = rowNumber.cross(arguments[1].first);
if ( rowNumber instanceof cArea || rowNumber instanceof cArea3D ) {
rowNumber = rowNumber.cross( arguments[1].first );
}
else if( rowNumber instanceof cArray ){
rowNumber = rowNumber.getElementRowCol(0,0);
else if ( rowNumber instanceof cArray ) {
rowNumber = rowNumber.getElementRowCol( 0, 0 );
}
if ( colNumber instanceof cArea || colNumber instanceof cArea3D ){
colNumber = colNumber.cross(arguments[1].first);
if ( colNumber instanceof cArea || colNumber instanceof cArea3D ) {
colNumber = colNumber.cross( arguments[1].first );
}
else if( colNumber instanceof cArray ){
colNumber = colNumber.getElementRowCol(0,0);
else if ( colNumber instanceof cArray ) {
colNumber = colNumber.getElementRowCol( 0, 0 );
}
if ( refType instanceof cArea || refType instanceof cArea3D ){
refType = refType.cross(arguments[1].first);
if ( refType instanceof cArea || refType instanceof cArea3D ) {
refType = refType.cross( arguments[1].first );
}
else if( refType instanceof cArray ){
refType = refType.getElementRowCol(0,0);
else if ( refType instanceof cArray ) {
refType = refType.getElementRowCol( 0, 0 );
}
if ( A1RefType instanceof cArea || A1RefType instanceof cArea3D ){
A1RefType = A1RefType.cross(arguments[1].first);
if ( A1RefType instanceof cArea || A1RefType instanceof cArea3D ) {
A1RefType = A1RefType.cross( arguments[1].first );
}
else if( A1RefType instanceof cArray ){
A1RefType = A1RefType.getElementRowCol(0,0);
else if ( A1RefType instanceof cArray ) {
A1RefType = A1RefType.getElementRowCol( 0, 0 );
}
if ( sheetName instanceof cArea || sheetName instanceof cArea3D ){
sheetName = sheetName.cross(arguments[1].first);
if ( sheetName instanceof cArea || sheetName instanceof cArea3D ) {
sheetName = sheetName.cross( arguments[1].first );
}
else if( sheetName instanceof cArray ){
sheetName = sheetName.getElementRowCol(0,0);
else if ( sheetName instanceof cArray ) {
sheetName = sheetName.getElementRowCol( 0, 0 );
}
rowNumber = rowNumber.tocNumber();
......@@ -75,31 +75,39 @@ cFormulaFunction.LookupAndReference = {
if ( A1RefType instanceof cError ) return this.value = A1RefType;
if ( sheetName instanceof cError ) return this.value = sheetName;
if( refType.getValue() > 4 && refType.getValue() < 1 || rowNumber.getValue() < 1 || colNumber.getValue() < 1 ){
if ( refType.getValue() > 4 && refType.getValue() < 1 || rowNumber.getValue() < 1 || colNumber.getValue() < 1 ) {
return this.value = new cError( cErrorType.not_numeric );
}
var strRef;
switch( refType.getValue() ){
case 1: strRef = "$" + _getColumnTitle( colNumber.getValue()-1 ) + "$" + _getRowTitle( rowNumber.getValue()-1 ); break;
case 2: strRef = _getColumnTitle( colNumber.getValue()-1 ) + "$" + _getRowTitle( rowNumber.getValue()-1 ); break;
case 3: strRef = "$" + _getColumnTitle( colNumber.getValue()-1 ) + _getRowTitle( rowNumber.getValue()-1 ); break;
case 4: strRef = _getColumnTitle( colNumber.getValue()-1 ) + _getRowTitle( rowNumber.getValue()-1 ); break;
}
if( sheetName instanceof cEmpty ){
switch ( refType.getValue() ) {
case 1:
strRef = "$" + _getColumnTitle( colNumber.getValue() - 1 ) + "$" + _getRowTitle( rowNumber.getValue() - 1 );
break;
case 2:
strRef = _getColumnTitle( colNumber.getValue() - 1 ) + "$" + _getRowTitle( rowNumber.getValue() - 1 );
break;
case 3:
strRef = "$" + _getColumnTitle( colNumber.getValue() - 1 ) + _getRowTitle( rowNumber.getValue() - 1 );
break;
case 4:
strRef = _getColumnTitle( colNumber.getValue() - 1 ) + _getRowTitle( rowNumber.getValue() - 1 );
break;
}
if ( sheetName instanceof cEmpty ) {
return this.value = new cString( strRef );
}
else{
if( !rx_test_ws_name.test(sheetName.toString()) ){
return this.value = "'"+sheetName.toString().replace(/'/g,"''")+"'"+"!"+strRef;
else {
if ( !rx_test_ws_name.test( sheetName.toString() ) ) {
return this.value = "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef;
}
else{
return this.value = sheetName.toString()+"!"+strRef;
else {
return this.value = sheetName.toString() + "!" + strRef;
}
}
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( row-number , col-number [ , [ ref-type ] [ , [ A1-ref-style-flag ] [ , sheet-name ] ] ] )"
......@@ -107,28 +115,28 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'AREAS' : function(){
var r = new cBaseFunction("AREAS");
'AREAS':function () {
var r = new cBaseFunction( "AREAS" );
return r;
},
'CHOOSE' : function(){
var r = new cBaseFunction("CHOOSE");
r.setArgumentsMin(2);
r.setArgumentsMax(30);
r.Calculate = function(arg){
'CHOOSE':function () {
var r = new cBaseFunction( "CHOOSE" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 30 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
arg0 = arg0.tocNumber();
if( arg0 instanceof cError ){
if ( arg0 instanceof cError ) {
return this.value = arg0;
}
if( arg0 instanceof cNumber ){
if( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ){
if ( arg0 instanceof cNumber ) {
if ( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
......@@ -137,7 +145,7 @@ cFormulaFunction.LookupAndReference = {
return this.value = new cError( cErrorType.wrong_value_type );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( index , argument-list )"
......@@ -145,37 +153,37 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'COLUMN' : function(){
var r = new cBaseFunction("COLUMN");
r.setArgumentsMin(0);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'COLUMN':function () {
var r = new cBaseFunction( "COLUMN" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0;
if( this.argumentsCurrent == 0 ){
if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1];
return this.value = new cNumber( arg0.getFirst().getCol() );
}
arg0 = arg[0];
if( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ) {
var range = arg0.getRange();
if( range )
if ( range )
return this.value = new cNumber( range.getFirst().getCol() );
else
return this.value = new cError( cErrorType.bad_reference );
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
var r = arg0.getRange();
if( r && r[0] && r[0].getFirst() ){
if ( r && r[0] && r[0].getFirst() ) {
return this.value = new cNumber( r[0].getFirst().getCol() );
}
else{
else {
return this.value = new cError( cErrorType.bad_reference );
}
}
else
return this.value = new cError( cErrorType.bad_reference );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( [ reference ] )"
......@@ -183,30 +191,30 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'COLUMNS' : function(){
var r = new cBaseFunction("COLUMNS");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'COLUMNS':function () {
var r = new cBaseFunction( "COLUMNS" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
return this.value = new cNumber(arg0.getCountElementInRow());
if ( arg0 instanceof cArray ) {
return this.value = new cNumber( arg0.getCountElementInRow() );
}
else if( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ){
else if ( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ) {
var range = arg0.getRange();
return this.value = new cNumber( Math.abs( range.getBBox().c1 - range.getBBox().c2 ) + 1 );
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
var range = arg0.getRange();
if( range.length > 1 )
if ( range.length > 1 )
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cNumber( Math.abs(range[0].getBBox().c1 - range[0].getBBox().c2) + 1 );
return this.value = new cNumber( Math.abs( range[0].getBBox().c1 - range[0].getBBox().c2 ) + 1 );
}
else
return this.value = new cError( cErrorType.wrong_value_type );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( array )"
......@@ -214,149 +222,149 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'GETPIVOTDATA' : function(){
var r = new cBaseFunction("GETPIVOTDATA");
'GETPIVOTDATA':function () {
var r = new cBaseFunction( "GETPIVOTDATA" );
return r;
},
'HLOOKUP' : function(){
var r = new cBaseFunction("HLOOKUP");
r.setArgumentsMin(3);
r.setArgumentsMax(4);
r.Calculate = function(arg){
'HLOOKUP':function () {
var r = new cBaseFunction( "HLOOKUP" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 4 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true );
var numberRow = arg2.getValue()-1, valueForSearching = arg0.getValue(), resC = -1, min, regexp;
var numberRow = arg2.getValue() - 1, valueForSearching = arg0.getValue(), resC = -1, min, regexp;
if( isNaN( numberRow ) )
if ( isNaN( numberRow ) )
return this.value = new cError( cErrorType.bad_reference );
if( numberRow < 0 )
if ( numberRow < 0 )
return this.value = new cError( cErrorType.wrong_value_type );
if( arg0 instanceof cString ){
if ( arg0 instanceof cString ) {
valueForSearching = arg0.getValue();
valueForSearching = valueForSearching
.replace(/(~)?\*/g, function($0, $1){
.replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*';
})
.replace(/(~)?\?/g, function($0, $1){
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}';
})
.replace(/\~/g, "\\");
regexp = new XRegExp(valueForSearching+"$","i");
} )
.replace( /\~/g, "\\" );
regexp = new XRegExp( valueForSearching + "$", "i" );
}
else if( arg0 instanceof cError )
else if ( arg0 instanceof cError )
return this.value = arg0;
else{
else {
valueForSearching = arg0.getValue();
}
var found = false, bb,
f = function(cell, r, c, r1, c1){
if( r == r1 ){
f = function ( cell, r, c, r1, c1 ) {
if ( r == r1 ) {
var cv = cell.getValueWithoutFormat();
if( c == c1 )
if ( c == c1 )
min = cv;
if( arg3.value == true ){
if( valueForSearching == cv ){
if ( arg3.value == true ) {
if ( valueForSearching == cv ) {
resC = c;
found = true;
}
else if( valueForSearching > cv && !found ){
else if ( valueForSearching > cv && !found ) {
resC = c;
}
}
else{
if( arg0 instanceof cString ){
if( regexp.test(cv) )
else {
if ( arg0 instanceof cString ) {
if ( regexp.test( cv ) )
resC = c;
}
else if( valueForSearching == cv ){
else if ( valueForSearching == cv ) {
resC = c;
}
}
if( resC > -1 ){
min = Math.min( min , cv );
if( arg3.value == false )
if ( resC > -1 ) {
min = Math.min( min, cv );
if ( arg3.value == false )
return true;
}
}
};
if( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ){
if ( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ) {
var range = arg1.getRange();
bb = range.getBBox0();
if( numberRow > bb.r2-bb.r1 )
if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference );
range._foreachColNoEmpty(/*func for col*/ null, /*func for cell in col*/ f);
range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
}
else if( arg1 instanceof cArea3D ){
else if ( arg1 instanceof cArea3D ) {
var range = arg1.getRange()[0];
bb = range.getBBox0();
if( numberRow > bb.r2-bb.r1 )
if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference );
range._foreachColNoEmpty(/*func for col*/ null, /*func for cell in col*/ f);
range._foreachColNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
}
else if( arg1 instanceof cArray ){
arg1.foreach(function(elem,r,c){
if( c == 0 )
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) {
if ( c == 0 )
min = elem.getValue();
if( arg3.value == true ){
if( valueForSearching == elem.getValue() ){
if ( arg3.value == true ) {
if ( valueForSearching == elem.getValue() ) {
resC = c;
found = true;
}
else if( valueForSearching > elem.getValue() && !found ){
else if ( valueForSearching > elem.getValue() && !found ) {
resC = c;
}
}
else{
if( arg0 instanceof cString ){
if( regexp.test(elem.getValue()) )
else {
if ( arg0 instanceof cString ) {
if ( regexp.test( elem.getValue() ) )
resC = c;
}
else if( valueForSearching == elem.getValue() ){
else if ( valueForSearching == elem.getValue() ) {
resC = c;
}
}
min = Math.min( min , elem.getValue() );
})
min = Math.min( min, elem.getValue() );
} )
if ( min > valueForSearching ){
if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available );
}
if( resC == -1 ){
if ( resC == -1 ) {
return this.value = new cError( cErrorType.not_available );
}
if( numberRow > arg1.getRowCount()-1 ){
if ( numberRow > arg1.getRowCount() - 1 ) {
return this.value = new cError( cErrorType.bad_reference );
}
return this.value = arg1.getElementRowCol(numberRow,resC);
return this.value = arg1.getElementRowCol( numberRow, resC );
}
if ( min > valueForSearching ){
if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available );
}
if( resC == -1 ){
if ( resC == -1 ) {
return this.value = new cError( cErrorType.not_available );
}
var c = new CellAddress(bb.r1+numberRow,resC,0);
var c = new CellAddress( bb.r1 + numberRow, resC, 0 );
var v = arg1.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat();
var v = arg1.getWS()._getCellNoEmpty( c.getRow0(), c.getCol0() ).getValueWithoutFormat();
return this.value = checkTypeCell(v);
return this.value = checkTypeCell( v );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( lookup-value , table-array , row-index-num [ , [ range-lookup-flag ] ] )"
......@@ -364,68 +372,68 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'HYPERLINK' : function(){
var r = new cBaseFunction("HYPERLINK");
'HYPERLINK':function () {
var r = new cBaseFunction( "HYPERLINK" );
return r;
},
'INDEX' : function(){
var r = new cBaseFunction("INDEX");
'INDEX':function () {
var r = new cBaseFunction( "INDEX" );
return r;
},
'INDIRECT' : function(){
var r = new cBaseFunction("INDIRECT");
r.setArgumentsMin(0);
r.setArgumentsMax(1);
r.Calculate = function(arg){
var arg0 = arg[0].tocString(), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos : 0 }, ref, found_operand;
'INDIRECT':function () {
var r = new cBaseFunction( "INDIRECT" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0].tocString(), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand;
function parseReference() {
if( (ref = parserHelp.is3DRef.call(o,o.Formula,o.pCurrPos))[0] ){
if ( (ref = parserHelp.is3DRef.call( o, o.Formula, o.pCurrPos ))[0] ) {
var _wsFrom = ref[1],
_wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) )? ref[2] : _wsFrom;
if( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ){
_wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) ) ? ref[2] : _wsFrom;
if ( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ) {
return this.value = new cError( cErrorType.bad_reference );
}
if ( parserHelp.isArea.call(o,o.Formula,o.pCurrPos) ){
found_operand = new cArea3D(o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb);
if(o.operand_str.indexOf("$") > -1)
if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true;
}
else if ( parserHelp.isRef.call(o,o.Formula,o.pCurrPos) ){
if( _wsTo != _wsFrom ){
found_operand = new cArea3D(o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb);
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos ) ) {
if ( _wsTo != _wsFrom ) {
found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
}
else{
found_operand = new cRef3D(o.operand_str.toUpperCase(), _wsFrom, wb);
else {
found_operand = new cRef3D( o.operand_str.toUpperCase(), _wsFrom, wb );
}
if(o.operand_str.indexOf("$") > -1)
if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true;
}
}
else if ( parserHelp.isName.call(o,o.Formula,o.pCurrPos, wb)[0] ){
found_operand = new cName(o.operand_str, wb);
else if ( parserHelp.isName.call( o, o.Formula, o.pCurrPos, wb )[0] ) {
found_operand = new cName( o.operand_str, wb );
}
else if ( parserHelp.isArea.call(o,o.Formula,o.pCurrPos) ){
found_operand = new cArea(o.operand_str.toUpperCase(), r.worksheet);
if(o.operand_str.indexOf("$") > -1)
else if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new cArea( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true;
}
else if ( parserHelp.isRef.call(o,o.Formula,o.pCurrPos,true) ){
found_operand = new cRef(o.operand_str.toUpperCase(), r.worksheet);
if(o.operand_str.indexOf("$") > -1)
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos, true ) ) {
found_operand = new cRef( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true;
}
}
if( arg0 instanceof cArray ){
if ( arg0 instanceof cArray ) {
var ret = new cArray();
arg0.foreach(function(elem,r,c){
o = { Formula:elem.toString(), pCurrPos : 0 };
arg0.foreach( function ( elem, r, c ) {
o = { Formula:elem.toString(), pCurrPos:0 };
parseReference();
if(!ret.array[r])
if ( !ret.array[r] )
ret.addRow();
ret.addElement(found_operand)
})
ret.addElement( found_operand )
} )
return this.value = ret;
}
else {
......@@ -433,13 +441,13 @@ cFormulaFunction.LookupAndReference = {
parseReference();
}
if( found_operand )
if ( found_operand )
return this.value = found_operand;
return this.value = new cError( cErrorType.bad_reference );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( ref-text [ , [ A1-ref-style-flag ] ] )"
......@@ -447,55 +455,55 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'LOOKUP' : function(){
var r = new cBaseFunction("LOOKUP");
r.setArgumentsMin(2);
r.setArgumentsMax(3);
r.Calculate = function(arg){
'LOOKUP':function () {
var r = new cBaseFunction( "LOOKUP" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2],
valueForSearching, resC = -1, resR = -1;
if( arg0 instanceof cError ){
if ( arg0 instanceof cError ) {
return this.value = arg0;
}
if( arg0 instanceof cRef ){
if ( arg0 instanceof cRef ) {
arg0 = arg0.tryConvert();
}
function arrFinder(arr){
if( arr.getRowCount() > arr.getCountElementInRow() ){
function arrFinder( arr ) {
if ( arr.getRowCount() > arr.getCountElementInRow() ) {
//ищем в первом столбце
resC = arr.getCountElementInRow()>1?1:0;
var arrCol = arr.getCol(0);
resR = _func.binarySearch( arg0, arrCol);
resC = arr.getCountElementInRow() > 1 ? 1 : 0;
var arrCol = arr.getCol( 0 );
resR = _func.binarySearch( arg0, arrCol );
}
else{
else {
//ищем в первой строке
resR = arr.getRowCount()>1?1:0;
var arrRow = arr.getRow(0);
resC = _func.binarySearch( arg0, arrRow);
resR = arr.getRowCount() > 1 ? 1 : 0;
var arrRow = arr.getRow( 0 );
resC = _func.binarySearch( arg0, arrRow );
}
}
if( !( arg1 instanceof cArea || arg1 instanceof cArea3D || arg1 instanceof cArray || arg2 instanceof cArea || arg2 instanceof cArea3D || arg2 instanceof cArray) ){
if ( !( arg1 instanceof cArea || arg1 instanceof cArea3D || arg1 instanceof cArray || arg2 instanceof cArea || arg2 instanceof cArea3D || arg2 instanceof cArray) ) {
return this.value = new cError( cErrorType.not_available );
}
if( arg1 instanceof cArray && arg2 instanceof cArray ){
if( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ){
if ( arg1 instanceof cArray && arg2 instanceof cArray ) {
if ( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ) {
return this.value = new cError( cErrorType.not_available );
}
arrFinder(arg1);
arrFinder( arg1 );
if( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ){
if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) {
return this.value = new cError( cErrorType.not_available );
}
return this.value = arg2.getElementRowCol(resR,resC);
return this.value = arg2.getElementRowCol( resR, resC );
}
else if( arg1 instanceof cArray || arg2 instanceof cArray ){
else if ( arg1 instanceof cArray || arg2 instanceof cArray ) {
var _arg1, _arg2;
......@@ -505,49 +513,49 @@ cFormulaFunction.LookupAndReference = {
var BBox = _arg2.getBBox();
if( _arg1.getRowCount() != (BBox.r2-BBox.r1) && _arg1.getCountElementInRow() != (BBox.c2-BBox.c1) ){
if ( _arg1.getRowCount() != (BBox.r2 - BBox.r1) && _arg1.getCountElementInRow() != (BBox.c2 - BBox.c1) ) {
return this.value = new cError( cErrorType.not_available );
}
arrFinder(_arg1);
arrFinder( _arg1 );
if( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ){
if ( resR <= -1 && resC <= -1 || resR <= -2 || resC <= -2 ) {
return this.value = new cError( cErrorType.not_available );
}
var c = new CellAddress(BBox.r1+resR,BBox.c1+resC)
var c = new CellAddress( BBox.r1 + resR, BBox.c1 + resC )
return this.value = checkTypeCell( _arg2.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat() );
return this.value = checkTypeCell( _arg2.getWS()._getCellNoEmpty( c.getRow0(), c.getCol0() ).getValueWithoutFormat() );
}
else{
else {
var arg1Range = arg1.getRange(), arg2Range = arg2.getRange();
if( arg1 instanceof cArea3D && arg1Range.length > 1 || arg2 instanceof cArea3D && arg2Range.length > 1 )
if ( arg1 instanceof cArea3D && arg1Range.length > 1 || arg2 instanceof cArea3D && arg2Range.length > 1 )
return this.value = new cError( cErrorType.not_available );
if( arg1 instanceof cArea3D )
if ( arg1 instanceof cArea3D )
arg1Range = arg1Range[0];
if( arg2 instanceof cArea3D )
if ( arg2 instanceof cArea3D )
arg2Range = arg2Range[0];
var oBBox1 = arg1Range.getBBox0(), oBBox2 = arg2Range.getBBox0();
if( !(oBBox1.r1 == oBBox1.r2 || oBBox1.c1 == oBBox1.c2) && !(oBBox2.r1 == oBBox2.r2 || oBBox2.c1 == oBBox2.c2) ){
if ( !(oBBox1.r1 == oBBox1.r2 || oBBox1.c1 == oBBox1.c2) && !(oBBox2.r1 == oBBox2.r2 || oBBox2.c1 == oBBox2.c2) ) {
return this.value = new cError( cErrorType.not_available );
}
var index;
if( (oBBox1.r1 == oBBox1.r2 && ( (oBBox2.r1 == oBBox2.r2 && oBBox1.r1 - oBBox1.r2 == oBBox2.r1 - oBBox2.r2) || (oBBox2.c1 == oBBox2.c2 && oBBox1.r1 - oBBox1.r2 == oBBox2.c1 - oBBox2.c2)))
if ( (oBBox1.r1 == oBBox1.r2 && ( (oBBox2.r1 == oBBox2.r2 && oBBox1.r1 - oBBox1.r2 == oBBox2.r1 - oBBox2.r2) || (oBBox2.c1 == oBBox2.c2 && oBBox1.r1 - oBBox1.r2 == oBBox2.c1 - oBBox2.c2)))
||
(oBBox1.c1 == oBBox1.c2 && ( (oBBox2.r1 == oBBox2.r2 && oBBox1.c1 - oBBox1.c2 == oBBox2.r1 - oBBox2.r2) || (oBBox2.c1 == oBBox2.c2 && oBBox1.c1 - oBBox1.c2 == oBBox2.c1 - oBBox2.c2)))
){
) {
index = _func.binarySearch( arg0, arg1.getValue() )
if( index < 0 ) return this.value = new cError( cErrorType.not_available );
if ( index < 0 ) return this.value = new cError( cErrorType.not_available );
}
else{
else {
return this.value = new cError( cErrorType.not_available );
}
......@@ -555,7 +563,7 @@ cFormulaFunction.LookupAndReference = {
}
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( lookup-value , lookup-vector , result-vector )"
......@@ -563,45 +571,45 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'MATCH' : function(){
var r = new cBaseFunction("MATCH");
'MATCH':function () {
var r = new cBaseFunction( "MATCH" );
return r;
},
'OFFSET' : function(){
var r = new cBaseFunction("OFFSET");
'OFFSET':function () {
var r = new cBaseFunction( "OFFSET" );
return r;
},
'ROW' : function(){
var r = new cBaseFunction("ROW");
r.setArgumentsMin(0);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'ROW':function () {
var r = new cBaseFunction( "ROW" );
r.setArgumentsMin( 0 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0;
if( this.argumentsCurrent == 0 ){
if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1];
return this.value = new cNumber( arg0.getFirst().getRow() );
}
arg0 = arg[0];
if( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ){
if ( arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea ) {
var range = arg0.getRange();
if( range )
if ( range )
return this.value = new cNumber( range.getFirst().getRow() );
else
return this.value = new cError( cErrorType.bad_reference );
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
var r = arg0.getRange();
if( r && r[0] && r[0].getFirst() ){
if ( r && r[0] && r[0].getFirst() ) {
return this.value = new cNumber( r[0].getFirst().getRow() );
}
else{
else {
return this.value = new cError( cErrorType.bad_reference );
}
}
else
return this.value = new cError( cErrorType.bad_reference );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( [ reference ] )"
......@@ -609,30 +617,30 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'ROWS' : function(){
var r = new cBaseFunction("ROWS");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
'ROWS':function () {
var r = new cBaseFunction( "ROWS" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 1 );
r.Calculate = function ( arg ) {
var arg0 = arg[0];
if( arg0 instanceof cArray ){
return this.value = new cNumber(arg0.getRowCount());
if ( arg0 instanceof cArray ) {
return this.value = new cNumber( arg0.getRowCount() );
}
else if( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ){
else if ( arg0 instanceof cArea || arg0 instanceof cRef || arg0 instanceof cRef3D ) {
var range = arg0.getRange();
return this.value = new cNumber( Math.abs( range.getBBox().r1 - range.getBBox().r2 ) + 1 );
}
else if( arg0 instanceof cArea3D ){
else if ( arg0 instanceof cArea3D ) {
var range = arg0.getRange();
if( range.length > 1 )
if ( range.length > 1 )
return this.value = new cError( cErrorType.wrong_value_type );
return this.value = new cNumber( Math.abs(range[0].getBBox().r1 - range[0].getBBox().r2) + 1 );
return this.value = new cNumber( Math.abs( range[0].getBBox().r1 - range[0].getBBox().r2 ) + 1 );
}
else
return this.value = new cError( cErrorType.wrong_value_type );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( array )"
......@@ -640,153 +648,153 @@ cFormulaFunction.LookupAndReference = {
}
return r;
},
'RTD' : function(){
var r = new cBaseFunction("RTD");
'RTD':function () {
var r = new cBaseFunction( "RTD" );
return r;
},
'TRANSPOSE' : function(){
var r = new cBaseFunction("TRANSPOSE");
'TRANSPOSE':function () {
var r = new cBaseFunction( "TRANSPOSE" );
return r;
},
'VLOOKUP' : function(){
var r = new cBaseFunction("VLOOKUP");
r.setArgumentsMin(3);
r.setArgumentsMax(4);
r.Calculate = function(arg){
'VLOOKUP':function () {
var r = new cBaseFunction( "VLOOKUP" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 4 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true );
var numberCol = arg2.getValue()-1, valueForSearching, resR = -1, min, regexp;
var numberCol = arg2.getValue() - 1, valueForSearching, resR = -1, min, regexp;
if( isNaN( numberCol ) )
if ( isNaN( numberCol ) )
return this.value = new cError( cErrorType.bad_reference );
if( numberCol < 0 )
if ( numberCol < 0 )
return this.value = new cError( cErrorType.wrong_value_type );
if( arg0 instanceof cString ){
if ( arg0 instanceof cString ) {
valueForSearching = arg0.getValue();
valueForSearching = valueForSearching
.replace(/(~)?\*/g, function($0, $1){
.replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*';
})
.replace(/(~)?\?/g, function($0, $1){
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}';
})
.replace(/\~/g, "\\");
regexp = new XRegExp(valueForSearching+"$","i");
} )
.replace( /\~/g, "\\" );
regexp = new XRegExp( valueForSearching + "$", "i" );
}
else if( arg0 instanceof cError )
else if ( arg0 instanceof cError )
return this.value = arg0;
else{
else {
valueForSearching = arg0.getValue();
}
var found = false, bb,
f = function(cell, r, c, r1, c1){
if( c == c1 ){
f = function ( cell, r, c, r1, c1 ) {
if ( c == c1 ) {
var cv = cell.getValueWithoutFormat();
if( r == r1 )
if ( r == r1 )
min = cv;
if( arg3.value == true ){
if( valueForSearching == cv ){
if ( arg3.value == true ) {
if ( valueForSearching == cv ) {
resR = r;
found = true;
}
else if( valueForSearching > cv && !found ){
else if ( valueForSearching > cv && !found ) {
resR = r;
}
}
else{
if( arg0 instanceof cString ){
if( regexp.test(cv) )
else {
if ( arg0 instanceof cString ) {
if ( regexp.test( cv ) )
resR = r;
}
else if( valueForSearching == cv ){
else if ( valueForSearching == cv ) {
resR = r;
}
}
if( resR > -1 ){
min = Math.min( min , cv );
if( arg3.value == false )
if ( resR > -1 ) {
min = Math.min( min, cv );
if ( arg3.value == false )
return true;
}
}
};
if( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ){
if ( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ) {
var range = arg1.getRange();
bb = range.getBBox0();
if( numberCol > bb.c2-bb.c1 )
if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference );
range._foreachRowNoEmpty(/*func for col*/ null, /*func for cell in col*/ f);
range._foreachRowNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
}
else if( arg1 instanceof cArea3D ){
else if ( arg1 instanceof cArea3D ) {
var range = arg1.getRange()[0];
bb = range.getBBox0();
if( numberCol > bb.c2-bb.c1 )
if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference );
range._foreachRowNoEmpty(/*func for col*/ null, /*func for cell in col*/ f);
range._foreachRowNoEmpty( /*func for col*/ null, /*func for cell in col*/ f );
}
else if( arg1 instanceof cArray ){
arg1.foreach(function(elem,r,c){
if( r == 0 )
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) {
if ( r == 0 )
min = elem.getValue();
if( arg3.value == true ){
if( valueForSearching == elem.getValue() ){
if ( arg3.value == true ) {
if ( valueForSearching == elem.getValue() ) {
resR = r;
found = true;
}
else if( valueForSearching > elem.getValue() && !found ){
else if ( valueForSearching > elem.getValue() && !found ) {
resR = r;
}
}
else{
if( arg0 instanceof cString ){
if( regexp.test(elem.getValue()) )
else {
if ( arg0 instanceof cString ) {
if ( regexp.test( elem.getValue() ) )
resR = r;
}
else if( valueForSearching == elem.getValue() ){
else if ( valueForSearching == elem.getValue() ) {
resR = r;
}
}
min = Math.min( min , elem.getValue() );
})
min = Math.min( min, elem.getValue() );
} )
if ( min > valueForSearching ){
if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available );
}
if( resR == -1 ){
if ( resR == -1 ) {
return this.value = new cError( cErrorType.not_available );
}
if( numberCol > arg1.getCountElementInRow()-1 ){
if ( numberCol > arg1.getCountElementInRow() - 1 ) {
return this.value = new cError( cErrorType.bad_reference );
}
return this.value = arg1.getElementRowCol(resR,numberCol);
return this.value = arg1.getElementRowCol( resR, numberCol );
}
if ( min > valueForSearching ){
if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available );
}
if( resR == -1 ){
if ( resR == -1 ) {
return this.value = new cError( cErrorType.not_available );
}
var c = new CellAddress(resR,bb.c1+numberCol,0);
var c = new CellAddress( resR, bb.c1 + numberCol, 0 );
var v = arg1.getWS()._getCellNoEmpty(c.getRow0(),c.getCol0()).getValueWithoutFormat();
var v = arg1.getWS()._getCellNoEmpty( c.getRow0(), c.getCol0() ).getValueWithoutFormat();
return this.value = checkTypeCell(v);
return this.value = checkTypeCell( v );
}
r.getInfo = function(){
r.getInfo = function () {
return {
name:this.name,
args:"( lookup-value , table-array , col-index-num [ , [ range-lookup-flag ] ] )"
......
......@@ -3026,7 +3026,7 @@ cFormulaFunction.Mathematic = {
r.setArgumentsMin( 2 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _count = 0, valueForSearching, regexpSearch;
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, valueForSearching, regexpSearch;
if ( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
......@@ -3077,11 +3077,11 @@ cFormulaFunction.Mathematic = {
}
arg1 = arg1.toString();
var operators = new RegExp( "^ *[<=> ]+ *" ), searchOperators = new RegExp( "^ *[*?]" )
var operators = new RegExp( "^ *[<=> ]+ *" );
var match = arg1.match( operators );
if ( match || parseNum( arg1 ) ) {
var search, oper, val, calcVal;
var search, oper, val;
if ( match ) {
search = arg1.substr( match[0].length );
oper = match[0].replace( /\s/g, "" );
......@@ -3098,7 +3098,7 @@ cFormulaFunction.Mathematic = {
r1 = r.first.getRow0() + i, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_count += r.getValue().getValue();
_sum += r.getValue().getValue();
}
}
}
......@@ -3110,7 +3110,7 @@ cFormulaFunction.Mathematic = {
r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_count += r.getValue().getValue();
_sum += r.getValue().getValue();
}
}
}
......@@ -3133,7 +3133,7 @@ cFormulaFunction.Mathematic = {
r1 = r.first.getRow0() + i, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_count += r.getValue().getValue();
_sum += r.getValue().getValue();
}
}
}
......@@ -3145,18 +3145,18 @@ cFormulaFunction.Mathematic = {
r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_count += r.getValue().getValue();
_sum += r.getValue().getValue();
}
}
}
}
return this.value = new cNumber( _count );
return this.value = new cNumber( _sum );
}
r.getInfo = function () {
return {
name:this.name,
args:"( cell-range, selection-criteria )"
args:"( cell-range, selection-criteria [ , sum-range ] )"
};
}
return r;
......
......@@ -1531,6 +1531,10 @@ function cNumber( val ) {
cNumber.superclass.constructor.call( this, val );
this.type = cElementType.number;
this.value = parseFloat( val );
if( !isNaN( this.value ) && Math.abs(this.value)!=Infinity )
return this;
else
return new cError( cErrorType.not_numeric );
}
extend( cNumber, cBaseType );
cNumber.prototype.getValue = function () {
......@@ -1587,12 +1591,10 @@ function cBool( val ) {
this.type = cElementType.bool;
var that = this;
switch ( val.toString().toUpperCase() ) {
case "TRUE"/* ||true */
:
case "TRUE":
this.value = true;
break;
case "FALSE"/* ||false */
:
case "FALSE":
this.value = false;
break;
}
......
......@@ -9,6 +9,62 @@ cFormulaFunction.Statistical = {
'groupName':"Statistical",
'AVEDEV':function () {
var r = new cBaseFunction( "AVEDEV" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 ), arrX = [];
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber ) {
arrX.push( _argV );
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ) {
arrX.push( __arg );
count++;
}
}
}
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
var e = elem.tocNumber();
if ( e instanceof cNumber ) {
arrX.push( e );
count++;
}
} )
}
else {
if ( _arg instanceof cError )
continue;
arrX.push( _arg );
count++;
}
}
for ( var i = 0; i < arrX.length; i++ ) {
sum = _func[sum.type][arrX[i].type]( sum, arrX[i], "+" );
}
var a = 0
for ( var i = 0; i < arrX.length; i++ ) {
a += Math.abs( _func[sum.type][arrX[i].type]( sum, arrX[i], "-" ).getValue() );
}
return this.value = new cNumber( a / count );
};
r.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
return r;
},
'AVERAGE':function () {
......@@ -21,6 +77,9 @@ cFormulaFunction.Statistical = {
var _arg = arg[i];
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cString || _argV instanceof cEmpty || _argV instanceof cBool ) {
continue;
}
if ( _argV instanceof cNumber ) {
sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++;
......@@ -29,6 +88,9 @@ cFormulaFunction.Statistical = {
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++ ) {
if ( _argAreaValue[j] instanceof cString || _argAreaValue[j] instanceof cEmpty || _argAreaValue[j] instanceof cBool ) {
continue;
}
var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber ) {
sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
......@@ -38,6 +100,9 @@ cFormulaFunction.Statistical = {
}
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
if ( elem instanceof cString || elem instanceof cEmpty || elem instanceof cBool ) {
return false;
}
var e = elem.tocNumber();
if ( e instanceof cNumber ) {
sum = _func[sum.type][e.type]( sum, e, "+" );
......@@ -46,8 +111,9 @@ cFormulaFunction.Statistical = {
} )
}
else {
_arg = _arg.tocNumber();
if ( _arg instanceof cError )
continue;
return this.value = _arg;
sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++;
}
......@@ -57,33 +123,300 @@ cFormulaFunction.Statistical = {
r.getInfo = function () {
return {
name:this.name,
args:"(number1, number2, ...)"
args:"( argument-list )"
};
}
return r;
},
'AVERAGEA':function () {
var r = new cBaseFunction( "AVERAGEA" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 );
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber || _argV instanceof cBool ) {
sum = _func[sum.type][_argV.type]( sum, _argV, "+" );
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++ ) {
var __arg = _argAreaValue[j];
if ( __arg instanceof cNumber || __arg instanceof cBool ) {
sum = _func[sum.type][__arg.type]( sum, __arg, "+" );
count++;
}
}
}
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
if ( elem instanceof cString || elem instanceof cEmpty ) {
return false;
}
var e = elem.tocNumber();
if ( e instanceof cNumber ) {
sum = _func[sum.type][e.type]( sum, e, "+" );
count++;
}
} )
}
else {
_arg = _arg.tocNumber();
if ( _arg instanceof cError )
return this.value = _arg;
sum = _func[sum.type][_arg.type]( sum, _arg, "+" );
count++;
}
}
return this.value = new cNumber( sum.getValue() / count );
};
r.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
return r;
},
'AVERAGEIF':function () {
var r = new cBaseFunction( "AVERAGEIF" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, _count = 0, valueForSearching, regexpSearch;
if ( !(arg0 instanceof cRef || arg0 instanceof cRef3D || arg0 instanceof cArea) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
if ( !(arg2 instanceof cRef || arg2 instanceof cRef3D || arg2 instanceof cArea) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElementRowCol( 0, 0 );
}
arg1 = arg1.tocString();
if ( !(arg1 instanceof cString) ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
function matching( x, y, oper, startCell, pos ) {
var res = false;
if ( typeof x === typeof y ) {
switch ( oper ) {
case "<>":
res = (x.value != y.value);
break;
case ">":
res = (x.value > y.value);
break;
case "<":
res = (x.value < y.value);
break;
case ">=":
res = (x.value >= y.value);
break;
case "<=":
res = (x.value <= y.value);
break;
case "=":
default:
res = (x.value == y.value);
break;
}
}
return res;
}
arg1 = arg1.toString();
var operators = new RegExp( "^ *[<=> ]+ *" );
var match = arg1.match( operators );
if ( match || parseNum( arg1 ) ) {
var search, oper, val;
if ( match ) {
search = arg1.substr( match[0].length );
oper = match[0].replace( /\s/g, "" );
}
else {
search = arg1;
}
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if ( arg0 instanceof cArea ) {
val = arg0.getValue();
for ( var i = 0; i < val.length; i++ ) {
if ( matching( val[i], valueForSearching, oper ) ) {
var r = arg0.getRange(), ws = arg0.getWS(),
r1 = r.first.getRow0() + i, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_sum += r.getValue().getValue();
_count++;
}
}
}
}
else {
val = arg0.getValue();
if ( matching( val, valueForSearching, oper ) ) {
var r = arg0.getRange(), ws = arg0.getWS(),
r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_sum += r.getValue().getValue();
_count++;
}
}
}
}
else {
valueForSearching = arg1
.replace( /(~)?\*/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]*';
} )
.replace( /(~)?\?/g, function ( $0, $1 ) {
return $1 ? $0 : '[\\w\\W]{1,1}';
} )
.replace( /(~\*)/g, "\\*" ).replace( /(~\?)/g, "\\?" );
regexpSearch = new RegExp( valueForSearching + "$", "i" );
if ( arg0 instanceof cArea ) {
val = arg0.getValue();
for ( var i = 0; i < val.length; i++ ) {
if ( regexpSearch.test( val[i].value ) ) {
var r = arg0.getRange(), ws = arg0.getWS(),
r1 = r.first.getRow0() + i, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_sum += r.getValue().getValue();
_count++;
}
}
}
}
else {
val = arg0.getValue();
if ( regexpSearch.test( val.value ) ) {
var r = arg0.getRange(), ws = arg0.getWS(),
r1 = r.first.getRow0() + 0, c1 = arg2.getRange().first.getCol0();
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
if ( r.getValue() instanceof cNumber ) {
_sum += r.getValue().getValue();
_count++;
}
}
}
}
return this.value = new cNumber( _sum / _count );
}
r.getInfo = function () {
return {
name:this.name,
args:"( cell-range, selection-criteria [ , average-range ] )"
};
}
return r;
},
'AVERAGEIFS':function () {
var r = new cBaseFunction( "AVERAGEIFS" );
return r;
},
'BETADIST':function () {
'BETADIST':function () {/*Нет реализации в Google Docs*/
var r = new cBaseFunction( "BETADIST" );
return r;
},
'BETAINV':function () {
'BETAINV':function () {/*Нет реализации в Google Docs*/
var r = new cBaseFunction( "BETAINV" );
return r;
},
'BINOMDIST':function () {
var r = new cBaseFunction( "BINOMDIST" );
r.setArgumentsMin( 4 );
r.setArgumentsMax( 4 );
r.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
function binomCoeff( n, k ) {
return Math.fact( n ) / (Math.fact( k ) * Math.fact( n - k ));
}
function binomdist( x, n, p ) {
x = parseInt( x );
n = parseInt( n );
return binomCoeff( n, x ) * Math.pow( p, x ) * Math.pow( 1 - p, n - x );
}
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
else if ( arg0 instanceof cArray ) {
arg0 = arg0.getElement( 0 );
}
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
else if ( arg1 instanceof cArray ) {
arg1 = arg1.getElement( 0 );
}
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first );
}
else if ( arg2 instanceof cArray ) {
arg2 = arg2.getElement( 0 );
}
if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) {
arg3 = arg3.cross( arguments[1].first );
}
else if ( arg3 instanceof cArray ) {
arg3 = arg3.getElement( 0 );
}
arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber();
arg3 = arg3.tocBool();
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2;
if ( arg3 instanceof cError ) return this.value = arg3;
if ( arg0.getValue() < 0 || arg0.getValue() > arg1.getValue() || arg2.getValue() < 0 || arg2.getValue() > 1 )
return this.value = new cError( cErrorType.not_numeric );
if ( arg3.toBool() ) {
var x = parseInt( arg0.getValue() ), n = parseInt( arg1.getValue() ), p = arg2.getValue(), bm = 0;
for ( var y = 0; y <= x; y++ ) {
bm += binomdist( y, n, p );
}
return this.value = new cNumber( bm );
}
else
return this.value = new cNumber( binomdist( arg0.getValue(), arg1.getValue(), arg2.getValue() ) );
}
r.getInfo = function () {
return {
name:this.name,
args:"( number-successes , number-trials , success-probability , cumulative-flag )"
};
}
return r;
},
'CHIDIST':function () {
......@@ -100,10 +433,289 @@ cFormulaFunction.Statistical = {
},
'CONFIDENCE':function () {
var r = new cBaseFunction( "CONFIDENCE" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
function gaussinv( x ) {/*from openoffice source \sc\source\core\tool\interpr3.cxx*/
var q, t, z;
q = x - 0.5;
if ( Math.abs( q ) <= .425 ) {
t = 0.180625 - q * q;
z =
q *
(
(
(
(
(
(
(
t * 2509.0809287301226727 + 33430.575583588128105
)
* t + 67265.770927008700853
)
* t + 45921.953931549871457
)
* t + 13731.693765509461125
)
* t + 1971.5909503065514427
)
* t + 133.14166789178437745
)
* t + 3.387132872796366608
)
/
(
(
(
(
(
(
(
t * 5226.495278852854561 + 28729.085735721942674
)
* t + 39307.89580009271061
)
* t + 21213.794301586595867
)
* t + 5394.1960214247511077
)
* t + 687.1870074920579083
)
* t + 42.313330701600911252
)
* t + 1.0
);
}
else {
if ( q > 0 )
t = 1 - x;
else
t = x;
t = Math.sqrt( -Math.log( t ) );
if ( t <= 5.0 ) {
t += -1.6;
z =
(
(
(
(
(
(
(
t * 7.7454501427834140764e-4 + 0.0227238449892691845833
)
* t + 0.24178072517745061177
)
* t + 1.27045825245236838258
)
* t + 3.64784832476320460504
)
* t + 5.7694972214606914055
)
* t + 4.6303378461565452959
)
* t + 1.42343711074968357734
)
/
(
(
(
(
(
(
(
t * 1.05075007164441684324e-9 + 5.475938084995344946e-4
)
* t + 0.0151986665636164571966
)
* t + 0.14810397642748007459
)
* t + 0.68976733498510000455
)
* t + 1.6763848301838038494
)
* t + 2.05319162663775882187
)
* t + 1.0
);
}
else {
t += -5.0;
z =
(
(
(
(
(
(
(
t * 2.01033439929228813265e-7 + 2.71155556874348757815e-5
)
* t + 0.0012426609473880784386
)
* t + 0.026532189526576123093
)
* t + 0.29656057182850489123
)
* t + 1.7848265399172913358
)
* t + 5.4637849111641143699
)
* t + 6.6579046435011037772
)
/
(
(
(
(
(
(
(
t * 2.04426310338993978564e-15 + 1.4215117583164458887e-7
)
* t + 1.8463183175100546818e-5
)
* t + 7.868691311456132591e-4
)
* t + 0.0148753612908506148525
)
* t + 0.13692988092273580531
)
* t + 0.59983220655588793769
)
* t + 1.0
);
}
if ( q < 0.0 ) z = -z;
}
return z;
}
var alpha = arg[0], stdev_sigma = arg[1], size = arg[2];
if ( alpha instanceof cArea || alpha instanceof cArea3D ) {
alpha = alpha.cross( arguments[1].first );
}
else if ( alpha instanceof cArray ) {
alpha = alpha.getElement( 0 );
}
if ( stdev_sigma instanceof cArea || stdev_sigma instanceof cArea3D ) {
stdev_sigma = stdev_sigma.cross( arguments[1].first );
}
else if ( stdev_sigma instanceof cArray ) {
stdev_sigma = stdev_sigma.getElement( 0 );
}
if ( size instanceof cArea || size instanceof cArea3D ) {
size = size.cross( arguments[1].first );
}
else if ( size instanceof cArray ) {
size = size.getElement( 0 );
}
alpha = alpha.tocNumber();
stdev_sigma = stdev_sigma.tocNumber();
size = size.tocNumber();
if ( alpha instanceof cError ) return this.value = alpha;
if ( stdev_sigma instanceof cError ) return this.value = stdev_sigma;
if ( size instanceof cError ) return this.value = size;
if ( alpha.getValue() <= 0 || alpha.getValue() >= 1 || stdev_sigma.getValue <= 0 || size.getValue() < 1 )
return this.value = new cError( cErrorType.not_numeric );
return this.value = new cNumber( gaussinv( 1.0 - alpha.getValue() / 2.0 ) * stdev_sigma.getValue() / Math.sqrt( size.getValue() ) );
}
r.getInfo = function () {
return {
name:this.name,
args:"( alpha , standard-dev , size )"
};
}
return r;
},
'CORREL':function () {
var r = new cBaseFunction( "CORREL" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
function correl( x, y ) {
var s1 = 0, s2 = 0, s3 = 0, _x = 0, _y = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) {
if ( !( x[i] instanceof cNumber && y[i] instanceof cNumber ) ) {
continue;
}
_x += x[i].getValue();
_y += y[i].getValue();
xLength++;
}
_x /= xLength;
_y /= xLength;
for ( var i = 0; i < x.length; i++ ) {
if ( !( x[i] instanceof cNumber && y[i] instanceof cNumber ) ) {
continue;
}
s1 += (x[i].getValue() - _x) * (y[i].getValue() - _y);
s2 += (x[i].getValue() - _x) * (x[i].getValue() - _x);
s3 += (y[i].getValue() - _y) * (y[i].getValue() - _y);
}
if ( s2 == 0 || s3 == 0 )
return new cError( cErrorType.division_by_zero );
else
return new cNumber( s1 / Math.sqrt( s2 * s3 ) );
}
var arg0 = arg[0], arg1 = arg[1], arr0 = [], arr1 = [];
if ( arg0 instanceof cArea ) {
arr0 = arg0.getValue();
}
else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem ) {
arr0.push( elem );
} );
}
else
return this.value = cError( cErrorType.wrong_value_type )
if ( arg1 instanceof cArea ) {
arr1 = arg1.getValue();
}
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem ) {
arr1.push( elem );
} );
}
else
return this.value = cError( cErrorType.wrong_value_type )
return this.value = correl( arr0, arr1 );
}
r.getInfo = function () {
return {
name:this.name,
args:"( array-1 , array-2 )"
};
}
return r;
},
'COUNT':function () {
......@@ -157,6 +769,46 @@ cFormulaFunction.Statistical = {
},
'COUNTA':function () {
var r = new cBaseFunction( "COUNTA" );
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var count = 0;
for ( var i = 0; i < arg.length; i++ ) {
var _arg = arg[i];
if ( _arg instanceof cRef || _arg instanceof cRef3D ) {
var _argV = _arg.getValue();
if ( _argV instanceof cNumber || _argV instanceof cBool || _argV instanceof cError ) {
count++;
}
}
else if ( _arg instanceof cArea || _arg instanceof cArea3D ) {
var _argAreaValue = _arg.getValue();
for ( var j = 0; j < _argAreaValue.length; j++ ) {
if ( _argAreaValue[j] instanceof cNumber || _argAreaValue[j] instanceof cBool || _argAreaValue[j] instanceof cError ) {
count++;
}
}
}
else if ( _arg instanceof cArray ) {
_arg.foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cBool || elem instanceof cError ) {
count++;
}
} )
}
else if ( !( _arg instanceof cEmpty ) ) {
count++;
}
}
return this.value = new cNumber( count );
};
r.getInfo = function () {
return {
name:this.name,
args:"( argument-list )"
};
}
r.setFormat( r.formatType.noneFormat );
return r;
},
'COUNTBLANK':function () {
......@@ -314,10 +966,154 @@ cFormulaFunction.Statistical = {
},
'COVAR':function () {
var r = new cBaseFunction( "COVAR" );
r.setArgumentsMin( 2 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
function correl( x, y ) {
var s1 = 0, _x = 0, _y = 0, xLength = 0;
for ( var i = 0; i < x.length; i++ ) {
if ( !( x[i] instanceof cNumber && y[i] instanceof cNumber ) ) {
continue;
}
_x += x[i].getValue();
_y += y[i].getValue();
xLength++;
}
if ( xLength == 0 )
return new cError( cErrorType.division_by_zero );
_x /= xLength;
_y /= xLength;
for ( var i = 0; i < x.length; i++ ) {
if ( !( x[i] instanceof cNumber && y[i] instanceof cNumber ) ) {
continue;
}
s1 += (x[i].getValue() - _x) * (y[i].getValue() - _y);
}
return new cNumber( s1 / xLength );
}
var arg0 = arg[0], arg1 = arg[1], arr0 = [], arr1 = [];
if ( arg0 instanceof cArea ) {
arr0 = arg0.getValue();
}
else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem ) {
arr0.push( elem );
} );
}
else
return this.value = cError( cErrorType.wrong_value_type )
if ( arg1 instanceof cArea ) {
arr1 = arg1.getValue();
}
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem ) {
arr1.push( elem );
} );
}
else
return this.value = cError( cErrorType.wrong_value_type )
return this.value = correl( arr0, arr1 );
}
r.getInfo = function () {
return {
name:this.name,
args:"( array-1 , array-2 )"
};
}
return r;
},
'CRITBINOM':function () {
var r = new cBaseFunction( "CRITBINOM" );
r.setArgumentsMin( 3 );
r.setArgumentsMax( 3 );
r.Calculate = function ( arg ) {
var n = arg[0], p = arg[1], alpha = arg[2]; // alpha
function critbinom( n, p, alpha ) {
if ( n < 0 || alpha <= 0 || alpha >= 1 || p < 0 || p > 1 )
return new cError( cErrorType.not_numeric );
else {
var q = 1 - p,
factor = Math.pow( q, n );
if ( factor == 0 ) {
factor = Math.pow( p, n );
if ( factor == 0.0 )
return new cError( cErrorType.wrong_value_type );
else {
var sum = 1 - factor, max = n, i = 0;
for ( i = 0; i < max && sum >= alpha; i++ ) {
factor *= (n - i) / (i + 1) * q / p;
sum -= factor;
}
return new cNumber( n - i );
}
}
else {
var sum = factor, max = n, i = 0;
for ( i = 0; i < max && sum < alpha; i++ ) {
factor *= (n - i) / (i + 1) * p / q;
sum += factor;
}
return new cNumber( i );
}
}
}
if ( alpha instanceof cArea || alpha instanceof cArea3D ) {
alpha = alpha.cross( arguments[1].first );
}
else if ( alpha instanceof cArray ) {
alpha = alpha.getElement( 0 );
}
if ( n instanceof cArea || n instanceof cArea3D ) {
n = n.cross( arguments[1].first );
}
else if ( n instanceof cArray ) {
n = n.getElement( 0 );
}
if ( p instanceof cArea || p instanceof cArea3D ) {
p = p.cross( arguments[1].first );
}
else if ( p instanceof cArray ) {
p = p.getElement( 0 );
}
alpha = alpha.tocNumber();
n = n.tocNumber();
p = p.tocNumber();
if ( alpha instanceof cError ) return this.value = alpha;
if ( n instanceof cError ) return this.value = n;
if ( p instanceof cError ) return this.value = p;
return this.value = critbinom( n, p, alpha );
}
r.getInfo = function () {
return {
name:this.name,
args:"( number-trials , success-probability , alpha )"
};
}
return r;
},
'DEVSQ':function () {
......@@ -417,7 +1213,7 @@ cFormulaFunction.Statistical = {
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, argIVal, max = new cNumber( Number.NEGATIVE_INFINITY );
var argI, argIVal, max = Number.NEGATIVE_INFINITY;
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ) {
......@@ -425,8 +1221,8 @@ cFormulaFunction.Statistical = {
return this.value = argIVal;
if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
var v = argIVal.tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
}
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
......@@ -434,8 +1230,8 @@ cFormulaFunction.Statistical = {
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
else if ( argArr[j] instanceof cError ) {
return this.value = argArr[j];
......@@ -447,19 +1243,19 @@ cFormulaFunction.Statistical = {
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cNumber ) {
if ( elem.getValue() > max.getValue() )
max = elem;
if ( elem.getValue() > max )
max = elem.getValue();
}
else if ( elem instanceof cError ) {
max = elem;
......@@ -471,11 +1267,11 @@ cFormulaFunction.Statistical = {
}
}
else {
if ( argI.getValue() > max.getValue() )
max = argI;
if ( argI.getValue() > max )
max = argI.getValue();
}
}
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : max );
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) );
};
r.getInfo = function () {
return {
......@@ -490,7 +1286,7 @@ cFormulaFunction.Statistical = {
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, max = new cNumber( Number.NEGATIVE_INFINITY );
var argI, max = Number.NEGATIVE_INFINITY;
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ) {
......@@ -500,8 +1296,8 @@ cFormulaFunction.Statistical = {
var v = argIVal.tocNumber();
if ( v instanceof cNumber && v.getValue() > max.getValue() )
max = v;
if ( v instanceof cNumber && v.getValue() > max )
max = v.getValue();
}
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
......@@ -512,8 +1308,8 @@ cFormulaFunction.Statistical = {
var v = argArr[j].tocNumber();
if ( v instanceof cNumber && v.getValue() > max.getValue() )
max = v;
if ( v instanceof cNumber && v.getValue() > max )
max = v.getValue();
}
}
else if ( argI instanceof cError )
......@@ -521,13 +1317,13 @@ cFormulaFunction.Statistical = {
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() > max.getValue() )
max = v;
if ( v.getValue() > max )
max = v.getValue();
}
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
......@@ -537,8 +1333,8 @@ cFormulaFunction.Statistical = {
}
elem = elem.tocNumber();
if ( elem instanceof cNumber && elem.getValue() > max.getValue() ) {
max = elem;
if ( elem instanceof cNumber && elem.getValue() > max ) {
max = elem.getValue();
}
} )
if ( max instanceof cError ) {
......@@ -546,11 +1342,11 @@ cFormulaFunction.Statistical = {
}
}
else {
if ( argI.getValue() > max.getValue() )
max = argI;
if ( argI.getValue() > max )
max = argI.getValue();
}
}
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : max )
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) )
};
r.getInfo = function () {
return {
......@@ -569,7 +1365,7 @@ cFormulaFunction.Statistical = {
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, argIVal, min = new cNumber( Number.POSITIVE_INFINITY );
var argI, argIVal, min = Number.POSITIVE_INFINITY;
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ) {
......@@ -577,8 +1373,8 @@ cFormulaFunction.Statistical = {
return this.value = argIVal;
if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
var v = argIVal.tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
}
}
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
......@@ -586,8 +1382,8 @@ cFormulaFunction.Statistical = {
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
var v = argArr[j].tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
continue;
}
else if ( argArr[j] instanceof cError ) {
......@@ -600,19 +1396,19 @@ cFormulaFunction.Statistical = {
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
}
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
}
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
if ( elem instanceof cNumber ) {
if ( elem.getValue() < min.getValue() )
min = elem;
if ( elem.getValue() < min )
min = elem.getValue();
}
else if ( elem instanceof cError ) {
min = elem;
......@@ -624,11 +1420,11 @@ cFormulaFunction.Statistical = {
}
}
else {
if ( argI.getValue() < min.getValue() )
min = argI;
if ( argI.getValue() < min )
min = argI.getValue();
}
}
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : min );
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
};
r.getInfo = function () {
return {
......@@ -643,7 +1439,7 @@ cFormulaFunction.Statistical = {
r.setArgumentsMin( 1 );
r.setArgumentsMax( 255 );
r.Calculate = function ( arg ) {
var argI, min = new cNumber( Number.POSITIVE_INFINITY );
var argI, min = Number.POSITIVE_INFINITY;
for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i], argIVal = argI.getValue();
if ( argI instanceof cRef || argI instanceof cRef3D ) {
......@@ -653,8 +1449,8 @@ cFormulaFunction.Statistical = {
var v = argIVal.tocNumber();
if ( v instanceof cNumber && v.getValue() < min.getValue() )
min = v;
if ( v instanceof cNumber && v.getValue() < min )
min = v.getValue();
}
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
......@@ -666,8 +1462,8 @@ cFormulaFunction.Statistical = {
var v = argArr[j].tocNumber();
if ( v instanceof cNumber && v.getValue() < min.getValue() )
min = v;
if ( v instanceof cNumber && v.getValue() < min )
min = v.getValue();
}
}
else if ( argI instanceof cError )
......@@ -675,13 +1471,13 @@ cFormulaFunction.Statistical = {
else if ( argI instanceof cString ) {
var v = argI.tocNumber();
if ( v instanceof cNumber )
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
}
else if ( argI instanceof cBool || argI instanceof cEmpty ) {
var v = argI.tocNumber();
if ( v.getValue() < min.getValue() )
min = v;
if ( v.getValue() < min )
min = v.getValue();
}
else if ( argI instanceof cArray ) {
argI.foreach( function ( elem ) {
......@@ -692,8 +1488,8 @@ cFormulaFunction.Statistical = {
elem = elem.tocNumber();
if ( elem instanceof cNumber && elem.getValue() < min.getValue() ) {
min = elem;
if ( elem instanceof cNumber && elem.getValue() < min ) {
min = elem.getValue();
}
} )
if ( min instanceof cError ) {
......@@ -701,11 +1497,11 @@ cFormulaFunction.Statistical = {
}
}
else {
if ( argI.getValue() < min.getValue() )
min = argI;
if ( argI.getValue() < min )
min = argI.getValue();
}
}
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : min );
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
};
r.getInfo = function () {
return {
......@@ -843,7 +1639,6 @@ cFormulaFunction.Statistical = {
res += av * av;
}
return this.value = new cNumber( Math.sqrt( res / (count - 1) ) );
STDEV( 123, 134, 143, 173, 112, 109 )
};
r.getInfo = function () {
return {
......
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