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

добавлена функция ODDFPRICE;

рефакторинг после проверки JSHINT'ом.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55699 954022d7-b5bf-4e40-9824-e11837661b57
parent 06520e7b
...@@ -16,7 +16,7 @@ cFormulaFunction.Cube = { ...@@ -16,7 +16,7 @@ cFormulaFunction.Cube = {
'CUBESET':cCUBESET, 'CUBESET':cCUBESET,
'CUBESETCOUNT':cCUBESETCOUNT, 'CUBESETCOUNT':cCUBESETCOUNT,
'CUBEVALUE':cCUBEVALUE 'CUBEVALUE':cCUBEVALUE
} };
function cCUBEKPIMEMBER() { function cCUBEKPIMEMBER() {
// cBaseFunction.call( this, "CUBEKPIMEMBER" ); // cBaseFunction.call( this, "CUBEKPIMEMBER" );
...@@ -34,7 +34,7 @@ function cCUBEKPIMEMBER() { ...@@ -34,7 +34,7 @@ function cCUBEKPIMEMBER() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBEKPIMEMBER.prototype = Object.create( cBaseFunction.prototype ) cCUBEKPIMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBEMEMBER() { function cCUBEMEMBER() {
// cBaseFunction.call( this, "CUBEMEMBER" ); // cBaseFunction.call( this, "CUBEMEMBER" );
...@@ -52,7 +52,7 @@ function cCUBEMEMBER() { ...@@ -52,7 +52,7 @@ function cCUBEMEMBER() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBEMEMBER.prototype = Object.create( cBaseFunction.prototype ) cCUBEMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBEMEMBERPROPERTY() { function cCUBEMEMBERPROPERTY() {
// cBaseFunction.call( this, "CUBEMEMBERPROPERTY" ); // cBaseFunction.call( this, "CUBEMEMBERPROPERTY" );
...@@ -70,7 +70,7 @@ function cCUBEMEMBERPROPERTY() { ...@@ -70,7 +70,7 @@ function cCUBEMEMBERPROPERTY() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBEMEMBERPROPERTY.prototype = Object.create( cBaseFunction.prototype ) cCUBEMEMBERPROPERTY.prototype = Object.create( cBaseFunction.prototype );
function cCUBERANKEDMEMBER() { function cCUBERANKEDMEMBER() {
// cBaseFunction.call( this, "CUBERANKEDMEMBER" ); // cBaseFunction.call( this, "CUBERANKEDMEMBER" );
...@@ -88,7 +88,7 @@ function cCUBERANKEDMEMBER() { ...@@ -88,7 +88,7 @@ function cCUBERANKEDMEMBER() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBERANKEDMEMBER.prototype = Object.create( cBaseFunction.prototype ) cCUBERANKEDMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBESET() { function cCUBESET() {
// cBaseFunction.call( this, "CUBESET" ); // cBaseFunction.call( this, "CUBESET" );
...@@ -106,7 +106,7 @@ function cCUBESET() { ...@@ -106,7 +106,7 @@ function cCUBESET() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBESET.prototype = Object.create( cBaseFunction.prototype ) cCUBESET.prototype = Object.create( cBaseFunction.prototype );
function cCUBESETCOUNT() { function cCUBESETCOUNT() {
// cBaseFunction.call( this, "CUBESETCOUNT" ); // cBaseFunction.call( this, "CUBESETCOUNT" );
...@@ -124,7 +124,7 @@ function cCUBESETCOUNT() { ...@@ -124,7 +124,7 @@ function cCUBESETCOUNT() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBESETCOUNT.prototype = Object.create( cBaseFunction.prototype ) cCUBESETCOUNT.prototype = Object.create( cBaseFunction.prototype );
function cCUBEVALUE() { function cCUBEVALUE() {
// cBaseFunction.call( this, "CUBEVALUE" ); // cBaseFunction.call( this, "CUBEVALUE" );
...@@ -142,4 +142,4 @@ function cCUBEVALUE() { ...@@ -142,4 +142,4 @@ function cCUBEVALUE() {
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
} }
cCUBEVALUE.prototype = Object.create( cBaseFunction.prototype ) cCUBEVALUE.prototype = Object.create( cBaseFunction.prototype );
...@@ -21,64 +21,64 @@ cFormulaFunction.Database = { ...@@ -21,64 +21,64 @@ cFormulaFunction.Database = {
'DSUM':cDSUM, 'DSUM':cDSUM,
'DVAR':cDVAR, 'DVAR':cDVAR,
'DVARP':cDVARP 'DVARP':cDVARP
} };
function cDAVERAGE() { function cDAVERAGE() {
cBaseFunction.call( this, "DAVERAGE" ); cBaseFunction.call( this, "DAVERAGE" );
} }
cDAVERAGE.prototype = Object.create( cBaseFunction.prototype ) cDAVERAGE.prototype = Object.create( cBaseFunction.prototype );
function cDCOUNT() { function cDCOUNT() {
cBaseFunction.call( this, "DCOUNT" ); cBaseFunction.call( this, "DCOUNT" );
} }
cDCOUNT.prototype = Object.create( cBaseFunction.prototype ) cDCOUNT.prototype = Object.create( cBaseFunction.prototype );
function cDCOUNTA() { function cDCOUNTA() {
cBaseFunction.call( this, "DCOUNTA" ); cBaseFunction.call( this, "DCOUNTA" );
} }
cDCOUNTA.prototype = Object.create( cBaseFunction.prototype ) cDCOUNTA.prototype = Object.create( cBaseFunction.prototype );
function cDGET() { function cDGET() {
cBaseFunction.call( this, "DGET" ); cBaseFunction.call( this, "DGET" );
} }
cDGET.prototype = Object.create( cBaseFunction.prototype ) cDGET.prototype = Object.create( cBaseFunction.prototype );
function cDMAX() { function cDMAX() {
cBaseFunction.call( this, "DMAX" ); cBaseFunction.call( this, "DMAX" );
} }
cDMAX.prototype = Object.create( cBaseFunction.prototype ) cDMAX.prototype = Object.create( cBaseFunction.prototype );
function cDMIN() { function cDMIN() {
cBaseFunction.call( this, "DMIN" ); cBaseFunction.call( this, "DMIN" );
} }
cDMIN.prototype = Object.create( cBaseFunction.prototype ) cDMIN.prototype = Object.create( cBaseFunction.prototype );
function cDPRODUCT() { function cDPRODUCT() {
cBaseFunction.call( this, "DPRODUCT" ); cBaseFunction.call( this, "DPRODUCT" );
} }
cDPRODUCT.prototype = Object.create( cBaseFunction.prototype ) cDPRODUCT.prototype = Object.create( cBaseFunction.prototype );
function cDSTDEV() { function cDSTDEV() {
cBaseFunction.call( this, "DSTDEV" ); cBaseFunction.call( this, "DSTDEV" );
} }
cDSTDEV.prototype = Object.create( cBaseFunction.prototype ) cDSTDEV.prototype = Object.create( cBaseFunction.prototype );
function cDSTDEVP() { function cDSTDEVP() {
cBaseFunction.call( this, "DSTDEVP" ); cBaseFunction.call( this, "DSTDEVP" );
} }
cDSTDEVP.prototype = Object.create( cBaseFunction.prototype ) cDSTDEVP.prototype = Object.create( cBaseFunction.prototype );
function cDSUM() { function cDSUM() {
cBaseFunction.call( this, "DSUM" ); cBaseFunction.call( this, "DSUM" );
} }
cDSUM.prototype = Object.create( cBaseFunction.prototype ) cDSUM.prototype = Object.create( cBaseFunction.prototype );
function cDVAR() { function cDVAR() {
cBaseFunction.call( this, "DVAR" ); cBaseFunction.call( this, "DVAR" );
} }
cDVAR.prototype = Object.create( cBaseFunction.prototype ) cDVAR.prototype = Object.create( cBaseFunction.prototype );
function cDVARP() { function cDVARP() {
cBaseFunction.call( this, "DVARP" ); cBaseFunction.call( this, "DVARP" );
} }
cDVARP.prototype = Object.create( cBaseFunction.prototype ) cDVARP.prototype = Object.create( cBaseFunction.prototype );
...@@ -34,7 +34,7 @@ function yearFrac(d1, d2, mode) { ...@@ -34,7 +34,7 @@ function yearFrac(d1, d2, mode) {
switch ( mode ) { switch ( mode ) {
case DayCountBasis.UsPsa30_360: case DayCountBasis.UsPsa30_360:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) / 360 ); return new CNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) / 360 );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
var yc = /*Math.abs*/( year2 - year1 ), var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? new Date(d2) : new Date(d1), sd = year1 > year2 ? new Date(d2) : new Date(d1),
...@@ -45,19 +45,19 @@ function yearFrac(d1, d2, mode) { ...@@ -45,19 +45,19 @@ function yearFrac(d1, d2, mode) {
} }
yearAverage /= (yc + 1); yearAverage /= (yc + 1);
dayDiff /= (yearAverage * c_msPerDay); dayDiff /= (yearAverage * c_msPerDay);
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (360 * c_msPerDay); dayDiff /= (360 * c_msPerDay);
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = Math.abs( d2 - d1 );
dayDiff /= (365 * c_msPerDay); dayDiff /= (365 * c_msPerDay);
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ) / 360 ); return new CNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ) / 360 );
default: default:
return new cError( cErrorType.not_numeric ); return new CError( cErrorType.not_numeric );
} }
} }
...@@ -71,30 +71,30 @@ function diffDate(d1, d2, mode){ ...@@ -71,30 +71,30 @@ function diffDate(d1, d2, mode){
switch ( mode ) { switch ( mode ) {
case DayCountBasis.UsPsa30_360: case DayCountBasis.UsPsa30_360:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) ); return new CNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
var yc = Math.abs( year2 - year1 ), var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? d2 : d1, sd = year1 > year2 ? new Date(d2) : new Date(d1),
yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = Math.abs( d2 - d1 ); yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = d2 - d1;
for ( var i = 0; i < yc; i++ ) { for ( var i = 0; i < yc; i++ ) {
sd.addYears( 1 ); sd.addYears( 1 );
yearAverage += sd.isLeapYear() ? 366 : 365; yearAverage += sd.isLeapYear() ? 366 : 365;
} }
yearAverage /= (yc + 1); yearAverage /= (yc + 1);
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = d2 - d1;
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
var dayDiff = Math.abs( d2 - d1 ); var dayDiff = d2 - d1;
dayDiff /= c_msPerDay; dayDiff /= c_msPerDay;
return new cNumber( dayDiff ); return new CNumber( dayDiff );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) ) ); return new CNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, false ) );
default: default:
return new cError( cErrorType.not_numeric ); return new CError( cErrorType.not_numeric );
} }
} }
...@@ -113,7 +113,7 @@ function diffDate2(d1, d2, mode){ ...@@ -113,7 +113,7 @@ function diffDate2(d1, d2, mode){
nDaysInYear = 360; nDaysInYear = 360;
nYears = year1 - year2; nYears = year1 - year2;
nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, true ) ) - nYears * nDaysInYear; nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, true ) ) - nYears * nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear ); return new CNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.ActualActual: case DayCountBasis.ActualActual:
nYears = year2 - year1; nYears = year2 - year1;
nDaysInYear = d1.isLeapYear() ? 366 : 365; nDaysInYear = d1.isLeapYear() ? 366 : 365;
...@@ -130,26 +130,26 @@ function diffDate2(d1, d2, mode){ ...@@ -130,26 +130,26 @@ function diffDate2(d1, d2, mode){
if( dayDiff < 0 ) if( dayDiff < 0 )
dayDiff += nDaysInYear; dayDiff += nDaysInYear;
return new cNumber( nYears + dayDiff / nDaysInYear ); return new CNumber( nYears + dayDiff / nDaysInYear );
case DayCountBasis.Actual360: case DayCountBasis.Actual360:
nDaysInYear = 360; nDaysInYear = 360;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear ); nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay; nDayDiff = (d2 - d1)/c_msPerDay;
nDayDiff %= nDaysInYear; nDayDiff %= nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear ); return new CNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Actual365: case DayCountBasis.Actual365:
nDaysInYear = 365; nDaysInYear = 365;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear ); nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay; nDayDiff = (d2 - d1)/c_msPerDay;
nDayDiff %= nDaysInYear; nDayDiff %= nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear ); return new CNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Europ30_360: case DayCountBasis.Europ30_360:
nDaysInYear = 360; nDaysInYear = 360;
nYears = year1 - year2; nYears = year1 - year2;
nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, false ) ) - nYears * nDaysInYear; nDayDiff = Math.abs( GetDiffDate360( date1, month1+1, year1, d1.isLeapYear(), date2, month2+1, year2, false ) ) - nYears * nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear ); return new CNumber( nYears + nDayDiff / nDaysInYear );
default: default:
return new cError( cErrorType.not_numeric ); return new CError( cErrorType.not_numeric );
} }
} }
...@@ -258,22 +258,22 @@ cDATE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -258,22 +258,22 @@ cDATE.prototype = Object.create( cBaseFunction.prototype )
cDATE.prototype.Calculate = function ( arg ) { cDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], year, month, day; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], year, month, day;
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElement( 0 ); arg1 = arg1.getElement( 0 );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElement( 0 ); arg2 = arg2.getElement( 0 );
} }
...@@ -281,9 +281,9 @@ cDATE.prototype.Calculate = function ( arg ) { ...@@ -281,9 +281,9 @@ cDATE.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
if ( arg1 instanceof cError ) return this.setCA( arg1, true ); if ( arg1 instanceof CError ) return this.setCA( arg1, true );
if ( arg2 instanceof cError ) return this.setCA( arg2, true ); if ( arg2 instanceof CError ) return this.setCA( arg2, true );
year = arg0.getValue(); year = arg0.getValue();
month = arg1.getValue(); month = arg1.getValue();
...@@ -292,9 +292,9 @@ cDATE.prototype.Calculate = function ( arg ) { ...@@ -292,9 +292,9 @@ cDATE.prototype.Calculate = function ( arg ) {
if ( year >= 0 && year <= 1899 ) if ( year >= 0 && year <= 1899 )
year += 1900; year += 1900;
if ( month == 0 ) { if ( month == 0 ) {
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
} }
this.value = new cNumber( Math.round( new Date( year, month - 1, day ).getExcelDate() ) ) this.value = new CNumber( Math.round( new Date( year, month - 1, day ).getExcelDate() ) )
this.value.numFormat = 14; this.value.numFormat = 14;
this.value.ca = true; this.value.ca = true;
return this.value; return this.value;
...@@ -328,24 +328,24 @@ function cDATEDIF() { ...@@ -328,24 +328,24 @@ function cDATEDIF() {
cDATEDIF.prototype = Object.create( cBaseFunction.prototype ) cDATEDIF.prototype = Object.create( cBaseFunction.prototype )
cDATEDIF.prototype.Calculate = function ( arg ) { cDATEDIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -353,14 +353,14 @@ cDATEDIF.prototype.Calculate = function ( arg ) { ...@@ -353,14 +353,14 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocString(); arg2 = arg2.tocString();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
var val0 = arg0.getValue(), val1 = arg1.getValue(); var val0 = arg0.getValue(), val1 = arg1.getValue();
if ( val0 < 0 || val1 < 0 || val0 >= val1 ) if ( val0 < 0 || val1 < 0 || val0 >= val1 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
val0 = Date.prototype.getDateFromExcel( val0 ); val0 = Date.prototype.getDateFromExcel( val0 );
val1 = Date.prototype.getDateFromExcel( val1 ); val1 = Date.prototype.getDateFromExcel( val1 );
...@@ -379,38 +379,38 @@ cDATEDIF.prototype.Calculate = function ( arg ) { ...@@ -379,38 +379,38 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
switch ( arg2.getValue().toUpperCase() ) { switch ( arg2.getValue().toUpperCase() ) {
case "Y": case "Y":
return this.value = new cNumber( dateDiff( val0, val1 )[0] ); return this.value = new CNumber( dateDiff( val0, val1 )[0] );
break; break;
case "M": case "M":
return this.value = new cNumber( dateDiff( val0, val1 )[1] ); return this.value = new CNumber( dateDiff( val0, val1 )[1] );
break; break;
case "D": case "D":
return this.value = new cNumber( parseInt( (val1 - val0) / c_msPerDay ) ); return this.value = new CNumber( parseInt( (val1 - val0) / c_msPerDay ) );
break; break;
case "MD": case "MD":
if ( val0.getDate() > val1.getDate() ) { if ( val0.getDate() > val1.getDate() ) {
this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val0.getMonth() + 1, val1.getDate() ) ) / c_msPerDay ); this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val0.getMonth() + 1, val1.getDate() ) ) / c_msPerDay );
} }
else { else {
this.value = new cNumber( val1.getDate() - val0.getDate() ); this.value = new CNumber( val1.getDate() - val0.getDate() );
} }
return this.value; return this.value;
break; break;
case "YM": case "YM":
var d = dateDiff( val0, val1 ); var d = dateDiff( val0, val1 );
return this.value = new cNumber( d[1] - d[0] * 12 ); return this.value = new CNumber( d[1] - d[0] * 12 );
break; break;
case "YD": case "YD":
if ( val0.getMonth() > val1.getMonth() ) { if ( val0.getMonth() > val1.getMonth() ) {
this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear() + 1, val1.getMonth(), val1.getDate() ) ) / c_msPerDay ); this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear() + 1, val1.getMonth(), val1.getDate() ) ) / c_msPerDay );
} }
else { else {
this.value = new cNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val1.getMonth(), val1.getDate() ) ) / c_msPerDay ); this.value = new CNumber( Math.abs( new Date( val0.getFullYear(), val0.getMonth(), val0.getDate() ) - new Date( val0.getFullYear(), val1.getMonth(), val1.getDate() ) ) / c_msPerDay );
} }
return this.value; return this.value;
break; break;
default: default:
return this.value = new cError( cErrorType.not_numeric ) return this.value = new CError( cErrorType.not_numeric )
} }
} }
...@@ -444,27 +444,27 @@ cDATEVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -444,27 +444,27 @@ cDATEVALUE.prototype = Object.create( cBaseFunction.prototype )
cDATEVALUE.prototype.Calculate = function ( arg ) { cDATEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg0.tocNumber() instanceof cNumber && arg0.tocNumber().getValue() > 0 ) if ( arg0.tocNumber() instanceof CNumber && arg0.tocNumber().getValue() > 0 )
return this.value = new cNumber( parseInt( arg0.tocNumber().getValue() ) ); return this.value = new CNumber( parseInt( arg0.tocNumber().getValue() ) );
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res && res.bDateTime ) if ( res && res.bDateTime )
return this.value = new cNumber( parseInt( res.value ) ); return this.value = new CNumber( parseInt( res.value ) );
else else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cDATEVALUE.prototype.getInfo = function () { cDATEVALUE.prototype.getInfo = function () {
return { return {
...@@ -495,32 +495,32 @@ function cDAY() { ...@@ -495,32 +495,32 @@ function cDAY() {
cDAY.prototype = Object.create( cBaseFunction.prototype ) cDAY.prototype = Object.create( cBaseFunction.prototype )
cDAY.prototype.Calculate = function ( arg ) { cDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue().tocNumber(); val = arg0.getValue().tocNumber();
if ( val instanceof cNumber || val instanceof cBool ) { if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -530,17 +530,17 @@ cDAY.prototype.Calculate = function ( arg ) { ...@@ -530,17 +530,17 @@ cDAY.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 );
else if ( val == 60 ) else if ( val == 60 )
return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() + 1 ), true, 0 ); return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() + 1 ), true, 0 );
else else
return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst - 1) * c_msPerDay ) ).getUTCDate() ), true, 0 );
} }
else else
return this.setCA( new cNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 ); return this.setCA( new CNumber( ( new Date( (val - c_DateCorrectConst) * c_msPerDay ) ).getUTCDate() ), true, 0 );
} }
cDAY.prototype.getInfo = function () { cDAY.prototype.getInfo = function () {
return { return {
...@@ -570,26 +570,26 @@ function cDAYS360() { ...@@ -570,26 +570,26 @@ function cDAYS360() {
} }
cDAYS360.prototype = Object.create( cBaseFunction.prototype ) cDAYS360.prototype = Object.create( cBaseFunction.prototype )
cDAYS360.prototype.Calculate = function ( arg ) { cDAYS360.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cBool( false ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CBool( false );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -597,16 +597,16 @@ cDAYS360.prototype.Calculate = function ( arg ) { ...@@ -597,16 +597,16 @@ cDAYS360.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocBool(); arg2 = arg2.tocBool();
if ( arg0 instanceof cError )return this.value = arg0; if ( arg0 instanceof CError )return this.value = arg0;
if ( arg1 instanceof cError )return this.value = arg1; if ( arg1 instanceof CError )return this.value = arg1;
if ( arg2 instanceof cError )return this.value = arg2; if ( arg2 instanceof CError )return this.value = arg2;
if ( arg0.getValue() < 0 )return this.value = new cError( cErrorType.not_numeric ); if ( arg0.getValue() < 0 )return this.value = new CError( cErrorType.not_numeric );
if ( arg1.getValue() < 0 )return this.value = new cError( cErrorType.not_numeric ); if ( arg1.getValue() < 0 )return this.value = new CError( cErrorType.not_numeric );
var date1 = Date.prototype.getDateFromExcel( arg0.getValue() ), date2 = Date.prototype.getDateFromExcel( arg1.getValue() ); var date1 = Date.prototype.getDateFromExcel( arg0.getValue() ), date2 = Date.prototype.getDateFromExcel( arg1.getValue() );
return this.value = new cNumber( GetDiffDate360( date1.getDate(), date1.getMonth() + 1, date1.getFullYear(), date1.isLeapYear(), return this.value = new CNumber( GetDiffDate360( date1.getDate(), date1.getMonth() + 1, date1.getFullYear(), date1.isLeapYear(),
date2.getDate(), date2.getMonth() + 1, date2.getFullYear(), !arg2.toBool() ) ) date2.getDate(), date2.getMonth() + 1, date2.getFullYear(), !arg2.toBool() ) )
} }
...@@ -640,30 +640,30 @@ cEDATE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -640,30 +640,30 @@ cEDATE.prototype = Object.create( cBaseFunction.prototype )
cEDATE.prototype.Calculate = function ( arg ) { cEDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var val = arg0.getValue(), date, _date; var val = arg0.getValue(), date, _date;
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
val = new Date( (val - c_DateCorrectConst) * c_msPerDay ); val = new Date( (val - c_DateCorrectConst) * c_msPerDay );
...@@ -689,7 +689,7 @@ cEDATE.prototype.Calculate = function ( arg ) { ...@@ -689,7 +689,7 @@ cEDATE.prototype.Calculate = function ( arg ) {
val = new Date( val.setMonth( val.getMonth() + arg1.getValue() ) ); val = new Date( val.setMonth( val.getMonth() + arg1.getValue() ) );
} }
return this.value = new cNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) ) return this.value = new CNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) )
} }
cEDATE.prototype.getInfo = function () { cEDATE.prototype.getInfo = function () {
return { return {
...@@ -721,30 +721,30 @@ cEOMONTH.prototype = Object.create( cBaseFunction.prototype ) ...@@ -721,30 +721,30 @@ cEOMONTH.prototype = Object.create( cBaseFunction.prototype )
cEOMONTH.prototype.Calculate = function ( arg ) { cEOMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var val = arg0.getValue(), date, _date; var val = arg0.getValue(), date, _date;
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val < 60 ) if ( val < 60 )
val = new Date( (val - c_DateCorrectConst) * c_msPerDay ); val = new Date( (val - c_DateCorrectConst) * c_msPerDay );
...@@ -762,7 +762,7 @@ cEOMONTH.prototype.Calculate = function ( arg ) { ...@@ -762,7 +762,7 @@ cEOMONTH.prototype.Calculate = function ( arg ) {
val.setMonth( val.getMonth() + arg1.getValue() ); val.setMonth( val.getMonth() + arg1.getValue() );
val.setDate( val.getDaysInMonth() ); val.setDate( val.getDaysInMonth() );
return this.value = new cNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) ); return this.value = new CNumber( Math.floor( ( val.getTime() / 1000 - val.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) );
} }
cEOMONTH.prototype.getInfo = function () { cEOMONTH.prototype.getInfo = function () {
return { return {
...@@ -793,35 +793,35 @@ function cHOUR() { ...@@ -793,35 +793,35 @@ function cHOUR() {
cHOUR.prototype = Object.create( cBaseFunction.prototype ) cHOUR.prototype = Object.create( cBaseFunction.prototype )
cHOUR.prototype.Calculate = function ( arg ) { cHOUR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cError )return this.setCA( arg0, true ); if ( arg0 instanceof CError )return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof cError )return this.setCA( val, true ); if ( val instanceof CError )return this.setCA( val, true );
else if ( val instanceof cNumber || val instanceof cBool ) { else if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -833,9 +833,9 @@ cHOUR.prototype.Calculate = function ( arg ) { ...@@ -833,9 +833,9 @@ cHOUR.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else //1 2 3 4 4 3 2 1 else //1 2 3 4 4 3 2 1
return this.setCA( new cNumber( parseInt( ( ( val - Math.floor( val ) ) * 24 ).toFixed( cExcelDateTimeDigits ) ) ), true, 0 ); return this.setCA( new CNumber( parseInt( ( ( val - Math.floor( val ) ) * 24 ).toFixed( cExcelDateTimeDigits ) ) ), true, 0 );
} }
cHOUR.prototype.getInfo = function () { cHOUR.prototype.getInfo = function () {
return { return {
...@@ -866,35 +866,35 @@ function cMINUTE() { ...@@ -866,35 +866,35 @@ function cMINUTE() {
cMINUTE.prototype = Object.create( cBaseFunction.prototype ) cMINUTE.prototype = Object.create( cBaseFunction.prototype )
cMINUTE.prototype.Calculate = function ( arg ) { cMINUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof cError ) return this.setCA( val, true ); if ( val instanceof CError ) return this.setCA( val, true );
else if ( val instanceof cNumber || val instanceof cBool ) { else if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -906,10 +906,10 @@ cMINUTE.prototype.Calculate = function ( arg ) { ...@@ -906,10 +906,10 @@ cMINUTE.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else { else {
val = parseInt( ( ( val * 24 - Math.floor( val * 24 ) ) * 60 ).toFixed( cExcelDateTimeDigits ) ) % 60; val = parseInt( ( ( val * 24 - Math.floor( val * 24 ) ) * 60 ).toFixed( cExcelDateTimeDigits ) ) % 60;
return this.setCA( new cNumber( val ), true, 0 ); return this.setCA( new CNumber( val ), true, 0 );
} }
} }
cMINUTE.prototype.getInfo = function () { cMINUTE.prototype.getInfo = function () {
...@@ -941,33 +941,33 @@ function cMONTH() { ...@@ -941,33 +941,33 @@ function cMONTH() {
cMONTH.prototype = Object.create( cBaseFunction.prototype ) cMONTH.prototype = Object.create( cBaseFunction.prototype )
cMONTH.prototype.Calculate = function ( arg ) { cMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof cError ) return this.setCA( val, true ); if ( val instanceof CError ) return this.setCA( val, true );
else if ( val instanceof cNumber || val instanceof cBool ) { else if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -977,15 +977,15 @@ cMONTH.prototype.Calculate = function ( arg ) { ...@@ -977,15 +977,15 @@ cMONTH.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
if ( !g_bDate1904 ) { if ( !g_bDate1904 ) {
if ( val == 60 ) if ( val == 60 )
return this.setCA( new cNumber( 2 ), true, 0 ); return this.setCA( new CNumber( 2 ), true, 0 );
else else
return this.setCA( new cNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst - 1 ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 ); return this.setCA( new CNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst - 1 ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 );
} }
else else
return this.setCA( new cNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 ); return this.setCA( new CNumber( ( new Date( ( (val == 0 ? 1 : val) - c_DateCorrectConst ) * c_msPerDay ) ).getUTCMonth() + 1 ), true, 0 );
} }
cMONTH.prototype.getInfo = function () { cMONTH.prototype.getInfo = function () {
return { return {
...@@ -1017,30 +1017,30 @@ cNETWORKDAYS.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1017,30 +1017,30 @@ cNETWORKDAYS.prototype = Object.create( cBaseFunction.prototype )
cNETWORKDAYS.prototype.Calculate = function ( arg ) { cNETWORKDAYS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = []; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var val0 = arg0.getValue(), val1 = arg1.getValue(), dif, count = 0; var val0 = arg0.getValue(), val1 = arg1.getValue(), dif, count = 0;
if ( val0 < 0 ) if ( val0 < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val0 < 60 ) if ( val0 < 60 )
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
...@@ -1053,7 +1053,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1053,7 +1053,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
if ( val1 < 0 ) if ( val1 < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val1 < 60 ) if ( val1 < 60 )
val1 = new Date( (val1 - c_DateCorrectConst) * c_msPerDay ); val1 = new Date( (val1 - c_DateCorrectConst) * c_msPerDay );
...@@ -1068,29 +1068,29 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1068,29 +1068,29 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
var holidays = []; var holidays = [];
if ( arg2 ) { if ( arg2 ) {
if ( arg2 instanceof cRef ) { if ( arg2 instanceof CRef ) {
var a = arg2.getValue(); var a = arg2.getValue();
if ( a instanceof cNumber && a.getValue() >= 0 ) { if ( a instanceof CNumber && a.getValue() >= 0 ) {
holidays.push( a ); holidays.push( a );
} }
} }
else if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { else if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
var arr = arg2.getValue(); var arr = arg2.getValue();
for ( var i = 0; i < arr.length; i++ ) { for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] instanceof cNumber && arr[i].getValue() >= 0 ) { if ( arr[i] instanceof CNumber && arr[i].getValue() >= 0 ) {
holidays.push( arr[i] ); holidays.push( arr[i] );
} }
} }
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2.foreach( function ( elem, r, c ) { arg2.foreach( function ( elem, r, c ) {
if ( elem instanceof cNumber ) { if ( elem instanceof CNumber ) {
holidays.push( elem ); holidays.push( elem );
} }
else if ( elem instanceof cString ) { else if ( elem instanceof CString ) {
var res = g_oFormatParser.parse( elem.getValue() ); var res = g_oFormatParser.parse( elem.getValue() );
if ( res && res.bDateTime && res.value >= 0 ) if ( res && res.bDateTime && res.value >= 0 )
holidays.push( new cNumber( parseInt( res.value ) ) ); holidays.push( new CNumber( parseInt( res.value ) ) );
} }
} ) } )
} }
...@@ -1116,7 +1116,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) { ...@@ -1116,7 +1116,7 @@ cNETWORKDAYS.prototype.Calculate = function ( arg ) {
if ( date.getDay() != 6 && date.getDay() != 0 && includeInHolidays( date ) ) if ( date.getDay() != 6 && date.getDay() != 0 && includeInHolidays( date ) )
count++; count++;
} }
return this.value = new cNumber( (dif < 0 ? -1 : 1) * count ); return this.value = new CNumber( (dif < 0 ? -1 : 1) * count );
} }
cNETWORKDAYS.prototype.getInfo = function () { cNETWORKDAYS.prototype.getInfo = function () {
return { return {
...@@ -1151,7 +1151,7 @@ function cNOW() { ...@@ -1151,7 +1151,7 @@ function cNOW() {
cNOW.prototype = Object.create( cBaseFunction.prototype ) cNOW.prototype = Object.create( cBaseFunction.prototype )
cNOW.prototype.Calculate = function () { cNOW.prototype.Calculate = function () {
var d = new Date(); var d = new Date();
this.value = new cNumber( Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) ); this.value = new CNumber( Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + (c_DateCorrectConst + 1) ) + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) );
this.value.numFormat = 22; this.value.numFormat = 22;
return this.setCA( this.value, true ); return this.setCA( this.value, true );
} }
...@@ -1184,35 +1184,35 @@ function cSECOND() { ...@@ -1184,35 +1184,35 @@ function cSECOND() {
cSECOND.prototype = Object.create( cBaseFunction.prototype ) cSECOND.prototype = Object.create( cBaseFunction.prototype )
cSECOND.prototype.Calculate = function ( arg ) { cSECOND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof cError ) return this.setCA( val, true ); if ( val instanceof CError ) return this.setCA( val, true );
else if ( val instanceof cNumber || val instanceof cBool ) { else if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
d = g_oFormatParser.parseDate( arg0.getValue() ); d = g_oFormatParser.parseDate( arg0.getValue() );
if ( d == null ) { if ( d == null ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
val = d.value; val = d.value;
} }
...@@ -1224,10 +1224,10 @@ cSECOND.prototype.Calculate = function ( arg ) { ...@@ -1224,10 +1224,10 @@ cSECOND.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else { else {
val = parseInt( (( val * 24 * 60 - Math.floor( val * 24 * 60 ) ) * 60).toFixed( cExcelDateTimeDigits ) ) % 60; val = parseInt( (( val * 24 * 60 - Math.floor( val * 24 * 60 ) ) * 60).toFixed( cExcelDateTimeDigits ) ) % 60;
return this.setCA( new cNumber( val ), true, 0 ); return this.setCA( new CNumber( val ), true, 0 );
} }
} }
cSECOND.prototype.getInfo = function () { cSECOND.prototype.getInfo = function () {
...@@ -1259,22 +1259,22 @@ cTIME.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1259,22 +1259,22 @@ cTIME.prototype = Object.create( cBaseFunction.prototype )
cTIME.prototype.Calculate = function ( arg ) { cTIME.prototype.Calculate = function ( arg ) {
var hour = arg[0], minute = arg[1], second = arg[2]; var hour = arg[0], minute = arg[1], second = arg[2];
if ( hour instanceof cArea || hour instanceof cArea3D ) { if ( hour instanceof CArea || hour instanceof CArea3D ) {
hour = hour.cross( arguments[1].first ); hour = hour.cross( arguments[1].first );
} }
else if ( hour instanceof cArray ) { else if ( hour instanceof CArray ) {
hour = hour.getElement( 0 ); hour = hour.getElement( 0 );
} }
if ( minute instanceof cArea || minute instanceof cArea3D ) { if ( minute instanceof CArea || minute instanceof CArea3D ) {
minute = minute.cross( arguments[1].first ); minute = minute.cross( arguments[1].first );
} }
else if ( minute instanceof cArray ) { else if ( minute instanceof CArray ) {
minute = minute.getElement( 0 ); minute = minute.getElement( 0 );
} }
if ( second instanceof cArea || second instanceof cArea3D ) { if ( second instanceof CArea || second instanceof CArea3D ) {
second = second.cross( arguments[1].first ); second = second.cross( arguments[1].first );
} }
else if ( second instanceof cArray ) { else if ( second instanceof CArray ) {
second = second.getElement( 0 ); second = second.getElement( 0 );
} }
...@@ -1282,16 +1282,16 @@ cTIME.prototype.Calculate = function ( arg ) { ...@@ -1282,16 +1282,16 @@ cTIME.prototype.Calculate = function ( arg ) {
minute = minute.tocNumber(); minute = minute.tocNumber();
second = second.tocNumber(); second = second.tocNumber();
if ( hour instanceof cError ) return this.setCA( hour, true ); if ( hour instanceof CError ) return this.setCA( hour, true );
if ( minute instanceof cError ) return this.setCA( minute, true ); if ( minute instanceof CError ) return this.setCA( minute, true );
if ( second instanceof cError ) return this.setCA( second, true ); if ( second instanceof CError ) return this.setCA( second, true );
hour = hour.getValue(); hour = hour.getValue();
minute = minute.getValue(); minute = minute.getValue();
second = second.getValue(); second = second.getValue();
var v = (hour * 60 * 60 + minute * 60 + second) / c_sPerDay; var v = (hour * 60 * 60 + minute * 60 + second) / c_sPerDay;
this.setCA( new cNumber( v - Math.floor( v ) ), true ); this.setCA( new CNumber( v - Math.floor( v ) ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
this.value.numFormat = 18; this.value.numFormat = 18;
return this.value; return this.value;
...@@ -1326,27 +1326,27 @@ cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1326,27 +1326,27 @@ cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype )
cTIMEVALUE.prototype.Calculate = function ( arg ) { cTIMEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg0.tocNumber() instanceof cNumber && arg0.tocNumber().getValue() > 0 ) if ( arg0.tocNumber() instanceof CNumber && arg0.tocNumber().getValue() > 0 )
return this.value = new cNumber( parseInt( arg0.tocNumber().getValue() ) ); return this.value = new CNumber( parseInt( arg0.tocNumber().getValue() ) );
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res && res.bDateTime ) if ( res && res.bDateTime )
return this.value = new cNumber( res.value - parseInt( res.value ) ); return this.value = new CNumber( res.value - parseInt( res.value ) );
else else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cTIMEVALUE.prototype.getInfo = function () { cTIMEVALUE.prototype.getInfo = function () {
return { return {
...@@ -1375,7 +1375,7 @@ function cTODAY() { ...@@ -1375,7 +1375,7 @@ function cTODAY() {
} }
cTODAY.prototype = Object.create( cBaseFunction.prototype ) cTODAY.prototype = Object.create( cBaseFunction.prototype )
cTODAY.prototype.Calculate = function () { cTODAY.prototype.Calculate = function () {
this.setCA( new cNumber( new Date().getExcelDate() ), true ); this.setCA( new CNumber( new Date().getExcelDate() ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
this.value.numFormat = 14; this.value.numFormat = 14;
return this.value; return this.value;
...@@ -1408,29 +1408,29 @@ function cWEEKDAY() { ...@@ -1408,29 +1408,29 @@ function cWEEKDAY() {
} }
cWEEKDAY.prototype = Object.create( cBaseFunction.prototype ) cWEEKDAY.prototype = Object.create( cBaseFunction.prototype )
cWEEKDAY.prototype.Calculate = function ( arg ) { cWEEKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 ); var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new CNumber( 1 );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
var weekday; var weekday;
...@@ -1463,12 +1463,12 @@ cWEEKDAY.prototype.Calculate = function ( arg ) { ...@@ -1463,12 +1463,12 @@ cWEEKDAY.prototype.Calculate = function ( arg ) {
weekday = [2, 3, 4, 5, 6, 7, 1]; weekday = [2, 3, 4, 5, 6, 7, 1];
break; break;
default: default:
return this.value = new cError( cErrorType.not_numeric ); return this.value = new CError( cErrorType.not_numeric );
} }
if ( arg0.getValue() < 0 ) if ( arg0.getValue() < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
return this.value = new cNumber( weekday[new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ).getDay()] ); return this.value = new CNumber( weekday[new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ).getDay()] );
} }
cWEEKDAY.prototype.getInfo = function () { cWEEKDAY.prototype.getInfo = function () {
return { return {
...@@ -1498,7 +1498,7 @@ function cWEEKNUM() { ...@@ -1498,7 +1498,7 @@ function cWEEKNUM() {
} }
cWEEKNUM.prototype = Object.create( cBaseFunction.prototype ) cWEEKNUM.prototype = Object.create( cBaseFunction.prototype )
cWEEKNUM.prototype.Calculate = function ( arg ) { cWEEKNUM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 ), type = 0; var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new CNumber( 1 ), type = 0;
function WeekNumber( dt, iso, type ) { function WeekNumber( dt, iso, type ) {
dt.setHours( 0, 0, 0 ); dt.setHours( 0, 0, 0 );
...@@ -1516,43 +1516,43 @@ cWEEKNUM.prototype.Calculate = function ( arg ) { ...@@ -1516,43 +1516,43 @@ cWEEKNUM.prototype.Calculate = function ( arg ) {
case 53: case 53:
// Если 31 декабря выпадает до четверга 1 недели следующего года // Если 31 декабря выпадает до четверга 1 недели следующего года
if ( endOfYear.getDay() < 4 ) if ( endOfYear.getDay() < 4 )
return new cNumber( 1 ); return new CNumber( 1 );
else else
return new cNumber( wk ); return new CNumber( wk );
default: default:
return new cNumber( wk ); return new CNumber( wk );
} }
else { else {
wk = parseInt( ((dt - startOfYear) / c_msPerDay + iso[startOfYear.getDay()] + 7) / 7 ); wk = parseInt( ((dt - startOfYear) / c_msPerDay + iso[startOfYear.getDay()] + 7) / 7 );
return new cNumber( wk ); return new CNumber( wk );
} }
} }
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
if ( arg0.getValue() < 0 ) if ( arg0.getValue() < 0 )
return this.value = new cError( cErrorType.not_numeric ); return this.value = new CError( cErrorType.not_numeric );
var weekdayStartDay; var weekdayStartDay;
...@@ -1586,10 +1586,10 @@ cWEEKNUM.prototype.Calculate = function ( arg ) { ...@@ -1586,10 +1586,10 @@ cWEEKNUM.prototype.Calculate = function ( arg ) {
type = 1; type = 1;
break; break;
default: default:
return this.value = new cError( cErrorType.not_numeric ); return this.value = new CError( cErrorType.not_numeric );
} }
return this.value = new cNumber( WeekNumber( new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ), weekdayStartDay, type ) ); return this.value = new CNumber( WeekNumber( new Date( (arg0.getValue() - (c_DateCorrectConst + 1)) * c_msPerDay ), weekdayStartDay, type ) );
} }
cWEEKNUM.prototype.getInfo = function () { cWEEKNUM.prototype.getInfo = function () {
...@@ -1622,30 +1622,30 @@ cWORKDAY.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1622,30 +1622,30 @@ cWORKDAY.prototype = Object.create( cBaseFunction.prototype )
cWORKDAY.prototype.Calculate = function ( arg ) { cWORKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = []; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var val0 = arg0.getValue(), val1 = arg1.getValue(), holidays = [] var val0 = arg0.getValue(), val1 = arg1.getValue(), holidays = []
if ( val0 < 0 ) if ( val0 < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
else if ( !g_bDate1904 ) { else if ( !g_bDate1904 ) {
if ( val0 < 60 ) if ( val0 < 60 )
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
...@@ -1658,23 +1658,23 @@ cWORKDAY.prototype.Calculate = function ( arg ) { ...@@ -1658,23 +1658,23 @@ cWORKDAY.prototype.Calculate = function ( arg ) {
val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay ); val0 = new Date( (val0 - c_DateCorrectConst) * c_msPerDay );
if ( arg2 ) { if ( arg2 ) {
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
var arr = arg2.getValue(); var arr = arg2.getValue();
for ( var i = 0; i < arr.length; i++ ) { for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] instanceof cNumber && arr[i].getValue() >= 0 ) { if ( arr[i] instanceof CNumber && arr[i].getValue() >= 0 ) {
holidays.push( arr[i] ); holidays.push( arr[i] );
} }
} }
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2.foreach( function ( elem, r, c ) { arg2.foreach( function ( elem, r, c ) {
if ( elem instanceof cNumber ) { if ( elem instanceof CNumber ) {
holidays.push( elem ); holidays.push( elem );
} }
else if ( elem instanceof cString ) { else if ( elem instanceof CString ) {
var res = g_oFormatParser.parse( elem.getValue() ); var res = g_oFormatParser.parse( elem.getValue() );
if ( res && res.bDateTime && res.value >= 0 ) if ( res && res.bDateTime && res.value >= 0 )
holidays.push( new cNumber( parseInt( res.value ) ) ); holidays.push( new CNumber( parseInt( res.value ) ) );
} }
} ) } )
} }
...@@ -1712,12 +1712,12 @@ cWORKDAY.prototype.Calculate = function ( arg ) { ...@@ -1712,12 +1712,12 @@ cWORKDAY.prototype.Calculate = function ( arg ) {
val = parseInt( ( date.getTime() / 1000 - date.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = parseInt( ( date.getTime() / 1000 - date.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
return this.setCA( new cNumber( val ), true, 14 ); return this.setCA( new CNumber( val ), true, 14 );
else else
return this.setCA( new cNumber( val ), true ); return this.setCA( new CNumber( val ), true );
} }
cWORKDAY.prototype.getInfo = function () { cWORKDAY.prototype.getInfo = function () {
return { return {
...@@ -1753,36 +1753,36 @@ function cYEAR() { ...@@ -1753,36 +1753,36 @@ function cYEAR() {
cYEAR.prototype = Object.create( cBaseFunction.prototype ) cYEAR.prototype = Object.create( cBaseFunction.prototype )
cYEAR.prototype.Calculate = function ( arg ) { cYEAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val; var arg0 = arg[0], val;
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cError ) return this.setCA( arg0, true ); if ( arg0 instanceof CError ) return this.setCA( arg0, true );
else if ( arg0 instanceof cNumber || arg0 instanceof cBool ) { else if ( arg0 instanceof CNumber || arg0 instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
val = arg0.getValue(); val = arg0.getValue();
if ( val instanceof cError ) return this.setCA( val, true ); if ( val instanceof CError ) return this.setCA( val, true );
else if ( val instanceof cNumber || val instanceof cBool ) { else if ( val instanceof CNumber || val instanceof CBool ) {
val = arg0.tocNumber().getValue(); val = arg0.tocNumber().getValue();
} }
else { else {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
} }
else if ( arg0 instanceof cString ) { else if ( arg0 instanceof CString ) {
val = arg0.tocNumber(); val = arg0.tocNumber();
if ( val instanceof cError || val instanceof cEmpty ) { if ( val instanceof CError || val instanceof CEmpty ) {
var d = new Date( arg0.getValue() ); var d = new Date( arg0.getValue() );
if ( isNaN( d ) ) { if ( isNaN( d ) ) {
return this.setCA( new cError( cErrorType.wrong_value_type ), true ); return this.setCA( new CError( cErrorType.wrong_value_type ), true );
} }
else else
val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ); val = Math.floor( ( d.getTime() / 1000 - d.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) );
...@@ -1792,9 +1792,9 @@ cYEAR.prototype.Calculate = function ( arg ) { ...@@ -1792,9 +1792,9 @@ cYEAR.prototype.Calculate = function ( arg ) {
} }
} }
if ( val < 0 ) if ( val < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true, 0 ); return this.setCA( new CError( cErrorType.not_numeric ), true, 0 );
else else
return this.setCA( new cNumber( (new Date( (val - (c_DateCorrectConst + 1)) * c_msPerDay )).getUTCFullYear() ), true, 0 ); return this.setCA( new CNumber( (new Date( (val - (c_DateCorrectConst + 1)) * c_msPerDay )).getUTCFullYear() ), true, 0 );
} }
cYEAR.prototype.getInfo = function () { cYEAR.prototype.getInfo = function () {
return { return {
...@@ -1824,25 +1824,25 @@ function cYEARFRAC() { ...@@ -1824,25 +1824,25 @@ function cYEARFRAC() {
} }
cYEARFRAC.prototype = Object.create( cBaseFunction.prototype ) cYEARFRAC.prototype = Object.create( cBaseFunction.prototype )
cYEARFRAC.prototype.Calculate = function ( arg ) { cYEARFRAC.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 0 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber( 0 );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
...@@ -1850,14 +1850,14 @@ cYEARFRAC.prototype.Calculate = function ( arg ) { ...@@ -1850,14 +1850,14 @@ cYEARFRAC.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
var val0 = arg0.getValue(), val1 = arg1.getValue(); var val0 = arg0.getValue(), val1 = arg1.getValue();
if ( val0 < 0 || val1 < 0 ) if ( val0 < 0 || val1 < 0 )
return this.setCA( new cError( cErrorType.not_numeric ), true ); return this.setCA( new CError( cErrorType.not_numeric ), true );
val0 = Date.prototype.getDateFromExcel( val0 ); val0 = Date.prototype.getDateFromExcel( val0 );
val1 = Date.prototype.getDateFromExcel( val1 ); val1 = Date.prototype.getDateFromExcel( val1 );
......
"use strict"; "use strict";
function ConvertToDec( aStrSource, nBase, nCharLim ){ function ConvertToDec( aStrSource, nBase, nCharLim ){
if ( nBase < 2 || nBase > 36 ) if ( nBase < 2 || nBase > 36 ){
return "Error #1"; return "Error #1";}
var nStrLen = aStrSource.length; var nStrLen = aStrSource.length;
if( nStrLen > nCharLim ) if( nStrLen > nCharLim ){
return "Error #2"; return "Error #2";}
else if( !nStrLen ) else if( !nStrLen ){
return 0; return 0;}
var fVal = 0; var fVal = 0, nFirstDig = 0,
bFirstDig = true;
var p = aStrSource; for(var i=0; i < aStrSource.length; i++)
var nFirstDig = 0;
var bFirstDig = true;
var fBase = nBase;
for(var i=0; i < p.length; i++)
{ {
var n; var n;
if( '0' <= p[i] && p[i] <= '9' ) if( '0' <= aStrSource[i] && aStrSource[i] <= '9' ){
n = p[i].charCodeAt() - '0'.charCodeAt(); n = aStrSource[i].charCodeAt(0) - '0'.charCodeAt(0);}
else if( 'A' <= p[i] && p[i] <= 'Z' ) else if( 'A' <= aStrSource[i] && aStrSource[i] <= 'Z' ){
n = 10 + ( p[i].charCodeAt() - 'A'.charCodeAt() ); n = 10 + ( aStrSource[i].charCodeAt(0) - 'A'.charCodeAt(0) );}
else if ( 'a' <= p[i] && p[i] <= 'z' ) else if ( 'a' <= aStrSource[i] && aStrSource[i] <= 'z' ){
n = 10 + ( p[i].charCodeAt() - 'a'.charCodeAt() ); n = 10 + ( aStrSource[i].charCodeAt(0) - 'a'.charCodeAt(0) );}
else else{
n = nBase; n = nBase;}
if( n < nBase ) if( n < nBase )
{ {
...@@ -38,13 +33,13 @@ function ConvertToDec( aStrSource, nBase, nCharLim ){ ...@@ -38,13 +33,13 @@ function ConvertToDec( aStrSource, nBase, nCharLim ){
bFirstDig = false; bFirstDig = false;
nFirstDig = n; nFirstDig = n;
} }
fVal = fVal * fBase + n; fVal = fVal * nBase + n;
} }
else else{
return "Error #3" return "Error #3";}
} }
if( nStrLen == nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) ) if( nStrLen === nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) )
{ // handling negativ values { // handling negativ values
fVal = ( Math.pow( nBase, nCharLim ) - fVal ); // complement fVal = ( Math.pow( nBase, nCharLim ) - fVal ); // complement
fVal *= -1.0; fVal *= -1.0;
...@@ -53,6 +48,302 @@ function ConvertToDec( aStrSource, nBase, nCharLim ){ ...@@ -53,6 +48,302 @@ function ConvertToDec( aStrSource, nBase, nCharLim ){
return fVal; return fVal;
} }
var f_PI_DIV_2 = Math.PI / 2.0;
var f_PI_DIV_4 = Math.PI / 4.0;
var f_2_DIV_PI = 2.0 / Math.PI;
function BesselJ( x, N ) {
if ( N < 0 ){
return new CError( cErrorType.not_numeric );}
if ( x === 0.0 ){
return new CNumber( (N == 0) ? 1 : 0 );}
/* The algorithm works only for x>0, therefore remember sign. BesselJ
with integer order N is an even function for even N (means J(-x)=J(x))
and an odd function for odd N (means J(-x)=-J(x)).*/
var fSign = (N % 2 == 1 && x < 0) ? -1 : 1;
var fX = Math.abs( x );
var fMaxIteration = 9000000; //experimental, for to return in < 3 seconds
var fEstimateIteration = fX * 1.5 + N;
var bAsymptoticPossible = Math.pow( fX, 0.4 ) > N;
if ( fEstimateIteration > fMaxIteration ) {
if ( bAsymptoticPossible ){
return new CNumber(fSign * Math.sqrt( f_2_DIV_PI / fX ) * Math.cos( fX - N * f_PI_DIV_2 - f_PI_DIV_4 ) );}
else{
return new CError(cErrorType.not_numeric);}
}
var epsilon = 1.0e-15; // relative error
var bHasfound = false, k = 0, u;
// first used with k=1
var m_bar, g_bar, g_bar_delta_u, g = 0, delta_u = 0, f_bar = -1; // f_bar_k = 1/f_k, but only used for k=0
if ( N == 0 ) {
u = 1;
g_bar_delta_u = 0;
g_bar = -2 / fX;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
k = 2;
}
else {
u = 0;
for ( k = 1; k <= N - 1; k = k + 1 ) {
m_bar = 2 * Math.fmod( k - 1, 2 ) * f_bar;
g_bar_delta_u = -g * delta_u - m_bar * u; // alpha_k = 0.0
g_bar = m_bar - 2 * k / fX + g;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
}
// Step alpha_N = 1.0
m_bar = 2 * Math.fmod( k - 1, 2 ) * f_bar;
g_bar_delta_u = f_bar - g * delta_u - m_bar * u; // alpha_k = 1.0
g_bar = m_bar - 2 * k / fX + g;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
k = k + 1;
}
// Loop until desired accuracy, always alpha_k = 0.0
do {
m_bar = 2 * Math.fmod( k - 1, 2 ) * f_bar;
g_bar_delta_u = -g * delta_u - m_bar * u;
g_bar = m_bar - 2 * k / fX + g;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
bHasfound = (Math.abs( delta_u ) <= Math.abs( u ) * epsilon);
k = k + 1;
}
while ( !bHasfound && k <= fMaxIteration );
if ( bHasfound ){
return new CNumber( u * fSign );}
else{
return new CError(cErrorType.not_numeric);}// unlikely to happen
}
function BesselI( x, n ) {
var nMaxIteration = 2000, fXHalf = x / 2, fResult = 0;
if ( n < 0 ){
return new CError( cErrorType.not_numeric );}
/* Start the iteration without TERM(n,0), which is set here.
TERM(n,0) = (x/2)^n / n!
*/
var nK = 0, fTerm = 1;
// avoid overflow in Fak(n)
for ( nK = 1; nK <= n; ++nK ) {
fTerm = fTerm / nK * fXHalf;
}
fResult = fTerm; // Start result with TERM(n,0).
if ( fTerm !== 0 ) {
nK = 1;
var fEpsilon = 1.0E-15;
do
{
/* Calculation of TERM(n,k) from TERM(n,k-1):
(x/2)^(n+2k)
TERM(n,k) = --------------
k! (n+k)!
(x/2)^2 (x/2)^(n+2(k-1))
= --------------------------
k (k-1)! (n+k) (n+k-1)!
(x/2)^2 (x/2)^(n+2(k-1))
= --------- * ------------------
k(n+k) (k-1)! (n+k-1)!
x^2/4
= -------- TERM(n,k-1)
k(n+k)
*/
fTerm = fTerm * fXHalf / nK * fXHalf / (nK + n);
fResult += fTerm;
nK++;
}
while ( (Math.abs( fTerm ) > Math.abs( fResult ) * fEpsilon) && (nK < nMaxIteration) );
}
return new CNumber( fResult );
}
function Besselk0( fNum ) {
var fRet,y;
if ( fNum <= 2 ) {
var fNum2 = fNum * 0.5;
y = fNum2 * fNum2;
fRet = -Math.log10( fNum2 ) * BesselI( fNum, 0 ) +
( -0.57721566 + y * ( 0.42278420 + y * ( 0.23069756 + y * ( 0.3488590e-1 + y * ( 0.262698e-2 + y * ( 0.10750e-3 + y * 0.74e-5 ) ) ) ) ) );
}
else {
y = 2 / fNum;
fRet = Math.exp( -fNum ) / Math.sqrt( fNum ) *
( 1.25331414 + y * ( -0.7832358e-1 + y * ( 0.2189568e-1 + y * ( -0.1062446e-1 + y * ( 0.587872e-2 + y * ( -0.251540e-2 + y * 0.53208e-3 ) ) ) ) ) );
}
return fRet;
}
function Besselk1( fNum ) {
var fRet, y;
if ( fNum <= 2 ) {
var fNum2 = fNum * 0.5;
y = fNum2 * fNum2;
fRet = Math.log10( fNum2 ) * BesselI( fNum, 1 ) +
( 1 + y * ( 0.15443144 + y * ( -0.67278579 + y * ( -0.18156897 + y * ( -0.1919402e-1 + y * ( -0.110404e-2 + y * ( -0.4686e-4 ) ) ) ) ) ) ) / fNum;
}
else {
y = 2 / fNum;
fRet = Math.exp( -fNum ) / Math.sqrt( fNum ) *
( 1.25331414 + y * ( 0.23498619 + y * ( -0.3655620e-1 + y * ( 0.1504268e-1 + y * ( -0.780353e-2 + y * ( 0.325614e-2 + y * ( -0.68245e-3 ) ) ) ) ) ) );
}
return fRet;
}
function BesselK( fNum, nOrder ) {
switch ( nOrder ) {
case 0:
return Besselk0( fNum );
case 1:
return Besselk1( fNum );
default:
{
var fBkp;
var fTox = 2 / fNum, fBkm = Besselk0( fNum ), fBk = Besselk1( fNum );
for ( var n = 1; n < nOrder; n++ ) {
fBkp = fBkm + n * fTox * fBk;
fBkm = fBk;
fBk = fBkp;
}
return fBk;
}
}
}
function Bessely0( fX ) {
if ( fX <= 0 )
return new CError( cErrorType.not_numeric );
var fMaxIteration = 9000000; // should not be reached
if ( fX > 5.0e+6 ) // iteration is not considerable better then approximation
return Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) - Math.cos( fX ));
var epsilon = 1.0e-15, EulerGamma = 0.57721566490153286060;
var alpha = Math.log10( fX / 2 ) + EulerGamma;
var u = alpha;
var k = 1, m_bar = 0, g_bar_delta_u = 0, g_bar = -2 / fX;
var delta_u = g_bar_delta_u / g_bar, g = -1 / g_bar, f_bar = -1 * g,
sign_alpha = 1, km1mod2, bHasFound = false;
k = k + 1;
do
{
km1mod2 = Math.fmod( k - 1, 2 );
m_bar = (2 * km1mod2) * f_bar;
if ( km1mod2 == 0 )
alpha = 0;
else {
alpha = sign_alpha * (4 / k);
sign_alpha = -sign_alpha;
}
g_bar_delta_u = f_bar * alpha - g * delta_u - m_bar * u;
g_bar = m_bar - (2 * k) / fX + g;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
bHasFound = (Math.abs( delta_u ) <= Math.abs( u ) * epsilon);
k = k + 1;
}
while ( !bHasFound && k < fMaxIteration );
if ( bHasFound )
return u * f_2_DIV_PI;
else
return new CError( cErrorType.not_numeric );
}
// See #i31656# for a commented version of this implementation, attachment #desc6
// http://www.openoffice.org/nonav/issues/showattachment.cgi/63609/Comments%20to%20the%20implementation%20of%20the%20Bessel%20functions.odt
function Bessely1( fX ) {
if ( fX <= 0 )
return new CError( cErrorType.not_numeric );
var fMaxIteration = 9000000; // should not be reached
if ( fX > 5e+6 ) // iteration is not considerable better then approximation
return -Math.sqrt( 1 / Math.PI / fX ) * (Math.sin( fX ) + Math.cos( fX ));
var epsilon = 1.0e-15, EulerGamma = 0.57721566490153286060, alpha = 1 / fX, f_bar = -1, u = alpha, k = 1, m_bar = 0;
alpha = 1 - EulerGamma - Math.log10( fX / 2 );
var g_bar_delta_u = -alpha, g_bar = -2 / fX, delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
var g = -1 / g_bar;
f_bar = f_bar * g;
var sign_alpha = -1, km1mod2, //will be (k-1) mod 2
q, // will be (k-1) div 2
bHasFound = false;
k = k + 1;
do
{
km1mod2 = Math.fmod( k - 1, 2 );
m_bar = (2 * km1mod2) * f_bar;
q = (k - 1) / 2;
if ( km1mod2 == 0 ) // k is odd
{
alpha = sign_alpha * (1 / q + 1 / (q + 1));
sign_alpha = -sign_alpha;
}
else
alpha = 0;
g_bar_delta_u = f_bar * alpha - g * delta_u - m_bar * u;
g_bar = m_bar - (2 * k) / fX + g;
delta_u = g_bar_delta_u / g_bar;
u = u + delta_u;
g = -1 / g_bar;
f_bar = f_bar * g;
bHasFound = (Math.abs( delta_u ) <= Math.abs( u ) * epsilon);
k = k + 1;
}
while ( !bHasFound && k < fMaxIteration );
if ( bHasFound )
return -u * 2 / Math.PI;
else
return new CError( cErrorType.not_numeric );
}
function BesselY( fNum, nOrder ) {
switch ( nOrder ) {
case 0:
return Bessely0( fNum );
case 1:
return Bessely1( fNum );
default:
{
var fByp, fTox = 2 / fNum, fBym = Bessely0( fNum ), fBy = Bessely1( fNum );
for ( var n = 1; n < nOrder; n++ ) {
fByp = n * fTox * fBy - fBym;
fBym = fBy;
fBy = fByp;
}
return fBy;
}
}
}
/** /**
* Created with JetBrains WebStorm. * Created with JetBrains WebStorm.
* User: Dmitry.Shahtanov * User: Dmitry.Shahtanov
...@@ -101,199 +392,199 @@ cFormulaFunction.Engineering = { ...@@ -101,199 +392,199 @@ cFormulaFunction.Engineering = {
'OCT2BIN':cOCT2BIN, 'OCT2BIN':cOCT2BIN,
'OCT2DEC':cOCT2DEC, 'OCT2DEC':cOCT2DEC,
'OCT2HEX':cOCT2HEX 'OCT2HEX':cOCT2HEX
} };
function cBESSELI() { function cBESSELI() {
cBaseFunction.call( this, "BESSELI" ); cBaseFunction.call( this, "BESSELI" );
} }
cBESSELI.prototype = Object.create( cBaseFunction.prototype ) cBESSELI.prototype = Object.create( cBaseFunction.prototype );
function cBESSELJ() { function cBESSELJ() {
cBaseFunction.call( this, "BESSELJ" ); cBaseFunction.call( this, "BESSELJ" );
} }
cBESSELJ.prototype = Object.create( cBaseFunction.prototype ) cBESSELJ.prototype = Object.create( cBaseFunction.prototype );
function cBESSELK() { function cBESSELK() {
cBaseFunction.call( this, "BESSELK" ); cBaseFunction.call( this, "BESSELK" );
} }
cBESSELK.prototype = Object.create( cBaseFunction.prototype ) cBESSELK.prototype = Object.create( cBaseFunction.prototype );
function cBESSELY() { function cBESSELY() {
cBaseFunction.call( this, "BESSELY" ); cBaseFunction.call( this, "BESSELY" );
} }
cBESSELY.prototype = Object.create( cBaseFunction.prototype ) cBESSELY.prototype = Object.create( cBaseFunction.prototype );
function cBIN2DEC() { function cBIN2DEC() {
cBaseFunction.call( this, "BIN2DEC" ); cBaseFunction.call( this, "BIN2DEC" );
} }
cBIN2DEC.prototype = Object.create( cBaseFunction.prototype ) cBIN2DEC.prototype = Object.create( cBaseFunction.prototype );
function cBIN2HEX() { function cBIN2HEX() {
cBaseFunction.call( this, "BIN2HEX" ); cBaseFunction.call( this, "BIN2HEX" );
} }
cBIN2HEX.prototype = Object.create( cBaseFunction.prototype ) cBIN2HEX.prototype = Object.create( cBaseFunction.prototype );
function cBIN2OCT() { function cBIN2OCT() {
cBaseFunction.call( this, "BIN2OCT" ); cBaseFunction.call( this, "BIN2OCT" );
} }
cBIN2OCT.prototype = Object.create( cBaseFunction.prototype ) cBIN2OCT.prototype = Object.create( cBaseFunction.prototype );
function cCOMPLEX() { function cCOMPLEX() {
cBaseFunction.call( this, "COMPLEX" ); cBaseFunction.call( this, "COMPLEX" );
} }
cCOMPLEX.prototype = Object.create( cBaseFunction.prototype ) cCOMPLEX.prototype = Object.create( cBaseFunction.prototype );
function cCONVERT() { function cCONVERT() {
cBaseFunction.call( this, "CONVERT" ); cBaseFunction.call( this, "CONVERT" );
} }
cCONVERT.prototype = Object.create( cBaseFunction.prototype ) cCONVERT.prototype = Object.create( cBaseFunction.prototype );
function cDEC2BIN() { function cDEC2BIN() {
cBaseFunction.call( this, "DEC2BIN" ); cBaseFunction.call( this, "DEC2BIN" );
} }
cDEC2BIN.prototype = Object.create( cBaseFunction.prototype ) cDEC2BIN.prototype = Object.create( cBaseFunction.prototype );
function cDEC2HEX() { function cDEC2HEX() {
cBaseFunction.call( this, "DEC2HEX" ); cBaseFunction.call( this, "DEC2HEX" );
} }
cDEC2HEX.prototype = Object.create( cBaseFunction.prototype ) cDEC2HEX.prototype = Object.create( cBaseFunction.prototype );
function cDEC2OCT() { function cDEC2OCT() {
cBaseFunction.call( this, "DEC2OCT" ); cBaseFunction.call( this, "DEC2OCT" );
} }
cDEC2OCT.prototype = Object.create( cBaseFunction.prototype ) cDEC2OCT.prototype = Object.create( cBaseFunction.prototype );
function cDELTA() { function cDELTA() {
cBaseFunction.call( this, "DELTA" ); cBaseFunction.call( this, "DELTA" );
} }
cDELTA.prototype = Object.create( cBaseFunction.prototype ) cDELTA.prototype = Object.create( cBaseFunction.prototype );
function cERF() { function cERF() {
cBaseFunction.call( this, "ERF" ); cBaseFunction.call( this, "ERF" );
} }
cERF.prototype = Object.create( cBaseFunction.prototype ) cERF.prototype = Object.create( cBaseFunction.prototype );
function cERFC() { function cERFC() {
cBaseFunction.call( this, "ERFC" ); cBaseFunction.call( this, "ERFC" );
} }
cERFC.prototype = Object.create( cBaseFunction.prototype ) cERFC.prototype = Object.create( cBaseFunction.prototype );
function cGESTEP() { function cGESTEP() {
cBaseFunction.call( this, "GESTEP" ); cBaseFunction.call( this, "GESTEP" );
} }
cGESTEP.prototype = Object.create( cBaseFunction.prototype ) cGESTEP.prototype = Object.create( cBaseFunction.prototype );
function cHEX2BIN() { function cHEX2BIN() {
cBaseFunction.call( this, "HEX2BIN" ); cBaseFunction.call( this, "HEX2BIN" );
} }
cHEX2BIN.prototype = Object.create( cBaseFunction.prototype ) cHEX2BIN.prototype = Object.create( cBaseFunction.prototype );
function cHEX2DEC() { function cHEX2DEC() {
cBaseFunction.call( this, "HEX2DEC" ); cBaseFunction.call( this, "HEX2DEC" );
} }
cHEX2DEC.prototype = Object.create( cBaseFunction.prototype ) cHEX2DEC.prototype = Object.create( cBaseFunction.prototype );
function cHEX2OCT() { function cHEX2OCT() {
cBaseFunction.call( this, "HEX2OCT" ); cBaseFunction.call( this, "HEX2OCT" );
} }
cHEX2OCT.prototype = Object.create( cBaseFunction.prototype ) cHEX2OCT.prototype = Object.create( cBaseFunction.prototype );
function cIMABS() { function cIMABS() {
cBaseFunction.call( this, "IMABS" ); cBaseFunction.call( this, "IMABS" );
} }
cIMABS.prototype = Object.create( cBaseFunction.prototype ) cIMABS.prototype = Object.create( cBaseFunction.prototype );
function cIMAGINARY() { function cIMAGINARY() {
cBaseFunction.call( this, "IMAGINARY" ); cBaseFunction.call( this, "IMAGINARY" );
} }
cIMAGINARY.prototype = Object.create( cBaseFunction.prototype ) cIMAGINARY.prototype = Object.create( cBaseFunction.prototype );
function cIMARGUMENT() { function cIMARGUMENT() {
cBaseFunction.call( this, "IMARGUMENT" ); cBaseFunction.call( this, "IMARGUMENT" );
} }
cIMARGUMENT.prototype = Object.create( cBaseFunction.prototype ) cIMARGUMENT.prototype = Object.create( cBaseFunction.prototype );
function cIMCONJUGATE() { function cIMCONJUGATE() {
cBaseFunction.call( this, "IMCONJUGATE" ); cBaseFunction.call( this, "IMCONJUGATE" );
} }
cIMCONJUGATE.prototype = Object.create( cBaseFunction.prototype ) cIMCONJUGATE.prototype = Object.create( cBaseFunction.prototype );
function cIMCOS() { function cIMCOS() {
cBaseFunction.call( this, "IMCOS" ); cBaseFunction.call( this, "IMCOS" );
} }
cIMCOS.prototype = Object.create( cBaseFunction.prototype ) cIMCOS.prototype = Object.create( cBaseFunction.prototype );
function cIMDIV() { function cIMDIV() {
cBaseFunction.call( this, "IMDIV" ); cBaseFunction.call( this, "IMDIV" );
} }
cIMDIV.prototype = Object.create( cBaseFunction.prototype ) cIMDIV.prototype = Object.create( cBaseFunction.prototype );
function cIMEXP() { function cIMEXP() {
cBaseFunction.call( this, "IMEXP" ); cBaseFunction.call( this, "IMEXP" );
} }
cIMEXP.prototype = Object.create( cBaseFunction.prototype ) cIMEXP.prototype = Object.create( cBaseFunction.prototype );
function cIMLN() { function cIMLN() {
cBaseFunction.call( this, "IMLN" ); cBaseFunction.call( this, "IMLN" );
} }
cIMLN.prototype = Object.create( cBaseFunction.prototype ) cIMLN.prototype = Object.create( cBaseFunction.prototype );
function cIMLOG10() { function cIMLOG10() {
cBaseFunction.call( this, "IMLOG10" ); cBaseFunction.call( this, "IMLOG10" );
} }
cIMLOG10.prototype = Object.create( cBaseFunction.prototype ) cIMLOG10.prototype = Object.create( cBaseFunction.prototype );
function cIMLOG2() { function cIMLOG2() {
cBaseFunction.call( this, "IMLOG2" ); cBaseFunction.call( this, "IMLOG2" );
} }
cIMLOG2.prototype = Object.create( cBaseFunction.prototype ) cIMLOG2.prototype = Object.create( cBaseFunction.prototype );
function cIMPOWER() { function cIMPOWER() {
cBaseFunction.call( this, "IMPOWER" ); cBaseFunction.call( this, "IMPOWER" );
} }
cIMPOWER.prototype = Object.create( cBaseFunction.prototype ) cIMPOWER.prototype = Object.create( cBaseFunction.prototype );
function cIMPRODUCT() { function cIMPRODUCT() {
cBaseFunction.call( this, "IMPRODUCT" ); cBaseFunction.call( this, "IMPRODUCT" );
} }
cIMPRODUCT.prototype = Object.create( cBaseFunction.prototype ) cIMPRODUCT.prototype = Object.create( cBaseFunction.prototype );
function cIMREAL() { function cIMREAL() {
cBaseFunction.call( this, "IMREAL" ); cBaseFunction.call( this, "IMREAL" );
} }
cIMREAL.prototype = Object.create( cBaseFunction.prototype ) cIMREAL.prototype = Object.create( cBaseFunction.prototype );
function cIMSIN() { function cIMSIN() {
cBaseFunction.call( this, "IMSIN" ); cBaseFunction.call( this, "IMSIN" );
} }
cIMSIN.prototype = Object.create( cBaseFunction.prototype ) cIMSIN.prototype = Object.create( cBaseFunction.prototype );
function cIMSQRT() { function cIMSQRT() {
cBaseFunction.call( this, "IMSQRT" ); cBaseFunction.call( this, "IMSQRT" );
} }
cIMSQRT.prototype = Object.create( cBaseFunction.prototype ) cIMSQRT.prototype = Object.create( cBaseFunction.prototype );
function cIMSUB() { function cIMSUB() {
cBaseFunction.call( this, "IMSUB" ); cBaseFunction.call( this, "IMSUB" );
} }
cIMSUB.prototype = Object.create( cBaseFunction.prototype ) cIMSUB.prototype = Object.create( cBaseFunction.prototype );
function cIMSUM() { function cIMSUM() {
cBaseFunction.call( this, "IMSUM" ); cBaseFunction.call( this, "IMSUM" );
} }
cIMSUM.prototype = Object.create( cBaseFunction.prototype ) cIMSUM.prototype = Object.create( cBaseFunction.prototype );
function cOCT2BIN() { function cOCT2BIN() {
cBaseFunction.call( this, "OCT2BIN" ); cBaseFunction.call( this, "OCT2BIN" );
} }
cOCT2BIN.prototype = Object.create( cBaseFunction.prototype ) cOCT2BIN.prototype = Object.create( cBaseFunction.prototype );
function cOCT2DEC() { function cOCT2DEC() {
cBaseFunction.call( this, "OCT2DEC" ); cBaseFunction.call( this, "OCT2DEC" );
} }
cOCT2DEC.prototype = Object.create( cBaseFunction.prototype ) cOCT2DEC.prototype = Object.create( cBaseFunction.prototype );
function cOCT2HEX() { function cOCT2HEX() {
cBaseFunction.call( this, "OCT2HEX" ); cBaseFunction.call( this, "OCT2HEX" );
} }
cOCT2HEX.prototype = Object.create( cBaseFunction.prototype ) cOCT2HEX.prototype = Object.create( cBaseFunction.prototype );
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -57,47 +57,47 @@ function cERROR_TYPE() { ...@@ -57,47 +57,47 @@ function cERROR_TYPE() {
cERROR_TYPE.prototype = Object.create( cBaseFunction.prototype ) cERROR_TYPE.prototype = Object.create( cBaseFunction.prototype )
cERROR_TYPE.prototype.Calculate = function ( arg ) { cERROR_TYPE.prototype.Calculate = function ( arg ) {
function typeError( elem ) { function typeError( elem ) {
if ( elem instanceof cError ) { if ( elem instanceof CError ) {
if ( elem.errorType == cErrorType.null_value ) { if ( elem.errorType == cErrorType.null_value ) {
return new cNumber( 1 ); return new CNumber( 1 );
} }
else if ( elem.errorType == cErrorType.division_by_zero ) { else if ( elem.errorType == cErrorType.division_by_zero ) {
return new cNumber( 2 ); return new CNumber( 2 );
} }
else if ( elem.errorType == cErrorType.wrong_value_type ) { else if ( elem.errorType == cErrorType.wrong_value_type ) {
return new cNumber( 3 ); return new CNumber( 3 );
} }
else if ( elem.errorType == cErrorType.bad_reference ) { else if ( elem.errorType == cErrorType.bad_reference ) {
return new cNumber( 4 ); return new CNumber( 4 );
} }
else if ( elem.errorType == cErrorType.wrong_name ) { else if ( elem.errorType == cErrorType.wrong_name ) {
return new cNumber( 5 ); return new CNumber( 5 );
} }
else if ( elem.errorType == cErrorType.not_numeric ) { else if ( elem.errorType == cErrorType.not_numeric ) {
return new cNumber( 6 ); return new CNumber( 6 );
} }
else if ( elem.errorType == cErrorType.not_available ) { else if ( elem.errorType == cErrorType.not_available ) {
return new cNumber( 7 ); return new CNumber( 7 );
} }
else if ( elem.errorType == cErrorType.getting_data ) { else if ( elem.errorType == cErrorType.getting_data ) {
return new cNumber( 8 ); return new CNumber( 8 );
} }
else { else {
return new cError( cErrorType.not_available ); return new CError( cErrorType.not_available );
} }
} }
else return new cError( cErrorType.not_available ); else return new CError( cErrorType.not_available );
} }
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
var ret = new cArray(); var ret = new CArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
...@@ -135,16 +135,16 @@ function cISBLANK() { ...@@ -135,16 +135,16 @@ function cISBLANK() {
cISBLANK.prototype = Object.create( cBaseFunction.prototype ) cISBLANK.prototype = Object.create( cBaseFunction.prototype )
cISBLANK.prototype.Calculate = function ( arg ) { cISBLANK.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cEmpty ) if ( arg0 instanceof CEmpty )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISBLANK.prototype.getInfo = function () { cISBLANK.prototype.getInfo = function () {
return { return {
...@@ -174,20 +174,20 @@ function cISERR() { ...@@ -174,20 +174,20 @@ function cISERR() {
cISERR.prototype = Object.create( cBaseFunction.prototype ) cISERR.prototype = Object.create( cBaseFunction.prototype )
cISERR.prototype.Calculate = function ( arg ) { cISERR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cError && arg0.errorType != cErrorType.not_available ) if ( arg0 instanceof CError && arg0.errorType != cErrorType.not_available )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISERR.prototype.getInfo = function () { cISERR.prototype.getInfo = function () {
return { return {
...@@ -217,20 +217,20 @@ function cISERROR() { ...@@ -217,20 +217,20 @@ function cISERROR() {
cISERROR.prototype = Object.create( cBaseFunction.prototype ) cISERROR.prototype = Object.create( cBaseFunction.prototype )
cISERROR.prototype.Calculate = function ( arg ) { cISERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISERROR.prototype.getInfo = function () { cISERROR.prototype.getInfo = function () {
return { return {
...@@ -260,24 +260,24 @@ function cISEVEN() { ...@@ -260,24 +260,24 @@ function cISEVEN() {
cISEVEN.prototype = Object.create( cBaseFunction.prototype ) cISEVEN.prototype = Object.create( cBaseFunction.prototype )
cISEVEN.prototype.Calculate = function ( arg ) { cISEVEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
var arg0 = arg0.tocNumber(); var arg0 = arg0.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else else
return this.value = new cBool( (arg0.getValue() & 1) == 0 ); return this.value = new CBool( (arg0.getValue() & 1) == 0 );
} }
cISEVEN.prototype.getInfo = function () { cISEVEN.prototype.getInfo = function () {
return { return {
...@@ -307,19 +307,19 @@ function cISLOGICAL() { ...@@ -307,19 +307,19 @@ function cISLOGICAL() {
cISLOGICAL.prototype = Object.create( cBaseFunction.prototype ) cISLOGICAL.prototype = Object.create( cBaseFunction.prototype )
cISLOGICAL.prototype.Calculate = function ( arg ) { cISLOGICAL.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cBool ) if ( arg0 instanceof CBool )
return this.value = new cBool( true ); return this.value = new CBool( true );
else return this.value = new cBool( false ); else return this.value = new CBool( false );
} }
cISLOGICAL.prototype.getInfo = function () { cISLOGICAL.prototype.getInfo = function () {
return { return {
...@@ -349,20 +349,20 @@ function cISNA() { ...@@ -349,20 +349,20 @@ function cISNA() {
cISNA.prototype = Object.create( cBaseFunction.prototype ) cISNA.prototype = Object.create( cBaseFunction.prototype )
cISNA.prototype.Calculate = function ( arg ) { cISNA.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cError && arg0.errorType == cErrorType.not_available ) if ( arg0 instanceof CError && arg0.errorType == cErrorType.not_available )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISNA.prototype.getInfo = function () { cISNA.prototype.getInfo = function () {
return { return {
...@@ -392,19 +392,19 @@ function cISNONTEXT() { ...@@ -392,19 +392,19 @@ function cISNONTEXT() {
cISNONTEXT.prototype = Object.create( cBaseFunction.prototype ) cISNONTEXT.prototype = Object.create( cBaseFunction.prototype )
cISNONTEXT.prototype.Calculate = function ( arg ) { cISNONTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( !(arg0 instanceof cString) ) if ( !(arg0 instanceof CString) )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISNONTEXT.prototype.getInfo = function () { cISNONTEXT.prototype.getInfo = function () {
return { return {
...@@ -434,20 +434,20 @@ function cISNUMBER() { ...@@ -434,20 +434,20 @@ function cISNUMBER() {
cISNUMBER.prototype = Object.create( cBaseFunction.prototype ) cISNUMBER.prototype = Object.create( cBaseFunction.prototype )
cISNUMBER.prototype.Calculate = function ( arg ) { cISNUMBER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cNumber ) if ( arg0 instanceof CNumber )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISNUMBER.prototype.getInfo = function () { cISNUMBER.prototype.getInfo = function () {
return { return {
...@@ -477,24 +477,24 @@ function cISODD() { ...@@ -477,24 +477,24 @@ function cISODD() {
cISODD.prototype = Object.create( cBaseFunction.prototype ) cISODD.prototype = Object.create( cBaseFunction.prototype )
cISODD.prototype.Calculate = function ( arg ) { cISODD.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
var arg0 = arg0.tocNumber(); var arg0 = arg0.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else else
return this.value = new cBool( (arg0.getValue() & 1) == 1 ); return this.value = new CBool( (arg0.getValue() & 1) == 1 );
} }
cISODD.prototype.getInfo = function () { cISODD.prototype.getInfo = function () {
return { return {
...@@ -523,9 +523,9 @@ function cISREF() { ...@@ -523,9 +523,9 @@ function cISREF() {
} }
cISREF.prototype = Object.create( cBaseFunction.prototype ) cISREF.prototype = Object.create( cBaseFunction.prototype )
cISREF.prototype.Calculate = function ( arg ) { cISREF.prototype.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() ) 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 ); return this.value = new CBool( true );
else return this.value = new cBool( false ); else return this.value = new CBool( false );
} }
cISREF.prototype.getInfo = function () { cISREF.prototype.getInfo = function () {
return { return {
...@@ -555,20 +555,20 @@ function cISTEXT() { ...@@ -555,20 +555,20 @@ function cISTEXT() {
cISTEXT.prototype = Object.create( cBaseFunction.prototype ) cISTEXT.prototype = Object.create( cBaseFunction.prototype )
cISTEXT.prototype.Calculate = function ( arg ) { cISTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cString ) if ( arg0 instanceof CString )
return this.value = new cBool( true ); return this.value = new CBool( true );
else else
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cISTEXT.prototype.getInfo = function () { cISTEXT.prototype.getInfo = function () {
return { return {
...@@ -599,31 +599,31 @@ function cN() { ...@@ -599,31 +599,31 @@ function cN() {
cN.prototype = Object.create( cBaseFunction.prototype ) cN.prototype = Object.create( cBaseFunction.prototype )
cN.prototype.Calculate = function ( arg ) { cN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
var arr = new cArray(); var arr = new CArray();
arg.foreach( function ( elem, r, c ) { arg.foreach( function ( elem, r, c ) {
if ( elem instanceof cNumber || elem instanceof cError ) if ( elem instanceof CNumber || elem instanceof CError )
arr.array[r][c] = elem; arr.array[r][c] = elem;
else if ( elem instanceof cBool ) else if ( elem instanceof CBool )
arr.array[r][c] = elem.tocNumber(); arr.array[r][c] = elem.tocNumber();
else else
arr.array[r][c] = new cNumber( 0 ); arr.array[r][c] = new CNumber( 0 );
} ) } )
return this.value = arr; return this.value = arr;
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cNumber || arg0 instanceof cError ) if ( arg0 instanceof CNumber || arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else if ( arg0 instanceof cBool ) else if ( arg0 instanceof CBool )
return this.value = arg0.tocNumber(); return this.value = arg0.tocNumber();
else else
return this.value = new cNumber( 0 ); return this.value = new CNumber( 0 );
} }
cN.prototype.getInfo = function () { cN.prototype.getInfo = function () {
...@@ -653,7 +653,7 @@ function cNA() { ...@@ -653,7 +653,7 @@ function cNA() {
} }
cNA.prototype = Object.create( cBaseFunction.prototype ) cNA.prototype = Object.create( cBaseFunction.prototype )
cNA.prototype.Calculate = function () { cNA.prototype.Calculate = function () {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
cNA.prototype.getInfo = function () { cNA.prototype.getInfo = function () {
return { return {
...@@ -683,23 +683,23 @@ function cTYPE() { ...@@ -683,23 +683,23 @@ function cTYPE() {
cTYPE.prototype = Object.create( cBaseFunction.prototype ) cTYPE.prototype = Object.create( cBaseFunction.prototype )
cTYPE.prototype.Calculate = function ( arg ) { cTYPE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { else if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cNumber ) if ( arg0 instanceof CNumber )
return this.value = new cNumber( 1 ); return this.value = new CNumber( 1 );
else if ( arg0 instanceof cString ) else if ( arg0 instanceof CString )
return this.value = new cNumber( 2 ) return this.value = new CNumber( 2 )
else if ( arg0 instanceof cBool ) else if ( arg0 instanceof CBool )
return this.value = new cNumber( 4 ) return this.value = new CNumber( 4 )
else if ( arg0 instanceof cError ) else if ( arg0 instanceof CError )
return this.value = new cNumber( 16 ) return this.value = new CNumber( 16 )
else else
return this.value = new cNumber( 64 ); return this.value = new CNumber( 64 );
} }
cTYPE.prototype.getInfo = function () { cTYPE.prototype.getInfo = function () {
return { return {
......
...@@ -41,40 +41,40 @@ cAND.prototype = Object.create( cBaseFunction.prototype ) ...@@ -41,40 +41,40 @@ cAND.prototype = Object.create( cBaseFunction.prototype )
cAND.prototype.Calculate = function ( arg ) { cAND.prototype.Calculate = function ( arg ) {
var argResult = null; var argResult = null;
for ( var i = 0; i < arg.length; i++ ) { for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) { if ( arg[i] instanceof CArea || arg[i] instanceof CArea3D ) {
var argArr = arg[i].getValue(); var argArr = arg[i].getValue();
for ( var j = 0; j < argArr.length; j++ ) { for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cString || argArr[j] instanceof cEmpty ) continue; if ( argArr[j] instanceof CString || argArr[j] instanceof CEmpty ) continue;
else if ( argArr[j] instanceof cError ) return this.value = argArr[j]; else if ( argArr[j] instanceof CError ) return this.value = argArr[j];
else { else {
if ( argResult == null ) if ( argResult == null )
argResult = argArr[j].tocBool(); argResult = argArr[j].tocBool();
else 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 ); if ( argResult.value == false ) return this.value = new CBool( false );
} }
} }
} }
else { else {
if ( arg[i] instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg[i] instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type );
else if ( arg[i] instanceof cError ) { else if ( arg[i] instanceof CError ) {
return this.value = arg[i]; return this.value = arg[i];
} }
else if ( arg[i] instanceof cArray ) { else if ( arg[i] instanceof CArray ) {
var thas = this; var thas = this;
arg[i].foreach( function ( elem ) { arg[i].foreach( function ( elem ) {
if ( elem instanceof cError ) { if ( elem instanceof CError ) {
argResult = elem; argResult = elem;
return true; return true;
} }
else if ( elem instanceof cString || elem instanceof cEmpty ) { else if ( elem instanceof CString || elem instanceof CEmpty ) {
return; return;
} }
else { else {
if ( argResult == null ) if ( argResult == null )
argResult = elem.tocBool(); argResult = elem.tocBool();
else else
argResult = new cBool( argResult.value && elem.tocBool().value ); argResult = new CBool( argResult.value && elem.tocBool().value );
if ( argResult.value == false ) { if ( argResult.value == false ) {
return true; return true;
} }
...@@ -85,13 +85,13 @@ cAND.prototype.Calculate = function ( arg ) { ...@@ -85,13 +85,13 @@ cAND.prototype.Calculate = function ( arg ) {
if ( argResult == null ) if ( argResult == null )
argResult = arg[i].tocBool(); argResult = arg[i].tocBool();
else 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 ); if ( argResult.value == false ) return this.value = new CBool( false );
} }
} }
} }
if ( argResult == null ) if ( argResult == null )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
return this.value = argResult; return this.value = argResult;
} }
cAND.prototype.getInfo = function () { cAND.prototype.getInfo = function () {
...@@ -120,7 +120,7 @@ function cFALSE() { ...@@ -120,7 +120,7 @@ function cFALSE() {
} }
cFALSE.prototype = Object.create( cBaseFunction.prototype ) cFALSE.prototype = Object.create( cBaseFunction.prototype )
cFALSE.prototype.Calculate = function () { cFALSE.prototype.Calculate = function () {
return this.value = new cBool( false ); return this.value = new CBool( false );
} }
cFALSE.prototype.getInfo = function () { cFALSE.prototype.getInfo = function () {
return { return {
...@@ -151,31 +151,31 @@ cIF.prototype = Object.create( cBaseFunction.prototype ) ...@@ -151,31 +151,31 @@ cIF.prototype = Object.create( cBaseFunction.prototype )
cIF.prototype.Calculate = function ( arg ) { cIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof cArray ) if ( arg0 instanceof CArray )
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
if ( arg1 instanceof cArray ) if ( arg1 instanceof CArray )
arg1 = arg1.getElement( 0 ); arg1 = arg1.getElement( 0 );
if ( arg2 instanceof cArray ) if ( arg2 instanceof CArray )
arg2 = arg2.getElement( 0 ); arg2 = arg2.getElement( 0 );
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else { else {
arg0 = arg0.tocBool(); arg0 = arg0.tocBool();
if ( arg0 instanceof cString ) if ( arg0 instanceof CString )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
else if ( arg0.value ) else if ( arg0.value )
return this.value = arg1 ? return this.value = arg1 ?
arg1 instanceof cEmpty ? arg1 instanceof CEmpty ?
new cNumber( 0 ) : new CNumber( 0 ) :
arg1 : arg1 :
new cBool( true ); new CBool( true );
else return this.value = arg2 ? else return this.value = arg2 ?
arg2 instanceof cEmpty ? arg2 instanceof CEmpty ?
new cNumber( 0 ) : new CNumber( 0 ) :
arg2 : arg2 :
new cBool( false ); new CBool( false );
} }
} }
cIF.prototype.getInfo = function () { cIF.prototype.getInfo = function () {
...@@ -206,18 +206,18 @@ function cIFERROR() { ...@@ -206,18 +206,18 @@ function cIFERROR() {
cIFERROR.prototype = Object.create( cBaseFunction.prototype ) cIFERROR.prototype = Object.create( cBaseFunction.prototype )
cIFERROR.prototype.Calculate = function ( arg ) { cIFERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
} }
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg[1] instanceof cArray ? arg[1].getElement( 0 ) : arg[1]; return this.value = arg[1] instanceof CArray ? arg[1].getElement( 0 ) : arg[1];
else return this.value = arg[0]; else return this.value = arg[0];
} }
cIFERROR.prototype.getInfo = function () { cIFERROR.prototype.getInfo = function () {
...@@ -248,24 +248,24 @@ function cNOT() { ...@@ -248,24 +248,24 @@ function cNOT() {
cNOT.prototype = Object.create( cBaseFunction.prototype ) cNOT.prototype = Object.create( cBaseFunction.prototype )
cNOT.prototype.Calculate = function ( arg ) { cNOT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) if ( arg0 instanceof CArray )
arg0 = arg0.getElement( 0 ); arg0 = arg0.getElement( 0 );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof cString ) { if ( arg0 instanceof CString ) {
var res = arg0.tocBool(); var res = arg0.tocBool();
if ( res instanceof cString ) if ( res instanceof CString )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
else 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; return this.value = arg0;
else else
return this.value = new cBool( !arg0.tocBool().value ); return this.value = new CBool( !arg0.tocBool().value );
} }
cNOT.prototype.getInfo = function () { cNOT.prototype.getInfo = function () {
return { return {
...@@ -296,38 +296,38 @@ cOR.prototype = Object.create( cBaseFunction.prototype ) ...@@ -296,38 +296,38 @@ cOR.prototype = Object.create( cBaseFunction.prototype )
cOR.prototype.Calculate = function ( arg ) { cOR.prototype.Calculate = function ( arg ) {
var argResult = null; var argResult = null;
for ( var i = 0; i < arg.length; i++ ) { for ( var i = 0; i < arg.length; i++ ) {
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) { if ( arg[i] instanceof CArea || arg[i] instanceof CArea3D ) {
var argArr = arg[i].getValue(); var argArr = arg[i].getValue();
for ( var j = 0; j < argArr.length; j++ ) { for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cString || argArr[j] instanceof cEmpty ) continue; if ( argArr[j] instanceof CString || argArr[j] instanceof CEmpty ) continue;
else if ( argArr[j] instanceof cError ) return this.value = argArr[j]; else if ( argArr[j] instanceof CError ) return this.value = argArr[j];
else { else {
if ( argResult == null ) if ( argResult == null )
argResult = argArr[j].tocBool(); argResult = argArr[j].tocBool();
else 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 ); if ( argResult.value === true ) return this.value = new CBool( true );
} }
} }
} }
else { else {
if ( arg[i] instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); 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 CError ) return this.value = arg[i];
else if ( arg[i] instanceof cArray ) { else if ( arg[i] instanceof CArray ) {
var thas = this; var thas = this;
arg[i].foreach( function ( elem ) { arg[i].foreach( function ( elem ) {
if ( elem instanceof cError ) { if ( elem instanceof CError ) {
argResult = elem; argResult = elem;
return true; return true;
} }
else if ( elem instanceof cString || elem instanceof cEmpty ) { else if ( elem instanceof CString || elem instanceof CEmpty ) {
return; return;
} }
else { else {
if ( argResult == null ) if ( argResult == null )
argResult = elem.tocBool(); argResult = elem.tocBool();
else else
argResult = new cBool( argResult.value || elem.tocBool().value ); argResult = new CBool( argResult.value || elem.tocBool().value );
} }
} ) } )
} }
...@@ -335,13 +335,13 @@ cOR.prototype.Calculate = function ( arg ) { ...@@ -335,13 +335,13 @@ cOR.prototype.Calculate = function ( arg ) {
if ( argResult == null ) if ( argResult == null )
argResult = arg[i].tocBool(); argResult = arg[i].tocBool();
else else
argResult = new cBool( argResult.value || arg[i].tocBool().value ); argResult = new CBool( argResult.value || arg[i].tocBool().value );
if ( argResult.value === true ) return this.value = new cBool( true ); if ( argResult.value === true ) return this.value = new CBool( true );
} }
} }
} }
if ( argResult == null ) if ( argResult == null )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
return this.value = argResult; return this.value = argResult;
} }
cOR.prototype.getInfo = function () { cOR.prototype.getInfo = function () {
...@@ -371,7 +371,7 @@ function cTRUE() { ...@@ -371,7 +371,7 @@ function cTRUE() {
} }
cTRUE.prototype = Object.create( cBaseFunction.prototype ) cTRUE.prototype = Object.create( cBaseFunction.prototype )
cTRUE.prototype.Calculate = function () { cTRUE.prototype.Calculate = function () {
return this.value = new cBool( true ); return this.value = new CBool( true );
} }
cTRUE.prototype.getInfo = function () { cTRUE.prototype.getInfo = function () {
return { return {
......
...@@ -55,42 +55,42 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -55,42 +55,42 @@ cADDRESS.prototype.Calculate = function ( arg ) {
} }
var rowNumber = arg[0], colNumber = arg[1], var rowNumber = arg[0], colNumber = arg[1],
refType = arg[2] ? arg[2] : new cNumber( 1 ), refType = arg[2] ? arg[2] : new CNumber( 1 ),
A1RefType = arg[3] ? arg[3] : new cBool( true ), A1RefType = arg[3] ? arg[3] : new CBool( true ),
sheetName = arg[4] ? arg[4] : new cEmpty(); sheetName = arg[4] ? arg[4] : new CEmpty();
if ( rowNumber instanceof cArea || rowNumber instanceof cArea3D ) { if ( rowNumber instanceof CArea || rowNumber instanceof CArea3D ) {
rowNumber = rowNumber.cross( arguments[1].first ); rowNumber = rowNumber.cross( arguments[1].first );
} }
else if ( rowNumber instanceof cArray ) { else if ( rowNumber instanceof CArray ) {
rowNumber = rowNumber.getElementRowCol( 0, 0 ); rowNumber = rowNumber.getElementRowCol( 0, 0 );
} }
if ( colNumber instanceof cArea || colNumber instanceof cArea3D ) { if ( colNumber instanceof CArea || colNumber instanceof CArea3D ) {
colNumber = colNumber.cross( arguments[1].first ); colNumber = colNumber.cross( arguments[1].first );
} }
else if ( colNumber instanceof cArray ) { else if ( colNumber instanceof CArray ) {
colNumber = colNumber.getElementRowCol( 0, 0 ); colNumber = colNumber.getElementRowCol( 0, 0 );
} }
if ( refType instanceof cArea || refType instanceof cArea3D ) { if ( refType instanceof CArea || refType instanceof CArea3D ) {
refType = refType.cross( arguments[1].first ); refType = refType.cross( arguments[1].first );
} }
else if ( refType instanceof cArray ) { else if ( refType instanceof CArray ) {
refType = refType.getElementRowCol( 0, 0 ); refType = refType.getElementRowCol( 0, 0 );
} }
if ( A1RefType instanceof cArea || A1RefType instanceof cArea3D ) { if ( A1RefType instanceof CArea || A1RefType instanceof CArea3D ) {
A1RefType = A1RefType.cross( arguments[1].first ); A1RefType = A1RefType.cross( arguments[1].first );
} }
else if ( A1RefType instanceof cArray ) { else if ( A1RefType instanceof CArray ) {
A1RefType = A1RefType.getElementRowCol( 0, 0 ); A1RefType = A1RefType.getElementRowCol( 0, 0 );
} }
if ( sheetName instanceof cArea || sheetName instanceof cArea3D ) { if ( sheetName instanceof CArea || sheetName instanceof CArea3D ) {
sheetName = sheetName.cross( arguments[1].first ); sheetName = sheetName.cross( arguments[1].first );
} }
else if ( sheetName instanceof cArray ) { else if ( sheetName instanceof CArray ) {
sheetName = sheetName.getElementRowCol( 0, 0 ); sheetName = sheetName.getElementRowCol( 0, 0 );
} }
...@@ -99,14 +99,14 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -99,14 +99,14 @@ cADDRESS.prototype.Calculate = function ( arg ) {
refType = refType.tocNumber(); refType = refType.tocNumber();
A1RefType = A1RefType.tocBool(); A1RefType = A1RefType.tocBool();
if ( rowNumber instanceof cError ) return this.value = rowNumber; if ( rowNumber instanceof CError ) return this.value = rowNumber;
if ( colNumber instanceof cError ) return this.value = colNumber; if ( colNumber instanceof CError ) return this.value = colNumber;
if ( refType instanceof cError ) return this.value = refType; if ( refType instanceof CError ) return this.value = refType;
if ( A1RefType instanceof cError ) return this.value = A1RefType; if ( A1RefType instanceof CError ) return this.value = A1RefType;
if ( sheetName instanceof cError ) return this.value = sheetName; 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 ); return this.value = new CError( cErrorType.not_numeric );
} }
var strRef; var strRef;
switch ( refType.getValue() ) { switch ( refType.getValue() ) {
...@@ -124,15 +124,15 @@ cADDRESS.prototype.Calculate = function ( arg ) { ...@@ -124,15 +124,15 @@ cADDRESS.prototype.Calculate = function ( arg ) {
break; break;
} }
if ( sheetName instanceof cEmpty ) { if ( sheetName instanceof CEmpty ) {
return this.value = new cString( strRef ); return this.value = new CString( strRef );
} }
else { else {
if ( !rx_test_ws_name.test( sheetName.toString() ) ) { if ( !rx_test_ws_name.test( sheetName.toString() ) ) {
return this.value = new cString( "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef ); return this.value = new CString( "'" + sheetName.toString().replace( /'/g, "''" ) + "'" + "!" + strRef );
} }
else { else {
return this.value = new cString( sheetName.toString() + "!" + strRef ); return this.value = new CString( sheetName.toString() + "!" + strRef );
} }
} }
...@@ -171,24 +171,24 @@ cCHOOSE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -171,24 +171,24 @@ cCHOOSE.prototype = Object.create( cBaseFunction.prototype )
cCHOOSE.prototype.Calculate = function ( arg ) { cCHOOSE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
if ( arg0 instanceof cNumber ) { if ( arg0 instanceof CNumber ) {
if ( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ) { if ( arg0.getValue() < 1 || arg0.getValue() > this.getArguments() ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
return this.value = arg[arg0.getValue()]; return this.value = arg[arg0.getValue()];
} }
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cCHOOSE.prototype.getInfo = function () { cCHOOSE.prototype.getInfo = function () {
return { return {
...@@ -220,27 +220,27 @@ cCOLUMN.prototype.Calculate = function ( arg ) { ...@@ -220,27 +220,27 @@ cCOLUMN.prototype.Calculate = function ( arg ) {
var arg0; var arg0;
if ( this.argumentsCurrent == 0 ) { if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1]; arg0 = arguments[1];
return this.value = new cNumber( arg0.getFirst().getCol() ); return this.value = new CNumber( arg0.getFirst().getCol() );
} }
arg0 = arg[0]; 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(); var range = arg0.getRange();
if ( range ) if ( range )
return this.value = new cNumber( range.getFirst().getCol() ); return this.value = new CNumber( range.getFirst().getCol() );
else else
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
else if ( arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea3D ) {
var r = arg0.getRange(); 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() ); return this.value = new CNumber( r[0].getFirst().getCol() );
} }
else { else {
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
} }
else else
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
cCOLUMN.prototype.getInfo = function () { cCOLUMN.prototype.getInfo = function () {
return { return {
...@@ -270,22 +270,22 @@ function cCOLUMNS() { ...@@ -270,22 +270,22 @@ function cCOLUMNS() {
cCOLUMNS.prototype = Object.create( cBaseFunction.prototype ) cCOLUMNS.prototype = Object.create( cBaseFunction.prototype )
cCOLUMNS.prototype.Calculate = function ( arg ) { cCOLUMNS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
return this.value = new cNumber( arg0.getCountElementInRow() ); 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(); var range = arg0.getRange();
return this.value = new cNumber( Math.abs( range.getBBox().c1 - range.getBBox().c2 ) + 1 ); 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(); 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 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 else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cCOLUMNS.prototype.getInfo = function () { cCOLUMNS.prototype.getInfo = function () {
return { return {
...@@ -321,20 +321,20 @@ function cHLOOKUP() { ...@@ -321,20 +321,20 @@ function cHLOOKUP() {
} }
cHLOOKUP.prototype = Object.create( cBaseFunction.prototype ) cHLOOKUP.prototype = Object.create( cBaseFunction.prototype )
cHLOOKUP.prototype.Calculate = function ( arg ) { cHLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true ); 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 ); return this.value = new CError( cErrorType.bad_reference );
if ( numberRow < 0 ) if ( numberRow < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
if ( arg0 instanceof cString ) { if ( arg0 instanceof CString ) {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
regexp = searchRegExp( valueForSearching ); regexp = searchRegExp( valueForSearching );
} }
else if ( arg0 instanceof cError ) else if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else { else {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
...@@ -342,13 +342,13 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -342,13 +342,13 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
var found = false, bb; var found = false, bb;
if ( arg1 instanceof cRef || arg1 instanceof cRef3D || arg1 instanceof cArea ) { if ( arg1 instanceof CRef || arg1 instanceof CRef3D || arg1 instanceof CArea ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberRow > bb.r2 - bb.r1 ) if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value); var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value);
if(oCache) if(oCache)
{ {
resC = oCache.index; resC = oCache.index;
...@@ -356,14 +356,14 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -356,14 +356,14 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
// 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], ws = arg1.getWS() var range = arg1.getRange()[0], ws = arg1.getWS()
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberRow > bb.r2 - bb.r1 ) if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value); var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value);
if(oCache) if(oCache)
{ {
resC = oCache.index; resC = oCache.index;
...@@ -372,7 +372,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -372,7 +372,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
// 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 ) { else if ( arg1 instanceof CArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
if ( c == 0 ) if ( c == 0 )
min = elem.getValue(); min = elem.getValue();
...@@ -387,7 +387,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -387,7 +387,7 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else { else {
if ( arg0 instanceof cString ) { if ( arg0 instanceof CString ) {
if ( regexp.test( elem.getValue() ) ) if ( regexp.test( elem.getValue() ) )
resC = c; resC = c;
} }
...@@ -400,15 +400,15 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -400,15 +400,15 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} ) } )
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
if ( resC == -1 ) { if ( resC == -1 ) {
return this.value = new cError( cErrorType.not_available ); 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 = new CError( cErrorType.bad_reference );
} }
return this.value = arg1.getElementRowCol( numberRow, resC ); return this.value = arg1.getElementRowCol( numberRow, resC );
...@@ -416,11 +416,11 @@ cHLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -416,11 +416,11 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
} }
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
if ( resC == -1 ) { if ( resC == -1 ) {
return this.value = new cError( cErrorType.not_available ); 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 );
...@@ -464,15 +464,15 @@ function cINDEX() { ...@@ -464,15 +464,15 @@ function cINDEX() {
cINDEX.prototype = Object.create( cBaseFunction.prototype ) cINDEX.prototype = Object.create( cBaseFunction.prototype )
cINDEX.prototype.Calculate = function ( arg ) { cINDEX.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : new cNumber(1), arg1 = arg[1] && !(arg[1] instanceof CEmpty) ? arg[1] : new CNumber(1),
arg2 = arg[2] && !(arg[2] instanceof cEmpty) ? arg[2] : new cNumber(1), arg2 = arg[2] && !(arg[2] instanceof CEmpty) ? arg[2] : new CNumber(1),
arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber(1), arg3 = arg[3] && !(arg[3] instanceof CEmpty) ? arg[3] : new CNumber(1),
isArrayForm = false, res; isArrayForm = false, res;
if( arg0 instanceof cArea3D ){ if( arg0 instanceof CArea3D ){
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
else if( arg0 instanceof cError ){ else if( arg0 instanceof CError ){
return this.value = arg0; return this.value = arg0;
} }
...@@ -480,18 +480,18 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -480,18 +480,18 @@ cINDEX.prototype.Calculate = function ( arg ) {
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if( arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError ){ if( arg1 instanceof CError || arg2 instanceof CError || arg3 instanceof CError ){
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
if( arg1.getValue() < 0 || arg2.getValue() < 0 ){ if( arg1.getValue() < 0 || arg2.getValue() < 0 ){
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
if( arg0 instanceof cArray ){ if( arg0 instanceof CArray ){
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else if( arg0 instanceof cArea ){ else if( arg0 instanceof CArea ){
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else{ else{
...@@ -502,7 +502,7 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -502,7 +502,7 @@ cINDEX.prototype.Calculate = function ( arg ) {
if( res ) if( res )
res = res[arg2.getValue()-1]; res = res[arg2.getValue()-1];
return this.value = res ? res : new cError( cErrorType.bad_reference ); return this.value = res ? res : new CError( cErrorType.bad_reference );
} }
cINDEX.prototype.getInfo = function () { cINDEX.prototype.getInfo = function () {
...@@ -532,48 +532,48 @@ function cINDIRECT() { ...@@ -532,48 +532,48 @@ function cINDIRECT() {
} }
cINDIRECT.prototype = Object.create( cBaseFunction.prototype ) cINDIRECT.prototype = Object.create( cBaseFunction.prototype )
cINDIRECT.prototype.Calculate = function ( arg ) { cINDIRECT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] : new cBool( true ), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand; var arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] : new CBool( true ), r = arguments[1], wb = r.worksheet.workbook, o = { Formula:"", pCurrPos:0 }, ref, found_operand;
function parseReference() { 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], var _wsFrom = ref[1],
_wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) ) ? ref[2] : _wsFrom; _wsTo = ( (ref[2] !== null) && (ref[2] !== undefined) ) ? ref[2] : _wsFrom;
if ( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ) { if ( !(wb.getWorksheetByName( _wsFrom ) && wb.getWorksheetByName( _wsTo )) ) {
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) { if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb ); found_operand = new CArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos ) ) { else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos ) ) {
if ( _wsTo != _wsFrom ) { if ( _wsTo != _wsFrom ) {
found_operand = new cArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb ); found_operand = new CArea3D( o.operand_str.toUpperCase(), _wsFrom, _wsTo, wb );
} }
else { else {
found_operand = new cRef3D( o.operand_str.toUpperCase(), _wsFrom, wb ); 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; found_operand.isAbsolute = true;
} }
} }
else if ( parserHelp.isName.call( o, o.Formula, o.pCurrPos, wb )[0] ) { else if ( parserHelp.isName.call( o, o.Formula, o.pCurrPos, wb )[0] ) {
found_operand = new cName( o.operand_str, wb ); found_operand = new CName( o.operand_str, wb );
} }
else if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) { else if ( parserHelp.isArea.call( o, o.Formula, o.pCurrPos ) ) {
found_operand = new cArea( o.operand_str.toUpperCase(), r.worksheet ); found_operand = new CArea( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos, true ) ) { else if ( parserHelp.isRef.call( o, o.Formula, o.pCurrPos, true ) ) {
found_operand = new cRef( o.operand_str.toUpperCase(), r.worksheet ); found_operand = new CRef( o.operand_str.toUpperCase(), r.worksheet );
if ( o.operand_str.indexOf( "$" ) > -1 ) if ( o.operand_str.indexOf( "$" ) > -1 )
found_operand.isAbsolute = true; found_operand.isAbsolute = true;
} }
} }
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
var ret = new cArray(); var ret = new CArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
o = { Formula:elem.toString(), pCurrPos:0 }; o = { Formula:elem.toString(), pCurrPos:0 };
parseReference(); parseReference();
...@@ -589,12 +589,12 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -589,12 +589,12 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
} }
if ( found_operand ) { if ( found_operand ) {
if ( found_operand instanceof cName ) if ( found_operand instanceof CName )
found_operand = found_operand.toRef(); found_operand = found_operand.toRef();
var cellName = r.getCells()[0].getName(), wsId = r.worksheet.getId(); var cellName = r.getCells()[0].getName(), wsId = r.worksheet.getId();
if ( (found_operand instanceof cRef || found_operand instanceof cRef3D || found_operand instanceof cArea) && found_operand.isValid() ) { if ( (found_operand instanceof CRef || found_operand instanceof CRef3D || found_operand instanceof CArea) && found_operand.isValid() ) {
var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ), var nFrom = wb.dependencyFormulas.addNode( wsId, cellName ),
nTo = wb.dependencyFormulas.addNode( found_operand.getWsId(), found_operand._cells ); nTo = wb.dependencyFormulas.addNode( found_operand.getWsId(), found_operand._cells );
...@@ -602,7 +602,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -602,7 +602,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
wb.dependencyFormulas.addEdge2( nFrom, nTo ); wb.dependencyFormulas.addEdge2( nFrom, nTo );
} }
else if ( found_operand instanceof cArea3D && found_operand.isValid() ) { else if ( found_operand instanceof CArea3D && found_operand.isValid() ) {
var wsR = found_operand.wsRange(); var wsR = found_operand.wsRange();
for ( var j = 0; j < wsR.length; j++ ) for ( var j = 0; j < wsR.length; j++ )
wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, found_operand._cells.replace( /\$/g, "" ) ); wb.dependencyFormulas.addEdge( wsId, cellName.replace( /\$/g, "" ), wsR[j].Id, found_operand._cells.replace( /\$/g, "" ) );
...@@ -611,7 +611,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) { ...@@ -611,7 +611,7 @@ cINDIRECT.prototype.Calculate = function ( arg ) {
return this.value = found_operand; return this.value = found_operand;
} }
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
cINDIRECT.prototype.getInfo = function () { cINDIRECT.prototype.getInfo = function () {
...@@ -644,10 +644,10 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -644,10 +644,10 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2], var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2],
resC = -1, resR = -1; resC = -1, resR = -1;
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
if ( arg0 instanceof cRef ) { if ( arg0 instanceof CRef ) {
arg0 = arg0.tryConvert(); arg0 = arg0.tryConvert();
} }
...@@ -666,42 +666,42 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -666,42 +666,42 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
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 ); return this.value = new CError( cErrorType.not_available );
} }
if ( arg1 instanceof cArray && arg2 instanceof cArray ) { if ( arg1 instanceof CArray && arg2 instanceof CArray ) {
if ( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ) { if ( arg1.getRowCount() != arg2.getRowCount() && arg1.getCountElementInRow() != arg2.getCountElementInRow() ) {
return this.value = new cError( cErrorType.not_available ); 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 = 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; var _arg1, _arg2;
_arg1 = arg1 instanceof cArray ? arg1 : arg2; _arg1 = arg1 instanceof CArray ? arg1 : arg2;
_arg2 = arg2 instanceof cArray ? arg1 : arg2; _arg2 = arg2 instanceof CArray ? arg1 : arg2;
var BBox = _arg2.getBBox(); 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 ); 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 = 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 )
...@@ -712,23 +712,23 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -712,23 +712,23 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
else { else {
var arg1Range = arg1.getRange(), arg2Range = arg2.getRange(); 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 ); return this.value = new CError( cErrorType.not_available );
if ( arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea3D ) {
arg1Range = arg1.getMatrix()[0]; arg1Range = arg1.getMatrix()[0];
// arg1Range = arg1Range[0]; // arg1Range = arg1Range[0];
} }
else if ( arg1 instanceof cArea ) { else if ( arg1 instanceof CArea ) {
arg1Range = arg1.getMatrix(); arg1Range = arg1.getMatrix();
} }
if ( arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea3D ) {
arg2Range = arg2.getMatrix()[0]; arg2Range = arg2.getMatrix()[0];
// arg2Range = arg2Range[0]; // arg2Range = arg2Range[0];
} }
else if ( arg2 instanceof cArea ) { else if ( arg2 instanceof CArea ) {
arg2Range = arg2.getMatrix(); arg2Range = arg2.getMatrix();
} }
...@@ -741,22 +741,22 @@ cLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -741,22 +741,22 @@ cLOOKUP.prototype.Calculate = function ( arg ) {
}() ) }() )
if ( index < 0 ) return this.value = new cError( cErrorType.not_available ); if ( index < 0 ) return this.value = new CError( cErrorType.not_available );
if ( this.argumentsCurrent == 2 ) { if ( this.argumentsCurrent == 2 ) {
if ( arg1Range[0].length >= 2 ) { if ( arg1Range[0].length >= 2 ) {
var b = arg1.getBBox(); var b = arg1.getBBox();
return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 1 ).getName(), arg1.ws ); return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 1 ).getName(), arg1.ws );
} }
else else
return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws ); return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws );
} }
else { else {
var b = arg2.getBBox(); var b = arg2.getBBox();
if ( arg2Range.length == 1 ) { if ( arg2Range.length == 1 ) {
return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws ); return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + 0, (b.c1 - 1) + index ).getName(), arg1.ws );
} }
else else
return this.value = new cRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 0 ).getName(), arg1.ws ); return this.value = new CRef( arg1.ws.getCell3( (b.r1 - 1) + index, (b.c1 - 1) + 0 ).getName(), arg1.ws );
} }
return this.value = arg2.getValue()[index]; return this.value = arg2.getValue()[index];
...@@ -788,16 +788,16 @@ function cMATCH() { ...@@ -788,16 +788,16 @@ function cMATCH() {
} }
cMATCH.prototype = Object.create( cBaseFunction.prototype ) cMATCH.prototype = Object.create( cBaseFunction.prototype )
cMATCH.prototype.Calculate = function ( arg ) { cMATCH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber(1);
function findMatch(a0,a1,a2){ function findMatch(a0,a1,a2){
var a1RowCount = a1.length, a1ColumnCount = a1[0].length, var a1RowCount = a1.length, a1ColumnCount = a1[0].length,
a0Value = a0.getValue(), a2Value = a2.getValue(), a0Value = a0.getValue(), a2Value = a2.getValue(),
arr = [], res = new cError( cErrorType.not_available ), arr = [], res = new CError( cErrorType.not_available ),
index = -1; index = -1;
if( a1RowCount > 1 && a1ColumnCount > 1 ){ if( a1RowCount > 1 && a1ColumnCount > 1 ){
return new cError( cErrorType.not_available ); return new CError( cErrorType.not_available );
} }
else if( a1RowCount == 1 && a1ColumnCount > 1 ){ else if( a1RowCount == 1 && a1ColumnCount > 1 ){
for(var i = 0; i < a1ColumnCount; i++){ for(var i = 0; i < a1ColumnCount; i++){
...@@ -814,7 +814,7 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -814,7 +814,7 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){ if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){
return new cError( cErrorType.not_numeric ); return new CError( cErrorType.not_numeric );
} }
if( a2Value == -1 ){ if( a2Value == -1 ){
...@@ -827,7 +827,7 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -827,7 +827,7 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
} }
else if( a2Value == 0 ){ else if( a2Value == 0 ){
if( a0 instanceof cString ){ if( a0 instanceof CString ){
for(var i = 0; i<arr.length; i++){ for(var i = 0; i<arr.length; i++){
if( searchRegExp2(arr[i].toString(),a0Value) ){ if( searchRegExp2(arr[i].toString(),a0Value) ){
index = i; index = i;
...@@ -853,37 +853,37 @@ cMATCH.prototype.Calculate = function ( arg ) { ...@@ -853,37 +853,37 @@ cMATCH.prototype.Calculate = function ( arg ) {
} }
if( index > -1 ) if( index > -1 )
res = new cNumber(index+1); res = new CNumber(index+1);
return res; return res;
} }
if( arg0 instanceof cArea3D || arg0 instanceof cArray || arg0 instanceof cArea ){ if( arg0 instanceof CArea3D || arg0 instanceof CArray || arg0 instanceof CArea ){
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
else if( arg0 instanceof cError ){ else if( arg0 instanceof CError ){
return this.value = arg0; return this.value = arg0;
} }
/* else{ /* else{
}*/ }*/
if( !(arg1 instanceof cArray || arg1 instanceof cArea) ){ if( !(arg1 instanceof CArray || arg1 instanceof CArea) ){
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
else { else {
arg1 = arg1.getMatrix(); arg1 = arg1.getMatrix();
} }
if( arg2 instanceof cNumber || arg2 instanceof cBool ){ if( arg2 instanceof CNumber || arg2 instanceof CBool ){
} }
else if( arg2 instanceof cError ){ else if( arg2 instanceof CError ){
return this.value = arg2; return this.value = arg2;
} }
else{ else{
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
return this.value = findMatch(arg0,arg1,arg2) return this.value = findMatch(arg0,arg1,arg2)
...@@ -914,7 +914,7 @@ function cOFFSET() { ...@@ -914,7 +914,7 @@ function cOFFSET() {
} }
cOFFSET.prototype = Object.create( cBaseFunction.prototype ) cOFFSET.prototype = Object.create( cBaseFunction.prototype )
cOFFSET.prototype.Calculate = function ( arg ) { cOFFSET.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber(0 ), arg4 = arg[4] ? arg[4] : new cNumber(0); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new CNumber(0 ), arg4 = arg[4] ? arg[4] : new CNumber(0);
if(1){} if(1){}
...@@ -949,27 +949,27 @@ cROW.prototype.Calculate = function ( arg ) { ...@@ -949,27 +949,27 @@ cROW.prototype.Calculate = function ( arg ) {
var arg0; var arg0;
if ( this.argumentsCurrent == 0 ) { if ( this.argumentsCurrent == 0 ) {
arg0 = arguments[1]; arg0 = arguments[1];
return this.value = new cNumber( arg0.getFirst().getRow() ); return this.value = new CNumber( arg0.getFirst().getRow() );
} }
arg0 = arg[0]; 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(); var range = arg0.getRange();
if ( range ) if ( range )
return this.value = new cNumber( range.getFirst().getRow() ); return this.value = new CNumber( range.getFirst().getRow() );
else else
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
else if ( arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea3D ) {
var r = arg0.getRange(); 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() ); return this.value = new CNumber( r[0].getFirst().getRow() );
} }
else { else {
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
} }
else else
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
} }
cROW.prototype.getInfo = function () { cROW.prototype.getInfo = function () {
return { return {
...@@ -999,22 +999,22 @@ function cROWS() { ...@@ -999,22 +999,22 @@ function cROWS() {
cROWS.prototype = Object.create( cBaseFunction.prototype ) cROWS.prototype = Object.create( cBaseFunction.prototype )
cROWS.prototype.Calculate = function ( arg ) { cROWS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
return this.value = new cNumber( arg0.getRowCount() ); 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(); var range = arg0.getRange();
return this.value = new cNumber( Math.abs( range.getBBox().r1 - range.getBBox().r2 ) + 1 ); 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(); 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 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 else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cROWS.prototype.getInfo = function () { cROWS.prototype.getInfo = function () {
return { return {
...@@ -1049,7 +1049,7 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) { ...@@ -1049,7 +1049,7 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
function TransposeMatrix( A ) { function TransposeMatrix( A ) {
var tMatrix = [], res = new cArray(); var tMatrix = [], res = new CArray();
for ( var i = 0; i < A.length; i++ ) { for ( var i = 0; i < A.length; i++ ) {
for ( var j = 0; j < A[i].length; j++ ) { for ( var j = 0; j < A[i].length; j++ ) {
...@@ -1064,17 +1064,17 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) { ...@@ -1064,17 +1064,17 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArray ) { if ( arg0 instanceof CArea || arg0 instanceof CArray ) {
arg0 = arg0.getMatrix(); arg0 = arg0.getMatrix();
} }
else if( arg0 instanceof cNumber || arg0 instanceof cString || arg0 instanceof cBool || arg0 instanceof cRef || arg0 instanceof cRef3D ){ else if( arg0 instanceof CNumber || arg0 instanceof CString || arg0 instanceof CBool || arg0 instanceof CRef || arg0 instanceof CRef3D ){
return this.value = arg0.getValue(); return this.value = arg0.getValue();
} }
else if( arg0 instanceof cError ){ else if( arg0 instanceof CError ){
return this.value = arg0; return this.value = arg0;
} }
else else
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
return this.value = TransposeMatrix( arg0 ); return this.value = TransposeMatrix( arg0 );
...@@ -1141,7 +1141,7 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV ...@@ -1141,7 +1141,7 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV
} }
if ( arg3Value == true ) { if ( arg3Value == true ) {
if ( isValueString ) { if ( isValueString ) {
if ( cvType instanceof cString ) { if ( cvType instanceof CString ) {
if ( valueForSearching.localeCompare( cvType.getValue() ) == 0 ) { if ( valueForSearching.localeCompare( cvType.getValue() ) == 0 ) {
res.index = index; res.index = index;
found = true; found = true;
...@@ -1212,23 +1212,23 @@ function cVLOOKUP() { ...@@ -1212,23 +1212,23 @@ function cVLOOKUP() {
} }
cVLOOKUP.prototype = Object.create( cBaseFunction.prototype ) cVLOOKUP.prototype = Object.create( cBaseFunction.prototype )
cVLOOKUP.prototype.Calculate = function ( arg ) { cVLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = this.argumentsCurrent == 4 ? arg[3].tocBool() : new cBool( true ); 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 ); return this.value = new CError( cErrorType.bad_reference );
if ( numberCol < 0 ) if ( numberCol < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
if ( arg0 instanceof cRef ) { if ( arg0 instanceof CRef ) {
arg0 = arg0.getValue() arg0 = arg0.getValue()
} }
if ( arg0 instanceof cString ) { if ( arg0 instanceof CString ) {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
} }
else if ( arg0 instanceof cError ) else if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else { else {
valueForSearching = arg0.getValue(); valueForSearching = arg0.getValue();
...@@ -1236,27 +1236,27 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1236,27 +1236,27 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
var found = false, bb; var found = false, bb;
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) { if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
min = oCache.min; min = oCache.min;
} }
} }
else if ( arg1 instanceof cArea ) { else if ( arg1 instanceof CArea ) {
var range = arg1.getRange(), ws = arg1.getWS(); var range = arg1.getRange(), ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
...@@ -1305,11 +1305,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1305,11 +1305,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
}*/ }*/
} }
else if ( arg1 instanceof cArea3D ) { else if ( arg1 instanceof CArea3D ) {
var range = arg1.getRange()[0], ws = arg1.getWS(); var range = arg1.getRange()[0], ws = arg1.getWS();
bb = range.getBBox0(); bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 ) if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference ); return this.value = new CError( cErrorType.bad_reference );
/*var matrix = arg1.getMatrix()[0] /*var matrix = arg1.getMatrix()[0]
...@@ -1355,7 +1355,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1355,7 +1355,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
}*/ }*/
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1); var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value); var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof CString, arg3.value);
if(oCache) if(oCache)
{ {
resR = oCache.index; resR = oCache.index;
...@@ -1363,8 +1363,8 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1363,8 +1363,8 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
if(arg0 instanceof cString) if(arg0 instanceof CString)
regexp = searchRegExp( valueForSearching ); regexp = searchRegExp( valueForSearching );
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
if ( r == 0 ) if ( r == 0 )
...@@ -1380,7 +1380,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1380,7 +1380,7 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
} }
else { else {
if ( arg0 instanceof cString ) { if ( arg0 instanceof CString ) {
if ( regexp.test( elem.getValue() ) ) if ( regexp.test( elem.getValue() ) )
resR = r; resR = r;
} }
...@@ -1393,15 +1393,15 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1393,15 +1393,15 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} ) } )
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
if ( resR == -1 ) { if ( resR == -1 ) {
return this.value = new cError( cErrorType.not_available ); 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 = new CError( cErrorType.bad_reference );
} }
return this.value = arg1.getElementRowCol( resR, numberCol ); return this.value = arg1.getElementRowCol( resR, numberCol );
...@@ -1409,11 +1409,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) { ...@@ -1409,11 +1409,11 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
} }
if ( min > valueForSearching ) { if ( min > valueForSearching ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
if ( resR == -1 ) { if ( resR == -1 ) {
return this.value = new cError( cErrorType.not_available ); 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 );
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -77,31 +77,31 @@ cCHAR.prototype = Object.create( cBaseFunction.prototype ) ...@@ -77,31 +77,31 @@ cCHAR.prototype = Object.create( cBaseFunction.prototype )
cCHAR.prototype.Calculate = function ( arg ) { cCHAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
var ret = new cArray(); var ret = new CArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocNumber(); var _elem = elem.tocNumber();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof cError ) if ( _elem instanceof CError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new cString( String.fromCharCode( _elem.getValue() ) ) ); ret.addElement( new CString( String.fromCharCode( _elem.getValue() ) ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocNumber(); arg0 = arg0.tocNumber();
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cString( String.fromCharCode( arg0.getValue() ) ); return this.value = new CString( String.fromCharCode( arg0.getValue() ) );
} }
cCHAR.prototype.getInfo = function () { cCHAR.prototype.getInfo = function () {
return { return {
...@@ -133,10 +133,10 @@ cCLEAN.prototype = Object.create( cBaseFunction.prototype ) ...@@ -133,10 +133,10 @@ cCLEAN.prototype = Object.create( cBaseFunction.prototype )
cCLEAN.prototype.Calculate = function ( arg ) { cCLEAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocNumber(); arg0 = arg0.cross( arguments[1].first ).tocNumber();
} }
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
...@@ -149,7 +149,7 @@ cCLEAN.prototype.Calculate = function ( arg ) { ...@@ -149,7 +149,7 @@ cCLEAN.prototype.Calculate = function ( arg ) {
res += v[i]; res += v[i];
} }
return this.value = new cString( res ); return this.value = new CString( res );
} }
cCLEAN.prototype.getInfo = function () { cCLEAN.prototype.getInfo = function () {
return { return {
...@@ -180,31 +180,31 @@ cCODE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -180,31 +180,31 @@ cCODE.prototype = Object.create( cBaseFunction.prototype )
cCODE.prototype.Calculate = function ( arg ) { cCODE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
var ret = new cArray(); var ret = new CArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof cError ) if ( _elem instanceof CError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new cNumber( _elem.toString().charCodeAt() ) ); ret.addElement( new CNumber( _elem.toString().charCodeAt() ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cNumber( arg0.toString().charCodeAt() ); return this.value = new CNumber( arg0.toString().charCodeAt() );
} }
cCODE.prototype.getInfo = function () { cCODE.prototype.getInfo = function () {
return { return {
...@@ -233,32 +233,32 @@ function cCONCATENATE() { ...@@ -233,32 +233,32 @@ function cCONCATENATE() {
} }
cCONCATENATE.prototype = Object.create( cBaseFunction.prototype ) cCONCATENATE.prototype = Object.create( cBaseFunction.prototype )
cCONCATENATE.prototype.Calculate = function ( arg ) { cCONCATENATE.prototype.Calculate = function ( arg ) {
var arg0 = new cString( "" ), argI; var arg0 = new CString( "" ), argI;
for ( var i = 0; i < this.argumentsCurrent; i++ ) { for ( var i = 0; i < this.argumentsCurrent; i++ ) {
argI = arg[i]; argI = arg[i];
if ( argI instanceof cArea || argI instanceof cArea3D ) { if ( argI instanceof CArea || argI instanceof CArea3D ) {
argI = argI.cross( arguments[1].first ); argI = argI.cross( arguments[1].first );
} }
argI = argI.tocString(); argI = argI.tocString();
if ( argI instanceof cError ) { if ( argI instanceof CError ) {
return this.value = argI; return this.value = argI;
} }
else if ( argI instanceof cArray ) { else if ( argI instanceof CArray ) {
argI.foreach( function ( elem ) { argI.foreach( function ( elem ) {
if ( elem instanceof cError ) { if ( elem instanceof CError ) {
arg0 = elem; arg0 = elem;
return true; return true;
} }
arg0 = new cString( arg0.toString().concat( elem.toString() ) ); arg0 = new CString( arg0.toString().concat( elem.toString() ) );
} ) } )
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
} }
else else
arg0 = new cString( arg0.toString().concat( argI.toString() ) ); arg0 = new CString( arg0.toString().concat( argI.toString() ) );
} }
return this.value = arg0; return this.value = arg0;
}; };
...@@ -316,16 +316,16 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -316,16 +316,16 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
if ( num_digits > cExcelMaxExponent ) { if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{ {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( 0 ); return new CNumber( 0 );
} }
else if ( num_digits < cExcelMinExponent ) { else if ( num_digits < cExcelMinExponent ) {
if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
{ {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( 0 ); return new CNumber( 0 );
} }
var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) ); var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
...@@ -333,10 +333,10 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -333,10 +333,10 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
number += significance / 2; number += significance / 2;
if ( number / significance == Infinity ) { if ( number / significance == Infinity ) {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( Floor( number, significance ) ); return new CNumber( Floor( number, significance ) );
} }
function toFix( str, skip ) { function toFix( str, skip ) {
...@@ -366,80 +366,80 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -366,80 +366,80 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new cNumber( 2 ), arg1 = arg[1] ? arg[1] : new CNumber( 2 ),
arg2 = arg[2] ? arg[2] : new cBool( false ); arg2 = arg[2] ? arg[2] : new CBool( false );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); else if ( arg0 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
} }
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) { if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); else if ( arg1 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
} }
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) { if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
else { else {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1.getElementRowCol( r, c ); var b = arg1.getElementRowCol( r, c );
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1; var b = arg1;
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
var a = arg0; var a = arg0;
var b = elem; var b = elem;
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg1; return this.value = arg1;
} }
...@@ -456,7 +456,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -456,7 +456,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
} }
} }
this.value = new cString( oNumFormatCache.get( "$#,##0" + cNull + ";($#,##0" + cNull + ")" ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text ) this.value = new CString( oNumFormatCache.get( "$#,##0" + cNull + ";($#,##0" + cNull + ")" ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text )
return this.value; return this.value;
} }
cDOLLAR.prototype.getInfo = function () { cDOLLAR.prototype.getInfo = function () {
...@@ -487,32 +487,32 @@ function cEXACT() { ...@@ -487,32 +487,32 @@ function cEXACT() {
cEXACT.prototype = Object.create( cBaseFunction.prototype ) cEXACT.prototype = Object.create( cBaseFunction.prototype )
cEXACT.prototype.Calculate = function ( arg ) { cEXACT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var arg0val = arg0.getValue(), arg1val = arg1.getValue(); var arg0val = arg0.getValue(), arg1val = arg1.getValue();
return this.value = new cBool( arg0val === arg1val ); return this.value = new CBool( arg0val === arg1val );
} }
cEXACT.prototype.getInfo = function () { cEXACT.prototype.getInfo = function () {
return { return {
...@@ -543,10 +543,10 @@ cFIND.prototype = Object.create( cBaseFunction.prototype ) ...@@ -543,10 +543,10 @@ cFIND.prototype = Object.create( cBaseFunction.prototype )
cFIND.prototype.Calculate = function ( arg ) { cFIND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1; var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1;
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
...@@ -555,29 +555,29 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -555,29 +555,29 @@ cFIND.prototype.Calculate = function ( arg ) {
if ( arg2 !== null ) { if ( arg2 !== null ) {
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg2 instanceof cArray ) { if ( arg2 instanceof CArray ) {
arg2 = arg1.getElementRowCol( 0, 0 ); arg2 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
pos = arg2.getValue(); pos = arg2.getValue();
pos = pos > 0 ? pos - 1 : pos; pos = pos > 0 ? pos - 1 : pos;
} }
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArray ) { if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
str = arg1.getValue(); str = arg1.getValue();
searchStr = arg0.getValue(); searchStr = arg0.getValue();
...@@ -585,7 +585,7 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -585,7 +585,7 @@ cFIND.prototype.Calculate = function ( arg ) {
if ( arg2 ) { if ( arg2 ) {
if ( pos > str.length || pos < 0 ) if ( pos > str.length || pos < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
str = str.substring( pos ); str = str.substring( pos );
res = str.search( searchStr ); res = str.search( searchStr );
...@@ -596,9 +596,9 @@ cFIND.prototype.Calculate = function ( arg ) { ...@@ -596,9 +596,9 @@ cFIND.prototype.Calculate = function ( arg ) {
res = str.search( searchStr ); res = str.search( searchStr );
if ( res < 0 ) if ( res < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
return this.value = new cNumber( res + 1 ); return this.value = new CNumber( res + 1 );
} }
cFIND.prototype.getInfo = function () { cFIND.prototype.getInfo = function () {
...@@ -660,16 +660,16 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -660,16 +660,16 @@ cFIXED.prototype.Calculate = function ( arg ) {
if ( num_digits > cExcelMaxExponent ) { if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{ {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( 0 ); return new CNumber( 0 );
} }
else if ( num_digits < cExcelMinExponent ) { else if ( num_digits < cExcelMinExponent ) {
if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
{ {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( 0 ); return new CNumber( 0 );
} }
var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) ); var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
...@@ -677,10 +677,10 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -677,10 +677,10 @@ cFIXED.prototype.Calculate = function ( arg ) {
number += significance / 2; number += significance / 2;
if ( number / significance == Infinity ) { if ( number / significance == Infinity ) {
return new cNumber( number ); return new CNumber( number );
} }
return new cNumber( Floor( number, significance ) ); return new CNumber( Floor( number, significance ) );
} }
function toFix( str, skip ) { function toFix( str, skip ) {
...@@ -710,80 +710,80 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -710,80 +710,80 @@ cFIXED.prototype.Calculate = function ( arg ) {
} }
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new cNumber( 2 ), arg1 = arg[1] ? arg[1] : new CNumber( 2 ),
arg2 = arg[2] ? arg[2] : new cBool( false ); arg2 = arg[2] ? arg[2] : new CBool( false );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); else if ( arg0 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
} }
else arg0 = arg0.tocNumber(); else arg0 = arg0.tocNumber();
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) { if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type ); else if ( arg1 instanceof CString ) return this.value = new CError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
} }
else arg1 = arg1.tocNumber(); else arg1 = arg1.tocNumber();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) { if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new cError( cErrorType.not_available ); return this.value = new CError( cErrorType.not_available );
} }
else { else {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1.getElementRowCol( r, c ); var b = arg1.getElementRowCol( r, c );
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var a = elem; var a = elem;
var b = arg1; var b = arg1;
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg0; return this.value = arg0;
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1.foreach( function ( elem, r, c ) { arg1.foreach( function ( elem, r, c ) {
var a = arg0; var a = arg0;
var b = elem; var b = elem;
if ( a instanceof cNumber && b instanceof cNumber ) { if ( a instanceof CNumber && b instanceof CNumber ) {
var res = roundHelper( a.getValue(), b.getValue() ); var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() ); this.array[r][c] = toFix( res.toString(), arg2.toBool() );
} }
else else
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new CError( cErrorType.wrong_value_type );
} ) } )
return this.value = arg1; return this.value = arg1;
} }
...@@ -797,7 +797,7 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -797,7 +797,7 @@ cFIXED.prototype.Calculate = function ( arg ) {
for ( var i = 0; i < num_digits; i++, cNull += "0" ) { for ( var i = 0; i < num_digits; i++, cNull += "0" ) {
} }
} }
return this.value = new cString( oNumFormatCache.get( "#" + (arg2.toBool() ? "" : ",") + "##0" + cNull ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text ) return this.value = new CString( oNumFormatCache.get( "#" + (arg2.toBool() ? "" : ",") + "##0" + cNull ).format( roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount )[0].text )
} }
cFIXED.prototype.getInfo = function () { cFIXED.prototype.getInfo = function () {
return { return {
...@@ -831,34 +831,34 @@ function cLEFT() { ...@@ -831,34 +831,34 @@ function cLEFT() {
} }
cLEFT.prototype = Object.create( cBaseFunction.prototype ) cLEFT.prototype = Object.create( cBaseFunction.prototype )
cLEFT.prototype.Calculate = function ( arg ) { cLEFT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new CNumber( 1 ) : arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type );
return this.value = new cString( arg0.getValue().substring( 0, arg1.getValue() ) ) return this.value = new CString( arg0.getValue().substring( 0, arg1.getValue() ) )
} }
cLEFT.prototype.getInfo = function () { cLEFT.prototype.getInfo = function () {
...@@ -895,19 +895,19 @@ function cLEN() { ...@@ -895,19 +895,19 @@ function cLEN() {
cLEN.prototype = Object.create( cBaseFunction.prototype ) cLEN.prototype = Object.create( cBaseFunction.prototype )
cLEN.prototype.Calculate = function ( arg ) { cLEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
return this.value = new cNumber( arg0.getValue().length ) return this.value = new CNumber( arg0.getValue().length )
} }
cLEN.prototype.getInfo = function () { cLEN.prototype.getInfo = function () {
...@@ -945,16 +945,16 @@ cLOWER.prototype = Object.create( cBaseFunction.prototype ) ...@@ -945,16 +945,16 @@ cLOWER.prototype = Object.create( cBaseFunction.prototype )
cLOWER.prototype.Calculate = function ( arg ) { cLOWER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) if ( arg0 instanceof CArea || arg0 instanceof CArea3D )
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cArray ) if ( arg0 instanceof CArray )
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
return this.value = new cString( arg0.getValue().toLowerCase() ); return this.value = new CString( arg0.getValue().toLowerCase() );
} }
cLOWER.prototype.getInfo = function () { cLOWER.prototype.getInfo = function () {
return { return {
...@@ -984,13 +984,13 @@ function cMID() { ...@@ -984,13 +984,13 @@ function cMID() {
cMID.prototype = Object.create( cBaseFunction.prototype ) cMID.prototype = Object.create( cBaseFunction.prototype )
cMID.prototype.Calculate = function ( arg ) { cMID.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ); arg2 = arg2.cross( arguments[1].first );
} }
...@@ -998,31 +998,31 @@ cMID.prototype.Calculate = function ( arg ) { ...@@ -998,31 +998,31 @@ cMID.prototype.Calculate = function ( arg ) {
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof cArray ) { if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cArray ) { if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg2 instanceof cArray ) { if ( arg2 instanceof CArray ) {
arg2 = arg2.getElementRowCol( 0, 0 ); arg2 = arg2.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2; if ( arg2 instanceof CError ) return this.value = arg2;
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type );
if ( arg2.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg2.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type );
var l = arg0.getValue().length; var l = arg0.getValue().length;
if ( arg1.getValue() > l ) if ( arg1.getValue() > l )
return this.value = new cString( "" ); return this.value = new CString( "" );
/* if( arg1.getValue() < l ) /* if( arg1.getValue() < l )
return this.value = arg0; */ return this.value = arg0; */
return this.value = new cString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue() - 1, arg2.getValue() ) ) return this.value = new CString( arg0.getValue().substr( arg1.getValue() == 0 ? 0 : arg1.getValue() - 1, arg2.getValue() ) )
} }
cMID.prototype.getInfo = function () { cMID.prototype.getInfo = function () {
...@@ -1087,31 +1087,31 @@ cPROPER.prototype.Calculate = function ( arg ) { ...@@ -1087,31 +1087,31 @@ cPROPER.prototype.Calculate = function ( arg ) {
return retStr; return retStr;
} }
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
var ret = new cArray(); var ret = new CArray();
arg0.foreach( function ( elem, r, c ) { arg0.foreach( function ( elem, r, c ) {
var _elem = elem.tocString(); var _elem = elem.tocString();
if ( !ret.array[r] ) if ( !ret.array[r] )
ret.addRow(); ret.addRow();
if ( _elem instanceof cError ) if ( _elem instanceof CError )
ret.addElement( _elem ); ret.addElement( _elem );
else else
ret.addElement( new cString( proper( _elem.toString() ) ) ); ret.addElement( new CString( proper( _elem.toString() ) ) );
} ) } )
return this.value = ret; return this.value = ret;
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) { if ( arg0 instanceof CError ) {
return this.value = arg0; return this.value = arg0;
} }
return this.value = new cString( proper( arg0.toString() ) ); return this.value = new CString( proper( arg0.toString() ) );
} }
cPROPER.prototype.getInfo = function () { cPROPER.prototype.getInfo = function () {
return { return {
...@@ -1142,53 +1142,53 @@ cREPLACE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1142,53 +1142,53 @@ cREPLACE.prototype = Object.create( cBaseFunction.prototype )
cREPLACE.prototype.Calculate = function ( arg ) { cREPLACE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3]; var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElement( 0 ).tocNumber(); arg1 = arg1.getElement( 0 ).tocNumber();
} }
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElement( 0 ).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) { if ( arg3 instanceof CArea || arg3 instanceof CArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocString(); arg3 = arg3.cross( arguments[1].first ).tocString();
} }
else if ( arg3 instanceof cArray ) { else if ( arg3 instanceof CArray ) {
arg3 = arg3.getElement( 0 ).tocString(); arg3 = arg3.getElement( 0 ).tocString();
} }
arg3 = arg3.tocString(); arg3 = arg3.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof cError ) if ( arg2 instanceof CError )
return this.value = arg2; return this.value = arg2;
if ( arg3 instanceof cError ) if ( arg3 instanceof CError )
return this.value = arg3; return this.value = arg3;
if ( arg1.getValue() < 1 || arg2.getValue() < 0 ) { if ( arg1.getValue() < 1 || arg2.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg3.getValue(), res = ""; var string1 = arg0.getValue(), string2 = arg3.getValue(), res = "";
...@@ -1199,7 +1199,7 @@ cREPLACE.prototype.Calculate = function ( arg ) { ...@@ -1199,7 +1199,7 @@ cREPLACE.prototype.Calculate = function ( arg ) {
res += string1[i]; res += string1[i];
} }
return this.value = new cString( res ); return this.value = new CString( res );
} }
cREPLACE.prototype.getInfo = function () { cREPLACE.prototype.getInfo = function () {
...@@ -1236,48 +1236,48 @@ function cREPT() { ...@@ -1236,48 +1236,48 @@ function cREPT() {
cREPT.prototype = Object.create( cBaseFunction.prototype ) cREPT.prototype = Object.create( cBaseFunction.prototype )
cREPT.prototype.Calculate = function ( arg ) { cREPT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], res = ""; var arg0 = arg[0], arg1 = arg[1], res = "";
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocNumber(); arg1 = arg1.cross( arguments[1].first ).tocNumber();
} }
else if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) { else if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
else if ( arg1 instanceof cString ) else if ( arg1 instanceof CString )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
else else
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type );
for ( var i = 0; i < arg1.getValue(); i++ ) { for ( var i = 0; i < arg1.getValue(); i++ ) {
res = res.concat( arg0.getValue() ); res = res.concat( arg0.getValue() );
} }
return this.value = new cString( res ); return this.value = new CString( res );
} }
cREPT.prototype.getInfo = function () { cREPT.prototype.getInfo = function () {
return { return {
...@@ -1306,34 +1306,34 @@ function cRIGHT() { ...@@ -1306,34 +1306,34 @@ function cRIGHT() {
} }
cRIGHT.prototype = Object.create( cBaseFunction.prototype ) cRIGHT.prototype = Object.create( cBaseFunction.prototype )
cRIGHT.prototype.Calculate = function ( arg ) { cRIGHT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1]; var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new CNumber( 1 ) : arg[1];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
arg1 = arg1.tocNumber(); arg1 = arg1.tocNumber();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) { if ( arg0 instanceof CArray && arg1 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type ); if ( arg1.getValue() < 0 ) return this.value = new CError( cErrorType.wrong_value_type );
var l = arg0.getValue().length, _number = l - arg1.getValue(); var l = arg0.getValue().length, _number = l - arg1.getValue();
return this.value = new cString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) ) return this.value = new CString( arg0.getValue().substring( _number < 0 ? 0 : _number, l ) )
} }
cRIGHT.prototype.getInfo = function () { cRIGHT.prototype.getInfo = function () {
...@@ -1370,44 +1370,44 @@ function cSEARCH() { ...@@ -1370,44 +1370,44 @@ function cSEARCH() {
cSEARCH.prototype = Object.create( cBaseFunction.prototype ) cSEARCH.prototype = Object.create( cBaseFunction.prototype )
cSEARCH.prototype.Calculate = function ( arg ) { cSEARCH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 1 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new CNumber( 1 );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElement( 0 ).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocNumber(); arg2 = arg2.cross( arguments[1].first ).tocNumber();
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElement( 0 ).tocNumber(); arg2 = arg2.getElement( 0 ).tocNumber();
} }
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof cError ) if ( arg2 instanceof CError )
return this.value = arg2; return this.value = arg2;
if ( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ) { if ( arg2.getValue() < 1 || arg2.getValue() > arg1.getValue().length ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
var string1 = arg0.getValue(), string2 = arg1.getValue(), var string1 = arg0.getValue(), string2 = arg1.getValue(),
...@@ -1437,9 +1437,9 @@ cSEARCH.prototype.Calculate = function ( arg ) { ...@@ -1437,9 +1437,9 @@ cSEARCH.prototype.Calculate = function ( arg ) {
var res = string2.substring( arg2.getValue() - 1 ).search( valueForSearching ) + arg2.getValue() - 1; var res = string2.substring( arg2.getValue() - 1 ).search( valueForSearching ) + arg2.getValue() - 1;
if ( res < 0 ) if ( res < 0 )
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
return this.value = new cNumber( res + 1 ); return this.value = new CNumber( res + 1 );
} }
cSEARCH.prototype.getInfo = function () { cSEARCH.prototype.getInfo = function () {
...@@ -1475,55 +1475,55 @@ function cSUBSTITUTE() { ...@@ -1475,55 +1475,55 @@ function cSUBSTITUTE() {
} }
cSUBSTITUTE.prototype = Object.create( cBaseFunction.prototype ) cSUBSTITUTE.prototype = Object.create( cBaseFunction.prototype )
cSUBSTITUTE.prototype.Calculate = function ( arg ) { cSUBSTITUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber( 0 ); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new CNumber( 0 );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ).tocString(); arg1 = arg1.cross( arguments[1].first ).tocString();
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElement( 0 ).tocString(); arg1 = arg1.getElement( 0 ).tocString();
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) { if ( arg2 instanceof CArea || arg2 instanceof CArea3D ) {
arg2 = arg2.cross( arguments[1].first ).tocString(); arg2 = arg2.cross( arguments[1].first ).tocString();
} }
else if ( arg2 instanceof cArray ) { else if ( arg2 instanceof CArray ) {
arg2 = arg2.getElement( 0 ).tocString(); arg2 = arg2.getElement( 0 ).tocString();
} }
arg2 = arg2.tocString(); arg2 = arg2.tocString();
if ( arg3 instanceof cArea || arg3 instanceof cArea3D ) { if ( arg3 instanceof CArea || arg3 instanceof CArea3D ) {
arg3 = arg3.cross( arguments[1].first ).tocNumber(); arg3 = arg3.cross( arguments[1].first ).tocNumber();
} }
else if ( arg3 instanceof cArray ) { else if ( arg3 instanceof CArray ) {
arg3 = arg3.getElement( 0 ).tocNumber(); arg3 = arg3.getElement( 0 ).tocNumber();
} }
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
if ( arg1 instanceof cError ) if ( arg1 instanceof CError )
return this.value = arg1; return this.value = arg1;
if ( arg2 instanceof cError ) if ( arg2 instanceof CError )
return this.value = arg2; return this.value = arg2;
if ( arg3 instanceof cError ) if ( arg3 instanceof CError )
return this.value = arg3; return this.value = arg3;
if ( arg3.getValue() < 0 ) { if ( arg3.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res; var string = arg0.getValue(), old_string = arg1.getValue(), new_string = arg2.getValue(), index = 0, res;
...@@ -1537,7 +1537,7 @@ cSUBSTITUTE.prototype.Calculate = function ( arg ) { ...@@ -1537,7 +1537,7 @@ cSUBSTITUTE.prototype.Calculate = function ( arg ) {
return equal; return equal;
} ) } )
return this.value = new cString( res ); return this.value = new CString( res );
} }
cSUBSTITUTE.prototype.getInfo = function () { cSUBSTITUTE.prototype.getInfo = function () {
...@@ -1568,22 +1568,22 @@ function cT() { ...@@ -1568,22 +1568,22 @@ function cT() {
cT.prototype = Object.create( cBaseFunction.prototype ) cT.prototype = Object.create( cBaseFunction.prototype )
cT.prototype.Calculate = function ( arg ) { cT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof cString || arg0 instanceof cError ) else if ( arg0 instanceof CString || arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg[0] instanceof cArray ) { else if ( arg[0] instanceof CArray ) {
arg0 = arg[0].getElementRowCol( 0, 0 ); arg0 = arg[0].getElementRowCol( 0, 0 );
} }
if ( arg0 instanceof cString || arg0 instanceof cError ) if ( arg0 instanceof CString || arg0 instanceof CError )
return this.value = arg[0]; return this.value = arg[0];
else else
return this.value = new cEmpty(); return this.value = new CEmpty();
} }
cT.prototype.getInfo = function () { cT.prototype.getInfo = function () {
return { return {
...@@ -1613,37 +1613,37 @@ function cTEXT() { ...@@ -1613,37 +1613,37 @@ function cTEXT() {
cTEXT.prototype = Object.create( cBaseFunction.prototype ) cTEXT.prototype = Object.create( cBaseFunction.prototype )
cTEXT.prototype.Calculate = function ( arg ) { cTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1]; var arg0 = arg[0], arg1 = arg[1];
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) { if ( arg0 instanceof CRef || arg0 instanceof CRef3D ) {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
} }
else if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { else if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) { if ( arg1 instanceof CRef || arg1 instanceof CRef3D ) {
arg1 = arg1.getValue(); arg1 = arg1.getValue();
} }
else if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) { else if ( arg1 instanceof CArea || arg1 instanceof CArea3D ) {
arg1 = arg1.cross( arguments[1].first ); arg1 = arg1.cross( arguments[1].first );
} }
else if ( arg1 instanceof cArray ) { else if ( arg1 instanceof CArray ) {
arg1 = arg1.getElementRowCol( 0, 0 ); arg1 = arg1.getElementRowCol( 0, 0 );
} }
arg1 = arg1.tocString(); arg1 = arg1.tocString();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1; if ( arg1 instanceof CError ) return this.value = arg1;
var _tmp = arg0.tocNumber(); var _tmp = arg0.tocNumber();
if ( _tmp instanceof cNumber ) if ( _tmp instanceof CNumber )
arg0 = _tmp; arg0 = _tmp;
var oFormat = oNumFormatCache.get( arg1.toString() ); var oFormat = oNumFormatCache.get( arg1.toString() );
var aText = oFormat.format( arg0.getValue(), arg0 instanceof cNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null ); var aText = oFormat.format( arg0.getValue(), arg0 instanceof CNumber ? CellValueType.Number : CellValueType.String, gc_nMaxDigCountView, null );
var text = ""; var text = "";
for ( var i = 0, length = aText.length; i < length; ++i ) { for ( var i = 0, length = aText.length; i < length; ++i ) {
...@@ -1658,7 +1658,7 @@ cTEXT.prototype.Calculate = function ( arg ) { ...@@ -1658,7 +1658,7 @@ cTEXT.prototype.Calculate = function ( arg ) {
text += aText[i].text; text += aText[i].text;
} }
return this.value = new cString( text ); return this.value = new CString( text );
} }
cTEXT.prototype.getInfo = function () { cTEXT.prototype.getInfo = function () {
return { return {
...@@ -1689,19 +1689,19 @@ cTRIM.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1689,19 +1689,19 @@ cTRIM.prototype = Object.create( cBaseFunction.prototype )
cTRIM.prototype.Calculate = function ( arg ) { cTRIM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ).tocString(); arg0 = arg0.cross( arguments[1].first ).tocString();
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElement( 0 ).tocString(); arg0 = arg0.getElement( 0 ).tocString();
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
return this.value = new cString( arg0.getValue().replace( rx_space_g, function ( $0, $1, $2 ) { return this.value = new CString( arg0.getValue().replace( rx_space_g, function ( $0, $1, $2 ) {
var res; var res;
rx_space.test( $2[$1 + 1] ) ? res = "" : res = $2[$1]; rx_space.test( $2[$1 + 1] ) ? res = "" : res = $2[$1];
return res; return res;
...@@ -1735,16 +1735,16 @@ function cUPPER() { ...@@ -1735,16 +1735,16 @@ function cUPPER() {
cUPPER.prototype = Object.create( cBaseFunction.prototype ) cUPPER.prototype = Object.create( cBaseFunction.prototype )
cUPPER.prototype.Calculate = function ( arg ) { cUPPER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
if ( arg0 instanceof cArray ) if ( arg0 instanceof CArray )
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) return this.value = arg0; if ( arg0 instanceof CError ) return this.value = arg0;
return this.value = new cString( arg0.getValue().toUpperCase() ); return this.value = new CString( arg0.getValue().toUpperCase() );
} }
cUPPER.prototype.getInfo = function () { cUPPER.prototype.getInfo = function () {
return { return {
...@@ -1776,24 +1776,24 @@ cVALUE.prototype = Object.create( cBaseFunction.prototype ) ...@@ -1776,24 +1776,24 @@ cVALUE.prototype = Object.create( cBaseFunction.prototype )
cVALUE.prototype.Calculate = function ( arg ) { cVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) { if ( arg0 instanceof CArea || arg0 instanceof CArea3D ) {
arg0 = arg0.cross( arguments[1].first ); arg0 = arg0.cross( arguments[1].first );
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof CArray ) {
arg0 = arg0.getElementRowCol( 0, 0 ); arg0 = arg0.getElementRowCol( 0, 0 );
} }
arg0 = arg0.tocString(); arg0 = arg0.tocString();
if ( arg0 instanceof cError ) if ( arg0 instanceof CError )
return this.value = arg0; return this.value = arg0;
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res ) if ( res )
return this.value = new cNumber( res.value ); return this.value = new CNumber( res.value );
else else
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new CError( cErrorType.wrong_value_type );
} }
cVALUE.prototype.getInfo = function () { cVALUE.prototype.getInfo = function () {
......
...@@ -3422,29 +3422,29 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){ ...@@ -3422,29 +3422,29 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
var oNewElem; var oNewElem;
if(range.isOneCell()) if(range.isOneCell())
{ {
if(elem instanceof cRef3D) if(elem instanceof CRef3D)
oNewElem = new cRef3D(ref, elem.ws.getName(), elem._wb); oNewElem = new CRef3D(ref, elem.ws.getName(), elem._wb);
else if(elem instanceof cArea3D) else if(elem instanceof CArea3D)
{ {
var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName(); var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName();
var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName(); var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName();
oNewElem = new cArea3D(ref, wsFrom, wsTo, elem._wb); oNewElem = new CArea3D(ref, wsFrom, wsTo, elem._wb);
} }
else else
oNewElem = new cRef(ref, elem.ws); oNewElem = new CRef(ref, elem.ws);
} }
else else
{ {
if(elem instanceof cRef3D) if(elem instanceof CRef3D)
oNewElem = new cArea3D(ref, elem.ws.getName(), elem.ws.getName(), elem._wb); oNewElem = new CArea3D(ref, elem.ws.getName(), elem.ws.getName(), elem._wb);
else if(elem instanceof cArea3D) else if(elem instanceof CArea3D)
{ {
var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName(); var wsFrom = elem._wb.getWorksheetById( elem.wsFrom ).getName();
var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName(); var wsTo = elem._wb.getWorksheetById( elem.wsTo ).getName();
oNewElem = new cArea3D(ref, wsFrom, wsTo, elem._wb); oNewElem = new CArea3D(ref, wsFrom, wsTo, elem._wb);
} }
else else
oNewElem = new cArea(ref, elem.ws); oNewElem = new CArea(ref, elem.ws);
} }
if ( ref.indexOf( "$" ) > -1 ) if ( ref.indexOf( "$" ) > -1 )
oNewElem.isAbsolute = true; oNewElem.isAbsolute = true;
...@@ -3535,9 +3535,9 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ ...@@ -3535,9 +3535,9 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
if ( c.formulaParsed && c.formulaParsed.outStack ) { if ( c.formulaParsed && c.formulaParsed.outStack ) {
for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) { for ( var i = 0, length = c.formulaParsed.outStack.length; i < length; i++ ) {
elem = c.formulaParsed.outStack[i]; elem = c.formulaParsed.outStack[i];
if ( elem instanceof cRef || elem instanceof cRef3D || elem instanceof cArea || elem instanceof cArea3D ) { if ( elem instanceof CRef || elem instanceof CRef3D || elem instanceof CArea || elem instanceof CArea3D ) {
var r = elem.getRange(); var r = elem.getRange();
if ( elem instanceof cArea3D && r.length > 0 ) if ( elem instanceof CArea3D && r.length > 0 )
r = r[0]; r = r[0];
if ( r && r.getNumFormatStr ) { if ( r && r.getNumFormatStr ) {
var sCurFormat = c.getNumFormatStr(); var sCurFormat = c.getNumFormatStr();
...@@ -3568,7 +3568,7 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){ ...@@ -3568,7 +3568,7 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad){
res = __cell.formulaParsed.calculate(); res = __cell.formulaParsed.calculate();
} }
else { else {
res = new cError( cErrorType.bad_reference ) res = new CError( cErrorType.bad_reference )
} }
if(res){ if(res){
if( res.type == cElementType.cell){ if( res.type == cElementType.cell){
......
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