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

рефакторинг.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55864 954022d7-b5bf-4e40-9824-e11837661b57
parent 9e84b5e7
......@@ -7,7 +7,9 @@
* Time: 15:15
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Cube = {
cFormulaFunction.Cube = {
'groupName':"Cube",
'CUBEKPIMEMBER':cCUBEKPIMEMBER,
'CUBEMEMBER':cCUBEMEMBER,
......@@ -34,6 +36,7 @@ function cCUBEKPIMEMBER() {
this.numFormat = this.formatType.def;
}
cCUBEKPIMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBEMEMBER() {
......@@ -52,6 +55,7 @@ function cCUBEMEMBER() {
this.numFormat = this.formatType.def;
}
cCUBEMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBEMEMBERPROPERTY() {
......@@ -70,6 +74,7 @@ function cCUBEMEMBERPROPERTY() {
this.numFormat = this.formatType.def;
}
cCUBEMEMBERPROPERTY.prototype = Object.create( cBaseFunction.prototype );
function cCUBERANKEDMEMBER() {
......@@ -88,6 +93,7 @@ function cCUBERANKEDMEMBER() {
this.numFormat = this.formatType.def;
}
cCUBERANKEDMEMBER.prototype = Object.create( cBaseFunction.prototype );
function cCUBESET() {
......@@ -106,6 +112,7 @@ function cCUBESET() {
this.numFormat = this.formatType.def;
}
cCUBESET.prototype = Object.create( cBaseFunction.prototype );
function cCUBESETCOUNT() {
......@@ -124,6 +131,7 @@ function cCUBESETCOUNT() {
this.numFormat = this.formatType.def;
}
cCUBESETCOUNT.prototype = Object.create( cBaseFunction.prototype );
function cCUBEVALUE() {
......@@ -142,4 +150,5 @@ function cCUBEVALUE() {
this.numFormat = this.formatType.def;
}
cCUBEVALUE.prototype = Object.create( cBaseFunction.prototype );
......@@ -7,7 +7,8 @@
* Time: 15:16
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Database = {
cFormulaFunction.Database = {
'groupName':"Database",
'DAVERAGE':cDAVERAGE,
'DCOUNT':cDCOUNT,
......@@ -26,59 +27,71 @@ FormulaObjects.cFormulaFunction.Database = {
function cDAVERAGE() {
cBaseFunction.call( this, "DAVERAGE" );
}
cDAVERAGE.prototype = Object.create( cBaseFunction.prototype );
function cDCOUNT() {
cBaseFunction.call( this, "DCOUNT" );
}
cDCOUNT.prototype = Object.create( cBaseFunction.prototype );
function cDCOUNTA() {
cBaseFunction.call( this, "DCOUNTA" );
}
cDCOUNTA.prototype = Object.create( cBaseFunction.prototype );
function cDGET() {
cBaseFunction.call( this, "DGET" );
}
cDGET.prototype = Object.create( cBaseFunction.prototype );
function cDMAX() {
cBaseFunction.call( this, "DMAX" );
}
cDMAX.prototype = Object.create( cBaseFunction.prototype );
function cDMIN() {
cBaseFunction.call( this, "DMIN" );
}
cDMIN.prototype = Object.create( cBaseFunction.prototype );
function cDPRODUCT() {
cBaseFunction.call( this, "DPRODUCT" );
}
cDPRODUCT.prototype = Object.create( cBaseFunction.prototype );
function cDSTDEV() {
cBaseFunction.call( this, "DSTDEV" );
}
cDSTDEV.prototype = Object.create( cBaseFunction.prototype );
function cDSTDEVP() {
cBaseFunction.call( this, "DSTDEVP" );
}
cDSTDEVP.prototype = Object.create( cBaseFunction.prototype );
function cDSUM() {
cBaseFunction.call( this, "DSUM" );
}
cDSUM.prototype = Object.create( cBaseFunction.prototype );
function cDVAR() {
cBaseFunction.call( this, "DVAR" );
}
cDVAR.prototype = Object.create( cBaseFunction.prototype );
function cDVARP() {
cBaseFunction.call( this, "DVARP" );
}
cDVARP.prototype = Object.create( cBaseFunction.prototype );
......@@ -8,6 +8,7 @@
* To change this template use File | Settings | File Templates.
*/
var DayCountBasis = {
// US 30/360
UsPsa30_360:0,
......@@ -21,16 +22,16 @@ var DayCountBasis = {
Europ30_360:4
}
function yearFrac(d1, d2, mode) {
function yearFrac( d1, d2, mode ) {
d1.truncate();
d2.truncate();
var date1 = d1.getUTCDate(),
month1 = d1.getUTCMonth()+1,
month1 = d1.getUTCMonth() + 1,
year1 = d1.getUTCFullYear(),
date2 = d2.getUTCDate(),
month2 = d2.getUTCMonth()+1,
month2 = d2.getUTCMonth() + 1,
year2 = d2.getUTCFullYear();
switch ( mode ) {
......@@ -38,7 +39,7 @@ function yearFrac(d1, d2, mode) {
return new cNumber( Math.abs( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) ) / 360 );
case DayCountBasis.ActualActual:
var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? new Date(d2) : new Date(d1),
sd = year1 > year2 ? new Date( d2 ) : new Date( d1 ),
yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = /*Math.abs*/( d2 - d1 );
for ( var i = 0; i < yc; i++ ) {
sd.addYears( 1 );
......@@ -62,12 +63,12 @@ function yearFrac(d1, d2, mode) {
}
}
function diffDate(d1, d2, mode){
function diffDate( d1, d2, mode ) {
var date1 = d1.getUTCDate(),
month1 = d1.getUTCMonth()+1,
month1 = d1.getUTCMonth() + 1,
year1 = d1.getUTCFullYear(),
date2 = d2.getUTCDate(),
month2 = d2.getUTCMonth()+1,
month2 = d2.getUTCMonth() + 1,
year2 = d2.getUTCFullYear();
switch ( mode ) {
......@@ -75,7 +76,7 @@ function diffDate(d1, d2, mode){
return new cNumber( GetDiffDate360( date1, month1, year1, d1.isLeapYear(), date2, month2, year2, true ) );
case DayCountBasis.ActualActual:
var yc = /*Math.abs*/( year2 - year1 ),
sd = year1 > year2 ? new Date(d2) : new Date(d1),
sd = year1 > year2 ? new Date( d2 ) : new Date( d1 ),
yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = d2 - d1;
for ( var i = 0; i < yc; i++ ) {
sd.addYears( 1 );
......@@ -99,7 +100,7 @@ function diffDate(d1, d2, mode){
}
}
function diffDate2(d1, d2, mode){
function diffDate2( d1, d2, mode ) {
var date1 = d1.getUTCDate(),
month1 = d1.getUTCMonth(),
year1 = d1.getUTCFullYear(),
......@@ -113,7 +114,7 @@ function diffDate2(d1, d2, mode){
case DayCountBasis.UsPsa30_360:
nDaysInYear = 360;
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 );
case DayCountBasis.ActualActual:
nYears = year2 - year1;
......@@ -121,62 +122,60 @@ function diffDate2(d1, d2, mode){
var dayDiff;
if( nYears && ( month1 > month2 || ( month1 == month2 && date1 > date2 ) ) )
if ( nYears && ( month1 > month2 || ( month1 == month2 && date1 > date2 ) ) )
nYears--;
if( nYears )
dayDiff = parseInt((d2 - new Date( Date.UTC(year2, month1, date1) ))/c_msPerDay);
if ( nYears )
dayDiff = parseInt( (d2 - new Date( Date.UTC( year2, month1, date1 ) )) / c_msPerDay );
else
dayDiff = parseInt(( d2 - d1 )/c_msPerDay);
dayDiff = parseInt( ( d2 - d1 ) / c_msPerDay );
if( dayDiff < 0 )
if ( dayDiff < 0 )
dayDiff += nDaysInYear;
return new cNumber( nYears + dayDiff / nDaysInYear );
case DayCountBasis.Actual360:
nDaysInYear = 360;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay;
nYears = parseInt( ( d2 - d1 ) / c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1) / c_msPerDay;
nDayDiff %= nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Actual365:
nDaysInYear = 365;
nYears = parseInt( ( d2 - d1 )/c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1)/c_msPerDay;
nYears = parseInt( ( d2 - d1 ) / c_msPerDay / nDaysInYear );
nDayDiff = (d2 - d1) / c_msPerDay;
nDayDiff %= nDaysInYear;
return new cNumber( nYears + nDayDiff / nDaysInYear );
case DayCountBasis.Europ30_360:
nDaysInYear = 360;
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 );
default:
return new cError( cErrorType.not_numeric );
}
}
function GetDiffDate( d1,d2, nMode ){
function GetDiffDate( d1, d2, nMode ) {
var bNeg = d1 > d2;
if( bNeg )
{
if ( bNeg ) {
var n = d2;
d2 = d1;
d1 = n;
}
var nRet,pOptDaysIn1stYear
var nRet, pOptDaysIn1stYear
var nD1 = d1.getUTCDate(),
nM1 = d1.getUTCMonth(),
nY1 = d1.getUTCFullYear(),
nY1 = d1.getUTCFullYear(),
nD2 = d2.getUTCDate(),
nM2 = d2.getUTCMonth(),
nY2 = d2.getUTCFullYear();
switch( nMode )
{
case DayCountBasis.UsPsa30_360: // 0=USA (NASD) 30/360
case DayCountBasis.Europ30_360: // 4=Europe 30/360
switch ( nMode ) {
case DayCountBasis.UsPsa30_360: // 0=USA (NASD) 30/360
case DayCountBasis.Europ30_360: // 4=Europe 30/360
{
var bLeap = d1.isLeapYear()
var nDays, nMonths/*, nYears*/;
......@@ -187,30 +186,30 @@ function GetDiffDate( d1,d2, nMode ){
nMonths += ( nY2 - nY1 ) * 12;
nRet = nMonths * 30 + nDays;
if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )
nRet -= bLeap? 1 : 2;
if ( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )
nRet -= bLeap ? 1 : 2;
pOptDaysIn1stYear = 360;
pOptDaysIn1stYear = 360;
}
break;
case DayCountBasis.ActualActual: // 1=exact/exact
case DayCountBasis.ActualActual: // 1=exact/exact
pOptDaysIn1stYear = d1.isLeapYear() ? 366 : 365;
nRet = d2 - d1;
break;
case DayCountBasis.Actual360: // 2=exact/360
case DayCountBasis.Actual360: // 2=exact/360
nRet = d2 - d1;
pOptDaysIn1stYear = 360;
break;
case DayCountBasis.Actual365: //3=exact/365
case DayCountBasis.Actual365: //3=exact/365
nRet = d2 - d1;
pOptDaysIn1stYear = 365;
pOptDaysIn1stYear = 365;
break;
}
return (bNeg ? -nRet : nRet) / c_msPerDay / pOptDaysIn1stYear;
}
FormulaObjects.cFormulaFunction.DateAndTime = {
cFormulaFunction.DateAndTime = {
'groupName':"DateAndTime",
'DATE':cDATE,
'DATEDIF':cDATEDIF,
......@@ -255,6 +254,7 @@ function cDATE() {
this.numFormat = this.formatType.def;
}
cDATE.prototype = Object.create( cBaseFunction.prototype )
cDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], year, month, day;
......@@ -295,7 +295,7 @@ cDATE.prototype.Calculate = function ( arg ) {
if ( month == 0 ) {
return this.setCA( new cError( cErrorType.not_numeric ), true );
}
this.value = new cNumber( Math.round( new Date( Date.UTC(year, month - 1, day) ).getExcelDate() ) )
this.value = new cNumber( Math.round( new Date( Date.UTC( year, month - 1, day ) ).getExcelDate() ) )
this.value.numFormat = 14;
this.value.ca = true;
return this.value;
......@@ -326,6 +326,7 @@ function cDATEDIF() {
this.numFormat = this.formatType.noneFormat;
}
cDATEDIF.prototype = Object.create( cBaseFunction.prototype )
cDATEDIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
......@@ -373,7 +374,7 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
years -= date2.getUTCMonth() < date1.getUTCMonth();
months -= date2.getUTCDate() < date1.getUTCDate();
days += days < 0 ? new Date( Date.UTC(date2.getUTCFullYear(), date2.getUTCMonth() - 1, 0) ).getUTCDate() + 1 : 0;
days += days < 0 ? new Date( Date.UTC( date2.getUTCFullYear(), date2.getUTCMonth() - 1, 0 ) ).getUTCDate() + 1 : 0;
return [ years, months, days ];
}
......@@ -390,7 +391,7 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
break;
case "MD":
if ( val0.getUTCDate() > val1.getUTCDate() ) {
this.value = new cNumber( Math.abs( new Date( Date.UTC(val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate()) ) - new Date( Date.UTC(val0.getUTCFullYear(), val0.getUTCMonth() + 1, val1.getUTCDate()) ) ) / c_msPerDay );
this.value = new cNumber( Math.abs( new Date( Date.UTC( val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate() ) ) - new Date( Date.UTC( val0.getUTCFullYear(), val0.getUTCMonth() + 1, val1.getUTCDate() ) ) ) / c_msPerDay );
}
else {
this.value = new cNumber( val1.getUTCDate() - val0.getUTCDate() );
......@@ -403,10 +404,10 @@ cDATEDIF.prototype.Calculate = function ( arg ) {
break;
case "YD":
if ( val0.getUTCMonth() > val1.getUTCMonth() ) {
this.value = new cNumber( Math.abs( new Date( Date.UTC(val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate()) ) - new Date( Date.UTC(val0.getUTCFullYear() + 1, val1.getUTCMonth(), val1.getUTCDate()) ) ) / c_msPerDay );
this.value = new cNumber( Math.abs( new Date( Date.UTC( val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate() ) ) - new Date( Date.UTC( val0.getUTCFullYear() + 1, val1.getUTCMonth(), val1.getUTCDate() ) ) ) / c_msPerDay );
}
else {
this.value = new cNumber( Math.abs( new Date( Date.UTC(val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate()) ) - new Date( Date.UTC(val0.getUTCFullYear(), val1.getUTCMonth(), val1.getUTCDate()) ) ) / c_msPerDay );
this.value = new cNumber( Math.abs( new Date( Date.UTC( val0.getUTCFullYear(), val0.getUTCMonth(), val0.getUTCDate() ) ) - new Date( Date.UTC( val0.getUTCFullYear(), val1.getUTCMonth(), val1.getUTCDate() ) ) ) / c_msPerDay );
}
return this.value;
break;
......@@ -441,6 +442,7 @@ function cDATEVALUE() {
this.numFormat = this.formatType.noneFormat;
}
cDATEVALUE.prototype = Object.create( cBaseFunction.prototype )
cDATEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -493,6 +495,7 @@ function cDAY() {
this.numFormat = this.formatType.noneFormat;
}
cDAY.prototype = Object.create( cBaseFunction.prototype )
cDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -569,6 +572,7 @@ function cDAYS360() {
this.numFormat = this.formatType.noneFormat;
}
cDAYS360.prototype = Object.create( cBaseFunction.prototype )
cDAYS360.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cBool( false );
......@@ -637,6 +641,7 @@ function cEDATE() {
this.numFormat = this.formatType.noneFormat;
}
cEDATE.prototype = Object.create( cBaseFunction.prototype )
cEDATE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -718,6 +723,7 @@ function cEOMONTH() {
this.numFormat = this.formatType.noneFormat;
}
cEOMONTH.prototype = Object.create( cBaseFunction.prototype )
cEOMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -791,6 +797,7 @@ function cHOUR() {
this.numFormat = this.formatType.noneFormat;
}
cHOUR.prototype = Object.create( cBaseFunction.prototype )
cHOUR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -864,6 +871,7 @@ function cMINUTE() {
this.numFormat = this.formatType.noneFormat;
}
cMINUTE.prototype = Object.create( cBaseFunction.prototype )
cMINUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -939,6 +947,7 @@ function cMONTH() {
this.numFormat = this.formatType.noneFormat;
}
cMONTH.prototype = Object.create( cBaseFunction.prototype )
cMONTH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -1014,6 +1023,7 @@ function cNETWORKDAYS() {
this.numFormat = this.formatType.noneFormat;
}
cNETWORKDAYS.prototype = Object.create( cBaseFunction.prototype )
cNETWORKDAYS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
......@@ -1129,6 +1139,7 @@ cNETWORKDAYS.prototype.getInfo = function () {
function cNETWORKDAYS_INTL() {
cBaseFunction.call( this, "NETWORKDAYS.INTL" );
}
cNETWORKDAYS_INTL.prototype = Object.create( cBaseFunction.prototype )
function cNOW() {
......@@ -1149,10 +1160,11 @@ function cNOW() {
this.numFormat = this.formatType.def;
}
cNOW.prototype = Object.create( cBaseFunction.prototype )
cNOW.prototype.Calculate = function () {
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( d.getExcelDate() + ( (d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds()) / c_sPerDay ) );
this.value.numFormat = 22;
return this.setCA( this.value, true );
}
......@@ -1182,6 +1194,7 @@ function cSECOND() {
this.numFormat = this.formatType.noneFormat;
}
cSECOND.prototype = Object.create( cBaseFunction.prototype )
cSECOND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -1256,6 +1269,7 @@ function cTIME() {
this.numFormat = this.formatType.def;
}
cTIME.prototype = Object.create( cBaseFunction.prototype )
cTIME.prototype.Calculate = function ( arg ) {
var hour = arg[0], minute = arg[1], second = arg[2];
......@@ -1323,6 +1337,7 @@ function cTIMEVALUE() {
this.numFormat = this.formatType.noneFormat;
}
cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype )
cTIMEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1374,6 +1389,7 @@ function cTODAY() {
this.numFormat = this.formatType.def;
}
cTODAY.prototype = Object.create( cBaseFunction.prototype )
cTODAY.prototype.Calculate = function () {
this.setCA( new cNumber( new Date().getExcelDate() ), true );
......@@ -1407,6 +1423,7 @@ function cWEEKDAY() {
this.numFormat = this.formatType.noneFormat;
}
cWEEKDAY.prototype = Object.create( cBaseFunction.prototype )
cWEEKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 );
......@@ -1497,13 +1514,14 @@ function cWEEKNUM() {
this.numFormat = this.formatType.noneFormat;
}
cWEEKNUM.prototype = Object.create( cBaseFunction.prototype )
cWEEKNUM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 1 ), type = 0;
function WeekNumber( dt, iso, type ) {
dt.setUTCHours( 0, 0, 0 );
var startOfYear = new Date( Date.UTC(dt.getUTCFullYear(), 0, 1) );
var startOfYear = new Date( Date.UTC( dt.getUTCFullYear(), 0, 1 ) );
var endOfYear = new Date( dt );
endOfYear.setUTCMonth( 11 );
endOfYear.setUTCDate( 31 );
......@@ -1619,6 +1637,7 @@ function cWORKDAY() {
this.numFormat = this.formatType.noneFormat;
}
cWORKDAY.prototype = Object.create( cBaseFunction.prototype )
cWORKDAY.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arrDateIncl = [];
......@@ -1730,6 +1749,7 @@ cWORKDAY.prototype.getInfo = function () {
function cWORKDAY_INTL() {
cBaseFunction.call( this, "WORKDAY.INTL" );
}
cWORKDAY_INTL.prototype = Object.create( cBaseFunction.prototype )
function cYEAR() {
......@@ -1751,6 +1771,7 @@ function cYEAR() {
this.numFormat = this.formatType.noneFormat;
}
cYEAR.prototype = Object.create( cBaseFunction.prototype )
cYEAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], val;
......@@ -1823,6 +1844,7 @@ function cYEARFRAC() {
this.numFormat = this.formatType.noneFormat;
}
cYEARFRAC.prototype = Object.create( cBaseFunction.prototype )
cYEARFRAC.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 0 );
......@@ -1872,4 +1894,5 @@ cYEARFRAC.prototype.getInfo = function () {
name:this.name,
args:"( start-date , end-date [ , basis ] )"
};
}
\ No newline at end of file
}
"use strict";
function ConvertToDec( aStrSource, nBase, nCharLim ){
if ( nBase < 2 || nBase > 36 ){
return "Error #1";}
function ConvertToDec( aStrSource, nBase, nCharLim ) {
if ( nBase < 2 || nBase > 36 ) {
return "Error #1";
}
var nStrLen = aStrSource.length;
if( nStrLen > nCharLim ){
return "Error #2";}
else if( !nStrLen ){
return 0;}
if ( nStrLen > nCharLim ) {
return "Error #2";
}
else if ( !nStrLen ) {
return 0;
}
var fVal = 0, nFirstDig = 0,
bFirstDig = true;
for(var i=0; i < aStrSource.length; i++)
{
for ( var i = 0; i < aStrSource.length; i++ ) {
var n;
if( '0' <= aStrSource[i] && aStrSource[i] <= '9' ){
n = aStrSource[i].charCodeAt(0) - '0'.charCodeAt(0);}
else if( 'A' <= aStrSource[i] && aStrSource[i] <= 'Z' ){
n = 10 + ( aStrSource[i].charCodeAt(0) - 'A'.charCodeAt(0) );}
else if ( 'a' <= aStrSource[i] && aStrSource[i] <= 'z' ){
n = 10 + ( aStrSource[i].charCodeAt(0) - 'a'.charCodeAt(0) );}
else{
n = nBase;}
if ( '0' <= aStrSource[i] && aStrSource[i] <= '9' ) {
n = aStrSource[i].charCodeAt( 0 ) - '0'.charCodeAt( 0 );
}
else if ( 'A' <= aStrSource[i] && aStrSource[i] <= 'Z' ) {
n = 10 + ( aStrSource[i].charCodeAt( 0 ) - 'A'.charCodeAt( 0 ) );
}
else if ( 'a' <= aStrSource[i] && aStrSource[i] <= 'z' ) {
n = 10 + ( aStrSource[i].charCodeAt( 0 ) - 'a'.charCodeAt( 0 ) );
}
else {
n = nBase;
}
if( n < nBase )
{
if( bFirstDig )
{
if ( n < nBase ) {
if ( bFirstDig ) {
bFirstDig = false;
nFirstDig = n;
}
fVal = fVal * nBase + n;
}
else{
return "Error #3";}
else {
return "Error #3";
}
}
if( nStrLen === nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) )
{ // handling negativ values
if ( nStrLen === nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) ) { // handling negativ values
fVal = ( Math.pow( nBase, nCharLim ) - fVal ); // complement
fVal *= -1.0;
}
......@@ -53,10 +57,12 @@ 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 );}
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))
......@@ -68,10 +74,12 @@ function BesselJ( x, N ) {
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);}
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
......@@ -124,16 +132,19 @@ function BesselJ( x, N ) {
k = k + 1;
}
while ( !bHasfound && k <= fMaxIteration );
if ( bHasfound ){
return new cNumber( u * fSign );}
else{
return new cError(cErrorType.not_numeric);}// unlikely to happen
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 );}
if ( n < 0 ) {
return new cError( cErrorType.not_numeric );
}
/* Start the iteration without TERM(n,0), which is set here.
......@@ -152,21 +163,21 @@ function BesselI( x, n ) {
{
/* Calculation of TERM(n,k) from TERM(n,k-1):
(x/2)^(n+2k)
(x/2)^(n+2k)
TERM(n,k) = --------------
k! (n+k)!
k! (n+k)!
(x/2)^2 (x/2)^(n+2(k-1))
(x/2)^2 (x/2)^(n+2(k-1))
= --------------------------
k (k-1)! (n+k) (n+k-1)!
k (k-1)! (n+k) (n+k-1)!
(x/2)^2 (x/2)^(n+2(k-1))
(x/2)^2 (x/2)^(n+2(k-1))
= --------- * ------------------
k(n+k) (k-1)! (n+k-1)!
k(n+k) (k-1)! (n+k-1)!
x^2/4
x^2/4
= -------- TERM(n,k-1)
k(n+k)
k(n+k)
*/
fTerm = fTerm * fXHalf / nK * fXHalf / (nK + n);
fResult += fTerm;
......@@ -179,7 +190,7 @@ function BesselI( x, n ) {
}
function Besselk0( fNum ) {
var fRet,y;
var fRet, y;
if ( fNum <= 2 ) {
var fNum2 = fNum * 0.5;
......@@ -351,7 +362,8 @@ function BesselY( fNum, nOrder ) {
* Time: 12:25
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Engineering = {
cFormulaFunction.Engineering = {
'groupName':"Engineering",
'BESSELI':cBESSELI,
'BESSELJ':cBESSELJ,
......@@ -397,194 +409,233 @@ FormulaObjects.cFormulaFunction.Engineering = {
function cBESSELI() {
cBaseFunction.call( this, "BESSELI" );
}
cBESSELI.prototype = Object.create( cBaseFunction.prototype );
function cBESSELJ() {
cBaseFunction.call( this, "BESSELJ" );
}
cBESSELJ.prototype = Object.create( cBaseFunction.prototype );
function cBESSELK() {
cBaseFunction.call( this, "BESSELK" );
}
cBESSELK.prototype = Object.create( cBaseFunction.prototype );
function cBESSELY() {
cBaseFunction.call( this, "BESSELY" );
}
cBESSELY.prototype = Object.create( cBaseFunction.prototype );
function cBIN2DEC() {
cBaseFunction.call( this, "BIN2DEC" );
}
cBIN2DEC.prototype = Object.create( cBaseFunction.prototype );
function cBIN2HEX() {
cBaseFunction.call( this, "BIN2HEX" );
}
cBIN2HEX.prototype = Object.create( cBaseFunction.prototype );
function cBIN2OCT() {
cBaseFunction.call( this, "BIN2OCT" );
}
cBIN2OCT.prototype = Object.create( cBaseFunction.prototype );
function cCOMPLEX() {
cBaseFunction.call( this, "COMPLEX" );
}
cCOMPLEX.prototype = Object.create( cBaseFunction.prototype );
function cCONVERT() {
cBaseFunction.call( this, "CONVERT" );
}
cCONVERT.prototype = Object.create( cBaseFunction.prototype );
function cDEC2BIN() {
cBaseFunction.call( this, "DEC2BIN" );
}
cDEC2BIN.prototype = Object.create( cBaseFunction.prototype );
function cDEC2HEX() {
cBaseFunction.call( this, "DEC2HEX" );
}
cDEC2HEX.prototype = Object.create( cBaseFunction.prototype );
function cDEC2OCT() {
cBaseFunction.call( this, "DEC2OCT" );
}
cDEC2OCT.prototype = Object.create( cBaseFunction.prototype );
function cDELTA() {
cBaseFunction.call( this, "DELTA" );
}
cDELTA.prototype = Object.create( cBaseFunction.prototype );
function cERF() {
cBaseFunction.call( this, "ERF" );
}
cERF.prototype = Object.create( cBaseFunction.prototype );
function cERFC() {
cBaseFunction.call( this, "ERFC" );
}
cERFC.prototype = Object.create( cBaseFunction.prototype );
function cGESTEP() {
cBaseFunction.call( this, "GESTEP" );
}
cGESTEP.prototype = Object.create( cBaseFunction.prototype );
function cHEX2BIN() {
cBaseFunction.call( this, "HEX2BIN" );
}
cHEX2BIN.prototype = Object.create( cBaseFunction.prototype );
function cHEX2DEC() {
cBaseFunction.call( this, "HEX2DEC" );
}
cHEX2DEC.prototype = Object.create( cBaseFunction.prototype );
function cHEX2OCT() {
cBaseFunction.call( this, "HEX2OCT" );
}
cHEX2OCT.prototype = Object.create( cBaseFunction.prototype );
function cIMABS() {
cBaseFunction.call( this, "IMABS" );
}
cIMABS.prototype = Object.create( cBaseFunction.prototype );
function cIMAGINARY() {
cBaseFunction.call( this, "IMAGINARY" );
}
cIMAGINARY.prototype = Object.create( cBaseFunction.prototype );
function cIMARGUMENT() {
cBaseFunction.call( this, "IMARGUMENT" );
}
cIMARGUMENT.prototype = Object.create( cBaseFunction.prototype );
function cIMCONJUGATE() {
cBaseFunction.call( this, "IMCONJUGATE" );
}
cIMCONJUGATE.prototype = Object.create( cBaseFunction.prototype );
function cIMCOS() {
cBaseFunction.call( this, "IMCOS" );
}
cIMCOS.prototype = Object.create( cBaseFunction.prototype );
function cIMDIV() {
cBaseFunction.call( this, "IMDIV" );
}
cIMDIV.prototype = Object.create( cBaseFunction.prototype );
function cIMEXP() {
cBaseFunction.call( this, "IMEXP" );
}
cIMEXP.prototype = Object.create( cBaseFunction.prototype );
function cIMLN() {
cBaseFunction.call( this, "IMLN" );
}
cIMLN.prototype = Object.create( cBaseFunction.prototype );
function cIMLOG10() {
cBaseFunction.call( this, "IMLOG10" );
}
cIMLOG10.prototype = Object.create( cBaseFunction.prototype );
function cIMLOG2() {
cBaseFunction.call( this, "IMLOG2" );
}
cIMLOG2.prototype = Object.create( cBaseFunction.prototype );
function cIMPOWER() {
cBaseFunction.call( this, "IMPOWER" );
}
cIMPOWER.prototype = Object.create( cBaseFunction.prototype );
function cIMPRODUCT() {
cBaseFunction.call( this, "IMPRODUCT" );
}
cIMPRODUCT.prototype = Object.create( cBaseFunction.prototype );
function cIMREAL() {
cBaseFunction.call( this, "IMREAL" );
}
cIMREAL.prototype = Object.create( cBaseFunction.prototype );
function cIMSIN() {
cBaseFunction.call( this, "IMSIN" );
}
cIMSIN.prototype = Object.create( cBaseFunction.prototype );
function cIMSQRT() {
cBaseFunction.call( this, "IMSQRT" );
}
cIMSQRT.prototype = Object.create( cBaseFunction.prototype );
function cIMSUB() {
cBaseFunction.call( this, "IMSUB" );
}
cIMSUB.prototype = Object.create( cBaseFunction.prototype );
function cIMSUM() {
cBaseFunction.call( this, "IMSUM" );
}
cIMSUM.prototype = Object.create( cBaseFunction.prototype );
function cOCT2BIN() {
cBaseFunction.call( this, "OCT2BIN" );
}
cOCT2BIN.prototype = Object.create( cBaseFunction.prototype );
function cOCT2DEC() {
cBaseFunction.call( this, "OCT2DEC" );
}
cOCT2DEC.prototype = Object.create( cBaseFunction.prototype );
function cOCT2HEX() {
cBaseFunction.call( this, "OCT2HEX" );
}
cOCT2HEX.prototype = Object.create( cBaseFunction.prototype );
......@@ -92,75 +92,79 @@ function getIPMT( rate, per, pv, type, pmt ) {
*/
function RateIteration( nper, payment, pv, fv, payType, guess ) {
var bValid = true, bFound = false, fX, fXnew, fTerm, fTermDerivation, fGeoSeries, fGeoSeriesDerivation,
var valid = true, found = false, x, xnew, term, termDerivation, geoSeries, geoSeriesDerivation,
iterationMax = 150, nCount = 0, minEps = 1E-14, eps = 1E-7,
fPowN, fPowNminus1;
powN, powNminus1;
fv = fv - payment * payType;
pv = pv + payment * payType;
if ( nper === Math.round( nper ) ) {
fX = guess.fGuess;
while ( !bFound && nCount < iterationMax ) {
fPowNminus1 = Math.pow( 1 + fX, nper - 1 );
fPowN = fPowNminus1 * (1 + fX);
if ( Math.approxEqual( Math.abs( fX ), 0 ) ) {
fGeoSeries = nper;
fGeoSeriesDerivation = nper * (nper - 1) / 2;
x = guess;
while ( !found && nCount < iterationMax ) {
powNminus1 = Math.pow( 1 + x, nper - 1 );
powN = powNminus1 * (1 + x);
if ( Math.approxEqual( Math.abs( x ), 0 ) ) {
geoSeries = nper;
geoSeriesDerivation = nper * (nper - 1) / 2;
}
else {
fGeoSeries = (fPowN - 1) / fX;
fGeoSeriesDerivation = nper * fPowNminus1 / fX - fGeoSeries / fX;
geoSeries = (powN - 1) / x;
geoSeriesDerivation = ( nper * powNminus1 - geoSeries ) / x;
}
fTerm = fv + pv * fPowN + payment * fGeoSeries;
fTermDerivation = pv * nper * fPowNminus1 + payment * fGeoSeriesDerivation;
if ( Math.abs( fTerm ) < minEps ) {
bFound = true;
term = fv + pv * powN + payment * geoSeries;
termDerivation = pv * nper * powNminus1 + payment * geoSeriesDerivation;
if ( Math.abs( term ) < minEps ) {
found = true;
}
else {
if ( Math.approxEqual( Math.abs( fTermDerivation ), 0 ) ) {
fXnew = fX + 1.1 * eps;
if ( Math.approxEqual( Math.abs( termDerivation ), 0 ) ) {
xnew = x + 1.1 * eps;
}
else {
fXnew = fX - fTerm / fTermDerivation;
xnew = x - term / termDerivation;
}
nCount++;
bFound = (Math.abs( fXnew - fX ) < eps);
fX = fXnew;
found = (Math.abs( xnew - x ) < eps);
x = xnew;
}
}
bValid = (fX >= -1);
valid = (x >= -1);
}
else {
fX = (guess.fGuest < -1) ? -1 : guess.fGuest;
while ( bValid && !bFound && nCount < iterationMax ) {
if ( Math.approxEqual( Math.abs( fX ), 0 ) ) {
fGeoSeries = nper;
fGeoSeriesDerivation = nper * (nper - 1) / 2;
x = (guess < -1) ? -1 : guess;
while ( valid && !found && nCount < iterationMax ) {
if ( Math.approxEqual( Math.abs( x ), 0 ) ) {
geoSeries = nper;
geoSeriesDerivation = nper * (nper - 1) / 2;
}
else {
fGeoSeries = (Math.pow( 1 + fX, nper ) - 1) / fX;
fGeoSeriesDerivation = nper * Math.pow( 1 + fX, nper - 1 ) / fX - fGeoSeries / fX;
geoSeries = (Math.pow( 1 + x, nper ) - 1) / x;
geoSeriesDerivation = nper * Math.pow( 1 + x, nper - 1 ) / x - geoSeries / x;
}
fTerm = fv + pv * Math.pow( 1 + fX, nper ) + payment * fGeoSeries;
fTermDerivation = pv * nper * Math.pow( 1 + fX, nper - 1 ) + payment * fGeoSeriesDerivation;
if ( Math.abs( fTerm ) < minEps ) {
bFound = true;
term = fv + pv * Math.pow( 1 + x, nper ) + payment * geoSeries;
termDerivation = pv * nper * Math.pow( 1 + x, nper - 1 ) + payment * geoSeriesDerivation;
if ( Math.abs( term ) < minEps ) {
found = true;
}
else {
if ( Math.approxEqual( Math.abs( fTermDerivation ), 0 ) ) {
fXnew = fX + 1.1 * eps;
if ( Math.approxEqual( Math.abs( termDerivation ), 0 ) ) {
xnew = x + 1.1 * eps;
}
else {
fXnew = fX - fTerm / fTermDerivation;
xnew = x - term / termDerivation;
}
nCount++;
bFound = (Math.abs( fXnew - fX ) < eps);
fX = fXnew;
bValid = (fX >= -1);
found = (Math.abs( xnew - x ) < eps);
x = xnew;
valid = (x >= -1);
}
}
}
guess.fGuess = fX;
return bValid && bFound;
if( valid && found ){
return new cNumber( x );
}
else{
return new cError( cErrorType.wrong_value_type );
}
}
function lcl_GetCouppcd( settl, matur, freq ) {
......@@ -215,6 +219,12 @@ function getcoupdaysnc( settl, matur, frequency, basis ) {
return getcoupdays( new Date( settl ), new Date( matur ), frequency, basis ) - getcoupdaybs( new Date( settl ), new Date( matur ), frequency, basis );
}
function getcoupncd( settl, matur, frequency ) {
var s = new Date( settl ), m = new Date( matur );
lcl_GetCoupncd( s, m, frequency );
return m;
}
function getprice( settle, mat, rate, yld, redemp, freq, base ) {
var cdays = getcoupdays( new Date( settle ), new Date( mat ), freq, base ),
......@@ -319,6 +329,108 @@ function getduration( settlement, maturity, coupon, yld, frequency, basis ) {
}
function oddFPrice(settl,matur,iss,firstCoup,rate,yld,redemption,frequency,basis) {
function positiveDaysBetween( d1, d2, b ) {
var res = diffDate( d1, d2, b );
return res > 0 ? res : 0;
}
function addMonth( orgDate, numMonths, returnLastDay ) {
var newDate = new Date( orgDate );
newDate.addMonths( numMonths );
if ( returnLastDay ) {
newDate.setUTCDate( newDate.getDaysInMonth() );
}
return newDate;
}
function coupNumber( mat, settl, numMonths, isWholeNumber ) {
var my = mat.getUTCFullYear(), mm = mat.getUTCMonth(), md = mat.getUTCDate(),
endOfMonthTemp = mat.lastDayOfMonth(),
endOfMonth = (!endOfMonthTemp && mm != 1 && md > 28 && md < new Date( my, mm ).getDaysInMonth()) ? settl.lastDayOfMonth() : endOfMonthTemp,
startDate = addMonth( settl, 0, endOfMonth ),
coupons = (isWholeNumber - 0) + (settl < startDate),
frontDate = addMonth( startDate, numMonths, endOfMonth );
while ( !(numMonths > 0 ? frontDate >= endDate : frontDate <= endDate) ) {
frontDate = addMonth( frontDate, numMonths, endOfMonth );
coupons++;
}
return coupons;
}
var res = 0, DSC,
numMonths = 12 / frequency,
numMonthsNeg = -numMonths,
E = getcoupdays( settl, new Date( firstCoup ), frequency, basis ),
coupNums = getcoupnum( settl, new Date( matur ), frequency ),
dfc = positiveDaysBetween( new Date( iss ), new Date( firstCoup ), basis );
if ( dfc < E ) {
DSC = positiveDaysBetween( settl, firstCoup, basis );
rate *= 100 / frequency;
yld /= frequency;
yld++;
DSC /= E;
res = redemption / Math.pow( yld, (coupNums - 1 + DSC) );
res += rate * dfc / E / Math.pow( yld, DSC );
res -= rate * positiveDaysBetween( iss, settl, basis ) / E;
for ( var i = 1; i < coupNums; i++ ) {
res += rate / Math.pow( yld, (i + DSC) );
}
}
else {
var nc = getcoupnum( iss, firstCoup, frequency ),
lateCoupon = new Date( firstCoup ),
DCdivNL = 0, AdivNL = 0, startDate, endDate,
earlyCoupon, NLi, DCi;
for ( var index = nc; index >= 1; index-- ) {
earlyCoupon = addMonth( lateCoupon, numMonthsNeg, false );
NLi = basis == DayCountBasis.ActualActual ? positiveDaysBetween( earlyCoupon, lateCoupon, basis ) : E;
DCi = index > 1 ? NLi : positiveDaysBetween( iss, lateCoupon, basis );
startDate = iss > earlyCoupon ? iss : earlyCoupon;
endDate = settl < lateCoupon ? settl : lateCoupon;
lateCoupon = new Date( earlyCoupon );
DCdivNL += DCi / NLi;
AdivNL += positiveDaysBetween( startDate, endDate, basis ) / NLi;
}
if ( basis == DayCountBasis.Actual360 || basis == DayCountBasis.Actual365 ) {
DSC = positiveDaysBetween( settl, getcoupncd( settl, firstCoup, frequency ), basis );
}
else {
DSC = E - diffDate( getcoupncd( settl, firstCoup, frequency ), settl, basis );
}
var Nq = coupNumber( firstCoup, settl, numMonths, true );
coupNums = getcoupnum( firstCoup, matur, frequency );
yld /= frequency;
yld++;
DSC /= E;
rate *= 100 / frequency;
for ( var i = 1; i <= coupNums; i++ ) {
res += 1 / Math.pow( yld, (i + Nq + DSC) );
}
res *= rate;
res += redemption / Math.pow( yld, (DSC + Nq + coupNums) );
res += rate * DCdivNL / Math.pow( yld, (Nq + DSC) );
res -= rate * AdivNL;
}
return res;
}
/**
* Created with JetBrains WebStorm.
* User: Dmitry.Shahtanov
......@@ -326,7 +438,7 @@ function getduration( settlement, maturity, coupon, yld, frequency, basis ) {
* Time: 15:19
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Financial = {
cFormulaFunction.Financial = {
'groupName':"Financial",
'ACCRINT':cACCRINT,
'ACCRINTM':cACCRINTM,
......@@ -399,6 +511,7 @@ function cACCRINT() {
this.numFormat = this.formatType.noneFormat;
}
cACCRINT.prototype = Object.create( cBaseFunction.prototype );
cACCRINT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1],
......@@ -507,6 +620,7 @@ function cACCRINTM() {
this.numFormat = this.formatType.noneFormat;
}
cACCRINTM.prototype = Object.create( cBaseFunction.prototype );
cACCRINTM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0],
......@@ -595,6 +709,7 @@ function cAMORDEGRC() {
this.numFormat = this.formatType.noneFormat;
}
cAMORDEGRC.prototype = Object.create( cBaseFunction.prototype );
cAMORDEGRC.prototype.Calculate = function ( arg ) {
var cost = arg[0],
......@@ -740,6 +855,7 @@ function cAMORLINC() {
this.numFormat = this.formatType.noneFormat;
}
cAMORLINC.prototype = Object.create( cBaseFunction.prototype );
cAMORLINC.prototype.Calculate = function ( arg ) {
var cost = arg[0],
......@@ -863,6 +979,7 @@ function cCOUPDAYBS() {
this.numFormat = this.formatType.noneFormat;
}
cCOUPDAYBS.prototype = Object.create( cBaseFunction.prototype );
cCOUPDAYBS.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -940,6 +1057,7 @@ function cCOUPDAYS() {
this.numFormat = this.formatType.noneFormat;
}
cCOUPDAYS.prototype = Object.create( cBaseFunction.prototype );
cCOUPDAYS.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1017,6 +1135,7 @@ function cCOUPDAYSNC() {
this.numFormat = this.formatType.noneFormat;
}
cCOUPDAYSNC.prototype = Object.create( cBaseFunction.prototype );
cCOUPDAYSNC.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1097,6 +1216,7 @@ function cCOUPNCD() {
this.numFormat = this.formatType.noneFormat;
}
cCOUPNCD.prototype = Object.create( cBaseFunction.prototype );
cCOUPNCD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1150,8 +1270,7 @@ cCOUPNCD.prototype.Calculate = function ( arg ) {
frequency = frequency.getValue();
lcl_GetCoupncd( settl, matur, frequency );
this.value = new cNumber( matur.getExcelDate() );
this.value = new cNumber( getcoupncd( settl, matur, frequency ).getExcelDate() );
this.value.numFormat = 14;
return this.value;
......@@ -1179,6 +1298,7 @@ function cCOUPNUM() {
this.numFormat = this.formatType.noneFormat;
}
cCOUPNUM.prototype = Object.create( cBaseFunction.prototype );
cCOUPNUM.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1259,6 +1379,7 @@ function cCOUPPCD() {
};
this.numFormat = this.formatType.noneFormat;
}
cCOUPPCD.prototype = Object.create( cBaseFunction.prototype );
cCOUPPCD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1342,6 +1463,7 @@ function cCUMIPMT() {
this.numFormat = this.formatType.noneFormat;
}
cCUMIPMT.prototype = Object.create( cBaseFunction.prototype );
cCUMIPMT.prototype.Calculate = function ( arg ) {
var rate = arg[0],
......@@ -1462,6 +1584,7 @@ function cCUMPRINC() {
this.numFormat = this.formatType.noneFormat;
}
cCUMPRINC.prototype = Object.create( cBaseFunction.prototype );
cCUMPRINC.prototype.Calculate = function ( arg ) {
var rate = arg[0],
......@@ -1586,6 +1709,7 @@ function cDB() {
this.numFormat = this.formatType.noneFormat;
}
cDB.prototype = Object.create( cBaseFunction.prototype );
cDB.prototype.Calculate = function ( arg ) {
var cost = arg[0],
......@@ -1696,6 +1820,7 @@ function cDDB() {
this.numFormat = this.formatType.noneFormat;
}
cDDB.prototype = Object.create( cBaseFunction.prototype );
cDDB.prototype.Calculate = function ( arg ) {
var cost = arg[0],
......@@ -1788,6 +1913,7 @@ function cDISC() {
this.numFormat = this.formatType.noneFormat;
}
cDISC.prototype = Object.create( cBaseFunction.prototype );
cDISC.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -1876,6 +2002,7 @@ function cDOLLARDE() {
this.numFormat = this.formatType.noneFormat;
}
cDOLLARDE.prototype = Object.create( cBaseFunction.prototype );
cDOLLARDE.prototype.Calculate = function ( arg ) {
var fractionalDollar = arg[0],
......@@ -1943,6 +2070,7 @@ function cDOLLARFR() {
this.numFormat = this.formatType.noneFormat;
}
cDOLLARFR.prototype = Object.create( cBaseFunction.prototype );
cDOLLARFR.prototype.Calculate = function ( arg ) {
var decimalDollar = arg[0],
......@@ -2010,6 +2138,7 @@ function cDURATION() {
this.numFormat = this.formatType.noneFormat;
}
cDURATION.prototype = Object.create( cBaseFunction.prototype );
cDURATION.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -2117,6 +2246,7 @@ function cEFFECT() {
this.numFormat = this.formatType.noneFormat;
}
cEFFECT.prototype = Object.create( cBaseFunction.prototype );
cEFFECT.prototype.Calculate = function ( arg ) {
var nominalRate = arg[0], npery = arg[1];
......@@ -2174,6 +2304,7 @@ function cFV() {
this.numFormat = this.formatType.noneFormat;
}
cFV.prototype = Object.create( cBaseFunction.prototype );
cFV.prototype.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pmt = arg[2], pv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
......@@ -2260,6 +2391,7 @@ function cFVSCHEDULE() {
this.numFormat = this.formatType.noneFormat;
}
cFVSCHEDULE.prototype = Object.create( cBaseFunction.prototype );
cFVSCHEDULE.prototype.Calculate = function ( arg ) {
var principal = arg[0],
......@@ -2329,6 +2461,7 @@ function cINTRATE() {
}
cINTRATE.prototype = Object.create( cBaseFunction.prototype );
cINTRATE.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -2418,6 +2551,7 @@ function cIPMT() {
this.numFormat = this.formatType.noneFormat;
}
cIPMT.prototype = Object.create( cBaseFunction.prototype );
cIPMT.prototype.Calculate = function ( arg ) {
var rate = arg[0], per = arg[1], nper = arg[2], pv = arg[3], fv = arg[4] ? arg[4] : new cNumber( 0 ), type = arg[5] ? arg[5] : new cNumber( 0 );
......@@ -2520,6 +2654,7 @@ function cIRR() {
this.numFormat = this.formatType.noneFormat;
}
cIRR.prototype = Object.create( cBaseFunction.prototype );
cIRR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 0.1 );
......@@ -2527,7 +2662,7 @@ cIRR.prototype.Calculate = function ( arg ) {
function irr( arr, x ) {
x = x.getValue();
var nC = 0, g_Eps = 1e-7, fEps = 1, fZ = 0, fN = 0, xN = 0, nIM = 100, nMC = 0, arr0 = arr[0], arrI, wasNegative = false, wasPositive = false;
var count = 0, g_Eps = 1e-7, eps = 1, funcVal = 0, derivVal = 0, xN = 0, nIM = 100, nMC = 0, arr0 = arr[0], arrI, wasNegative = false, wasPositive = false;
if ( arr0 instanceof cError ) {
return new cError( cErrorType.not_available );
......@@ -2540,36 +2675,36 @@ cIRR.prototype.Calculate = function ( arg ) {
if ( arr.length < 2 )
return new cError( cErrorType.not_numeric );
while ( fEps > g_Eps && nMC < nIM ) {
nC = 0;
fZ = 0;
fN = 0;
fZ += arr0.getValue() / Math.pow( 1 + x, nC );
fN += -nC * arr0.getValue() / Math.pow( 1 + x, nC + 1 );
nC++;
while ( eps > g_Eps && nMC < nIM ) {
count = 0;
funcVal = 0;
derivVal = 0;
funcVal += arr0.getValue() / Math.pow( 1 + x, count );
derivVal += -count * arr0.getValue() / Math.pow( 1 + x, count + 1 );
count++;
for ( var i = 1; i < arr.length; i++ ) {
if ( arr[i] instanceof cError ) {
return new cError( cErrorType.not_available );
}
arrI = arr[i].getValue();
fZ += arrI / Math.pow( 1 + x, nC );
fN += -nC * arrI / Math.pow( 1 + x, nC + 1 );
funcVal += arrI / Math.pow( 1 + x, count );
derivVal += -count * arrI / Math.pow( 1 + x, count + 1 );
if ( arrI < 0 )
wasNegative = true;
else if ( arrI > 0 )
wasPositive = true;
nC++
count++
}
xN = x - fZ / fN;
xN = x - funcVal / derivVal;
nMC++;
fEps = Math.abs( xN - x );
eps = Math.abs( xN - x );
x = xN;
}
if ( !(wasNegative && wasPositive) )
return new cError( cErrorType.not_numeric );
if ( fEps < g_Eps )
if ( eps < g_Eps )
return new cNumber( x );
else
return new cError( cErrorType.not_numeric );
......@@ -2620,6 +2755,7 @@ function cISPMT() {
this.numFormat = this.formatType.noneFormat;
}
cISPMT.prototype = Object.create( cBaseFunction.prototype );
cISPMT.prototype.Calculate = function ( arg ) {
var rate = arg[0], per = arg[1], nper = arg[2], pv = arg[3];
......@@ -2687,6 +2823,7 @@ function cMDURATION() {
this.numFormat = this.formatType.noneFormat;
}
cMDURATION.prototype = Object.create( cBaseFunction.prototype );
cMDURATION.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -2798,6 +2935,7 @@ function cMIRR() {
this.numFormat = this.formatType.noneFormat;
}
cMIRR.prototype = Object.create( cBaseFunction.prototype );
cMIRR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], fRate1_invest = arg[1], fRate1_reinvest = arg[2];
......@@ -2912,6 +3050,7 @@ function cNOMINAL() {
this.numFormat = this.formatType.noneFormat;
}
cNOMINAL.prototype = Object.create( cBaseFunction.prototype );
cNOMINAL.prototype.Calculate = function ( arg ) {
var effectRate = arg[0],
......@@ -2973,6 +3112,7 @@ function cNPER() {
this.numFormat = this.formatType.noneFormat;
}
cNPER.prototype = Object.create( cBaseFunction.prototype );
cNPER.prototype.Calculate = function ( arg ) {
var rate = arg[0], pmt = arg[1], pv = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
......@@ -3068,6 +3208,7 @@ function cNPV() {
this.numFormat = this.formatType.noneFormat;
}
cNPV.prototype = Object.create( cBaseFunction.prototype );
cNPV.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], iStart = 1, res = 0, rate;
......@@ -3149,6 +3290,7 @@ function cODDFPRICE() {
this.numFormat = this.formatType.noneFormat;
}
cODDFPRICE.prototype = Object.create( cBaseFunction.prototype );
cODDFPRICE.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -3254,9 +3396,11 @@ cODDFPRICE.prototype.Calculate = function ( arg ) {
frequency = frequency.getValue();
basis = basis.getValue();
if ( settlement >= maturity || maturity <= first_coupon ||
if ( maturity <= first_coupon || first_coupon <= settlement ||
settlement <= issue ||
basis < 0 || basis > 4 ||
yld < 0 || rate < 0 ||
redemption < 0 ||
frequency != 1 && frequency != 2 && frequency != 4 )
return this.value = new cError( cErrorType.not_numeric );
......@@ -3265,138 +3409,149 @@ cODDFPRICE.prototype.Calculate = function ( arg ) {
iss = Date.prototype.getDateFromExcel( issue ),
firstCoup = Date.prototype.getDateFromExcel( first_coupon );
function lastDayOfMonth( y, m, d ) {
return (new Date( y, m - 1 )).getDaysInMonth() == d;
}
function daysBetweenNotNeg( d1, d2, b ) {
var res = diffDate( d1, d2, b );
return res > 0 ? res : 0;
}
function changeMonth( orgDate, numMonths, returnLastDay ) {
var newDate = new Date( orgDate );
newDate.addMonths( numMonths );
if ( returnLastDay )
return new Date( newDate.getUTCFullYear(), newDate.getUTCMonth(), newDate.getDaysInMonth() );
else
return newDate;
}
this.value = new cNumber( oddFPrice(settl,matur,iss,firstCoup,rate,yld,redemption,frequency,basis) );
return this.value;
function _getcoupncd( settl, matur, frequency ) {
var s = new Date( settl ), m = new Date( matur );
lcl_GetCoupncd( s, m, frequency );
return m;
}
};
cODDFPRICE.prototype.getInfo = function () {
return {
name:this.name,
args:"( settlement , maturity , issue , first-coupon , rate , yld , redemption , frequency [ , [ basis ] ] )"
};
};
function datesAggregate1( startDate, endDate, numMonths, acc, returnLastMonth ) {
var frontDate = startDate, trailingDate = endDate;
function cODDFYIELD() {
cBaseFunction.call( this, "ODDFYIELD" );
}
while ( !(numMonths > 0 ? frontDate >= endDate : frontDate <= endDate) ) {
trailingDate = frontDate;
frontDate = changeMonth( frontDate, numMonths, returnLastMonth );
acc++;
}
return acc;
cODDFYIELD.prototype = Object.create( cBaseFunction.prototype );
/*cODDFYIELD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
maturity = arg[1],
issue = arg[2],
first_coupon = arg[3],
rate = arg[4],
pr = arg[5],
redemption = arg[6],
frequency = arg[7],
basis = arg[8] && !(arg[8] instanceof cEmpty) ? arg[8] : new cNumber( 0 );
if ( settlement instanceof cArea || settlement instanceof cArea3D ) {
settlement = settlement.cross( arguments[1].first );
}
else if ( settlement instanceof cArray ) {
settlement = settlement.getElementRowCol( 0, 0 );
}
function coupNumber( mat, settl, numMonths, isWholeNumber ) {
var my = mat.getUTCFullYear(), mm = mat.getUTCMonth() + 1, md = mat.getDate(),
sy = settl.getUTCFullYear(), sm = settl.getUTCMonth() + 1, sd = settl.getDate(),
endOfMonthTemp = lastDayOfMonth( my, mm, md ),
endOfMonth = (!endOfMonthTemp && mm != 2 && md > 28 && md < new Date( my, mm ).getDaysInMonth()) ? lastDayOfMonth( sy, sm, sd ) : endOfMonthTemp,
startDate = changeMonth( settl, 0, endOfMonth ),
coupons = (isWholeNumber - 0) + (settl < startDate);
var frontDate = changeMonth( startDate, numMonths, endOfMonth ), trailingDate = mat;
while ( !(numMonths > 0 ? frontDate >= endDate : frontDate <= endDate) ) {
trailingDate = frontDate;
frontDate = changeMonth( frontDate, numMonths, endOfMonth );
coupons++;
}
if ( maturity instanceof cArea || maturity instanceof cArea3D ) {
maturity = maturity.cross( arguments[1].first );
}
else if ( maturity instanceof cArray ) {
maturity = maturity.getElementRowCol( 0, 0 );
}
return coupons;
if ( issue instanceof cArea || issue instanceof cArea3D ) {
issue = issue.cross( arguments[1].first );
}
else if ( issue instanceof cArray ) {
issue = issue.getElementRowCol( 0, 0 );
}
if ( first_coupon instanceof cArea || first_coupon instanceof cArea3D ) {
first_coupon = first_coupon.cross( arguments[1].first );
}
else if ( first_coupon instanceof cArray ) {
first_coupon = first_coupon.getElementRowCol( 0, 0 );
}
var res = 0, dsc,
numMonths = 12 / frequency, numMonthsNeg = -numMonths,
e = getcoupdays( settl, new Date( firstCoup ), frequency, basis ),
coupNums = getcoupnum( settl, new Date( matur ), frequency ),
dfc = daysBetweenNotNeg( new Date( iss ), new Date( firstCoup ), basis );
if ( rate instanceof cArea || rate instanceof cArea3D ) {
rate = rate.cross( arguments[1].first );
}
else if ( rate instanceof cArray ) {
rate = rate.getElementRowCol( 0, 0 );
}
if ( dfc < e ) {
dsc = daysBetweenNotNeg( settl, firstCoup, basis );
rate *= 100 / frequency;
yld /= frequency;
yld++;
dsc /= e;
if ( pr instanceof cArea || pr instanceof cArea3D ) {
pr = pr.cross( arguments[1].first );
}
else if ( pr instanceof cArray ) {
pr = pr.getElementRowCol( 0, 0 );
}
res = redemption / Math.pow( yld, (coupNums - 1 + dsc) );
res += rate * dfc / e / Math.pow( yld, dsc );
res -= rate * daysBetweenNotNeg( iss, settl, basis ) / e;
if ( redemption instanceof cArea || redemption instanceof cArea3D ) {
redemption = redemption.cross( arguments[1].first );
}
else if ( redemption instanceof cArray ) {
redemption = redemption.getElementRowCol( 0, 0 );
}
for ( var i = 1; i < coupNums; i++ ) {
res += rate / Math.pow( yld, (i + dsc) );
}
if ( frequency instanceof cArea || frequency instanceof cArea3D ) {
frequency = frequency.cross( arguments[1].first );
}
else if ( frequency instanceof cArray ) {
frequency = frequency.getElementRowCol( 0, 0 );
}
if ( basis instanceof cArea || basis instanceof cArea3D ) {
basis = basis.cross( arguments[1].first );
}
else if ( basis instanceof cArray ) {
basis = basis.getElementRowCol( 0, 0 );
}
else {
var nc = getcoupnum( iss, firstCoup, frequency ),
lateCoupon = new Date( firstCoup ),
dcnl = 0, anl = 0, startDate, endDate,
earlyCoupon, nl, dci;
for ( var index = nc; index >= 1; index-- ) {
settlement = settlement.tocNumber();
maturity = maturity.tocNumber();
issue = issue.tocNumber();
first_coupon = first_coupon.tocNumber();
rate = rate.tocNumber();
pr = pr.tocNumber();
redemption = redemption.tocNumber();
frequency = frequency.tocNumber();
basis = basis.tocNumber();
earlyCoupon = changeMonth( lateCoupon, numMonthsNeg, false );
nl = basis == DayCountBasis.ActualActual ? daysBetweenNotNeg( earlyCoupon, lateCoupon, basis ) : e;
dci = index > 1 ? nl : daysBetweenNotNeg( iss, lateCoupon, basis );
startDate = iss > earlyCoupon ? iss : earlyCoupon;
endDate = settl < lateCoupon ? settl : lateCoupon;
lateCoupon = new Date( earlyCoupon );
dcnl += dci / nl;
anl += daysBetweenNotNeg( startDate, endDate, basis ) / nl;
if ( settlement instanceof cError ) return this.value = settlement;
if ( maturity instanceof cError ) return this.value = maturity;
if ( issue instanceof cError ) return this.value = issue;
if ( first_coupon instanceof cError ) return this.value = first_coupon;
if ( rate instanceof cError ) return this.value = rate;
if ( pr instanceof cError ) return this.value = pr;
if ( redemption instanceof cError ) return this.value = redemption;
if ( frequency instanceof cError ) return this.value = frequency;
if ( basis instanceof cError ) return this.value = basis;
}
settlement = settlement.getValue();
maturity = maturity.getValue();
issue = issue.getValue();
first_coupon = first_coupon.getValue();
rate = rate.getValue();
pr = pr.getValue();
redemption = redemption.getValue();
frequency = frequency.getValue();
basis = basis.getValue();
if ( basis == DayCountBasis.Actual360 || basis == DayCountBasis.Actual365 ) {
dsc = daysBetweenNotNeg( settl, _getcoupncd( settl, firstCoup, frequency ), basis );
}
else {
dsc = e - diffDate( _getcoupncd( settl, firstCoup, frequency ), settl, basis );
}
var nq = coupNumber( firstCoup, settl, numMonths, true );
coupNums = getcoupnum( firstCoup, matur, frequency );
yld = yld / frequency + 1;
dsc = dsc / e;
rate *= 100 / frequency;
res = redemption / Math.pow( yld, (dsc + nq + coupNums) );
res += rate * dcnl / Math.pow( yld, (nq + dsc) );
res -= rate * anl;
if ( maturity <= first_coupon || first_coupon <= settlement ||
settlement <= issue ||
basis < 0 || basis > 4 ||
pr < 0 || rate < 0 ||
redemption < 0 ||
frequency != 1 && frequency != 2 && frequency != 4 )
return this.value = new cError( cErrorType.not_numeric );
for ( var i = 1; i <= coupNums; i++ ) {
res += rate / Math.pow( yld, (i + nq + dsc) );
}
var settl = Date.prototype.getDateFromExcel( settlement ),
matur = Date.prototype.getDateFromExcel( maturity ),
iss = Date.prototype.getDateFromExcel( issue ),
firstCoup = Date.prototype.getDateFromExcel( first_coupon );
}
this.value = new cNumber( res );
this.value = new cNumber( oddFPrice(settl,matur,iss,firstCoup,rate,pr,redemption,frequency,basis) );
return this.value;
};
cODDFPRICE.prototype.getInfo = function () {
cODDFYIELD.prototype.getInfo = function () {
return {
name:this.name,
args:"( settlement , maturity , issue , first-coupon , rate , yld , redemption , frequency [ , [ basis ] ] )"
args:"( settlement , maturity , issue , first-coupon , rate , pr , redemption , frequency [ , [ basis ] ] )"
};
};
function cODDFYIELD() {
cBaseFunction.call( this, "ODDFYIELD" );
}
cODDFYIELD.prototype = Object.create( cBaseFunction.prototype );
};*/
function cODDLPRICE() {
// cBaseFunction.call( this, "ODDLPRICE" );
......@@ -3414,6 +3569,7 @@ function cODDLPRICE() {
this.numFormat = this.formatType.noneFormat;
}
cODDLPRICE.prototype = Object.create( cBaseFunction.prototype );
cODDLPRICE.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -3508,9 +3664,8 @@ cODDLPRICE.prototype.Calculate = function ( arg ) {
frequency = frequency.getValue();
basis = basis.getValue();
if ( settlement >= maturity || maturity <= last_interest ||
basis < 0 || basis > 4 ||
yld < 0 || rate < 0 ||
if ( maturity <= settlement || settlement <= last_interest ||
basis < 0 || basis > 4 || yld < 0 || rate < 0 ||
frequency != 1 && frequency != 2 && frequency != 4 )
return this.value = new cError( cErrorType.not_numeric );
......@@ -3553,6 +3708,7 @@ function cODDLYIELD() {
this.numFormat = this.formatType.noneFormat;
}
cODDLYIELD.prototype = Object.create( cBaseFunction.prototype );
cODDLYIELD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -3647,9 +3803,8 @@ cODDLYIELD.prototype.Calculate = function ( arg ) {
frequency = frequency.getValue();
basis = basis.getValue();
if ( settlement >= maturity || maturity <= last_interest ||
basis < 0 || basis > 4 ||
pr < 0 || rate < 0 ||
if ( maturity <= settlement || settlement <= last_interest ||
basis < 0 || basis > 4 || pr < 0 || rate < 0 ||
frequency != 1 && frequency != 2 && frequency != 4 )
return this.value = new cError( cErrorType.not_numeric );
......@@ -3696,6 +3851,7 @@ function cPMT() {
this.numFormat = this.formatType.noneFormat;
}
cPMT.prototype = Object.create( cBaseFunction.prototype );
cPMT.prototype.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pv = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
......@@ -3786,6 +3942,7 @@ function cPPMT() {
this.numFormat = this.formatType.noneFormat;
}
cPPMT.prototype = Object.create( cBaseFunction.prototype );
cPPMT.prototype.Calculate = function ( arg ) {
var rate = arg[0], per = arg[1], nper = arg[2], pv = arg[3], fv = arg[4] ? arg[4] : new cNumber( 0 ), type = arg[5] ? arg[5] : new cNumber( 0 );
......@@ -3890,6 +4047,7 @@ function cPRICE() {
this.numFormat = this.formatType.noneFormat;
}
cPRICE.prototype = Object.create( cBaseFunction.prototype );
cPRICE.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4009,6 +4167,7 @@ function cPRICEDISC() {
this.numFormat = this.formatType.noneFormat;
}
cPRICEDISC.prototype = Object.create( cBaseFunction.prototype );
cPRICEDISC.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4106,6 +4265,7 @@ function cPRICEMAT() {
this.numFormat = this.formatType.noneFormat;
}
cPRICEMAT.prototype = Object.create( cBaseFunction.prototype );
cPRICEMAT.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4225,6 +4385,7 @@ function cPV() {
this.numFormat = this.formatType.noneFormat;
}
cPV.prototype = Object.create( cBaseFunction.prototype );
cPV.prototype.Calculate = function ( arg ) {
var rate = arg[0], nper = arg[1], pmt = arg[2], fv = arg[3] ? arg[3] : new cNumber( 0 ), type = arg[4] ? arg[4] : new cNumber( 0 );
......@@ -4311,6 +4472,7 @@ function cRATE() {
this.numFormat = this.formatType.noneFormat;
}
cRATE.prototype = Object.create( cBaseFunction.prototype );
cRATE.prototype.Calculate = function ( arg ) {
......@@ -4374,13 +4536,7 @@ cRATE.prototype.Calculate = function ( arg ) {
if ( type.getValue() != 1 && type.getValue() != 0 ) return this.value = new cError( cErrorType.not_numeric );
var guess = {fGuess:quess.getValue()};
var bValid = RateIteration( nper.getValue(), pmt.getValue(), pv.getValue(), fv.getValue(), type.getValue(), guess );
if ( !bValid )
return this.value = new cError( cErrorType.wrong_value_type );
this.value = new cNumber( guess.fGuess );
this.value = new cNumber( RateIteration( nper.getValue(), pmt.getValue(), pv.getValue(), fv.getValue(), type.getValue(), quess.getValue() ) );
this.value.numFormat = 9;
return this.value;
};
......@@ -4407,6 +4563,7 @@ function cRECEIVED() {
this.numFormat = this.formatType.noneFormat;
}
cRECEIVED.prototype = Object.create( cBaseFunction.prototype );
cRECEIVED.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4495,6 +4652,7 @@ function cSLN() {
this.numFormat = this.formatType.noneFormat;
}
cSLN.prototype = Object.create( cBaseFunction.prototype );
cSLN.prototype.Calculate = function ( arg ) {
var cost = arg[0],
......@@ -4564,6 +4722,7 @@ function cSYD() {
this.numFormat = this.formatType.noneFormat;
}
cSYD.prototype = Object.create( cBaseFunction.prototype );
cSYD.prototype.Calculate = function ( arg ) {
var cost = arg[0], salvage = arg[1], life = arg[2], per = arg[3];
......@@ -4644,6 +4803,7 @@ function cTBILLEQ() {
this.numFormat = this.formatType.noneFormat;
}
cTBILLEQ.prototype = Object.create( cBaseFunction.prototype );
cTBILLEQ.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4722,6 +4882,7 @@ function cTBILLPRICE() {
this.numFormat = this.formatType.noneFormat;
}
cTBILLPRICE.prototype = Object.create( cBaseFunction.prototype );
cTBILLPRICE.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4801,6 +4962,7 @@ function cTBILLYIELD() {
this.numFormat = this.formatType.noneFormat;
}
cTBILLYIELD.prototype = Object.create( cBaseFunction.prototype );
cTBILLYIELD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -4878,6 +5040,7 @@ function cVDB() {
this.numFormat = this.formatType.noneFormat;
}
cVDB.prototype = Object.create( cBaseFunction.prototype );
cVDB.prototype.Calculate = function ( arg ) {
var cost = arg[0], salvage = arg[1], life = arg[2],
......@@ -5054,6 +5217,7 @@ function cXIRR() {
this.numFormat = this.formatType.noneFormat;
}
cXIRR.prototype = Object.create( cBaseFunction.prototype );
cXIRR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber( 0.1 );
......@@ -5222,6 +5386,7 @@ function cXNPV() {
this.numFormat = this.formatType.noneFormat;
}
cXNPV.prototype = Object.create( cBaseFunction.prototype );
cXNPV.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
......@@ -5342,6 +5507,7 @@ function cYIELD() {
this.numFormat = this.formatType.noneFormat;
}
cYIELD.prototype = Object.create( cBaseFunction.prototype );
cYIELD.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -5463,6 +5629,7 @@ function cYIELDDISC() {
this.numFormat = this.formatType.noneFormat;
}
cYIELDDISC.prototype = Object.create( cBaseFunction.prototype );
cYIELDDISC.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -5563,6 +5730,7 @@ function cYIELDMAT() {
this.numFormat = this.formatType.noneFormat;
}
cYIELDMAT.prototype = Object.create( cBaseFunction.prototype );
cYIELDMAT.prototype.Calculate = function ( arg ) {
var settlement = arg[0],
......@@ -5656,4 +5824,5 @@ cYIELDMAT.prototype.getInfo = function () {
name:this.name,
args:"( settlement , maturity , issue , rate , pr [ , [ basis ] ] )"
};
};
\ No newline at end of file
};
......@@ -7,7 +7,8 @@
* Time: 15:21
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Information = {
cFormulaFunction.Information = {
'groupName':"Information",
'ERROR.TYPE':cERROR_TYPE,
'ISBLANK':cISBLANK,
......@@ -54,6 +55,7 @@ function cERROR_TYPE() {
this.numFormat = this.formatType.def;
}
cERROR_TYPE.prototype = Object.create( cBaseFunction.prototype );
cERROR_TYPE.prototype.Calculate = function ( arg ) {
function typeError( elem ) {
......@@ -127,6 +129,7 @@ function cISBLANK() {
this.numFormat = this.formatType.def;
}
cISBLANK.prototype = Object.create( cBaseFunction.prototype );
cISBLANK.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -166,6 +169,7 @@ function cISERR() {
this.numFormat = this.formatType.def;
}
cISERR.prototype = Object.create( cBaseFunction.prototype );
cISERR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -209,6 +213,7 @@ function cISERROR() {
this.numFormat = this.formatType.def;
}
cISERROR.prototype = Object.create( cBaseFunction.prototype );
cISERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -252,6 +257,7 @@ function cISEVEN() {
this.numFormat = this.formatType.def;
}
cISEVEN.prototype = Object.create( cBaseFunction.prototype );
cISEVEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -299,6 +305,7 @@ function cISLOGICAL() {
this.numFormat = this.formatType.def;
}
cISLOGICAL.prototype = Object.create( cBaseFunction.prototype );
cISLOGICAL.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -341,6 +348,7 @@ function cISNA() {
this.numFormat = this.formatType.def;
}
cISNA.prototype = Object.create( cBaseFunction.prototype );
cISNA.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -384,6 +392,7 @@ function cISNONTEXT() {
this.numFormat = this.formatType.def;
}
cISNONTEXT.prototype = Object.create( cBaseFunction.prototype );
cISNONTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -426,6 +435,7 @@ function cISNUMBER() {
this.numFormat = this.formatType.def;
}
cISNUMBER.prototype = Object.create( cBaseFunction.prototype );
cISNUMBER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -469,6 +479,7 @@ function cISODD() {
this.numFormat = this.formatType.def;
}
cISODD.prototype = Object.create( cBaseFunction.prototype );
cISODD.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -516,6 +527,7 @@ function cISREF() {
this.numFormat = this.formatType.def;
}
cISREF.prototype = Object.create( cBaseFunction.prototype );
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() )
......@@ -547,6 +559,7 @@ function cISTEXT() {
this.numFormat = this.formatType.def;
}
cISTEXT.prototype = Object.create( cBaseFunction.prototype );
cISTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -591,6 +604,7 @@ function cN() {
this.numFormat = this.formatType.noneFormat;
}
cN.prototype = Object.create( cBaseFunction.prototype );
cN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -646,6 +660,7 @@ function cNA() {
this.numFormat = this.formatType.def;
}
cNA.prototype = Object.create( cBaseFunction.prototype );
cNA.prototype.Calculate = function () {
return this.value = new cError( cErrorType.not_available );
......@@ -675,6 +690,7 @@ function cTYPE() {
this.numFormat = this.formatType.def;
}
cTYPE.prototype = Object.create( cBaseFunction.prototype );
cTYPE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......
......@@ -7,7 +7,8 @@
* Time: 15:22
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Logical = {
cFormulaFunction.Logical = {
'groupName':"Logical",
'AND':cAND,
'FALSE':cFALSE,
......@@ -36,6 +37,7 @@ function cAND() {
this.numFormat = this.formatType.def;
}
cAND.prototype = Object.create( cBaseFunction.prototype );
cAND.prototype.Calculate = function ( arg ) {
var argResult = null;
......@@ -130,6 +132,7 @@ function cFALSE() {
};
this.numFormat = this.formatType.def;
}
cFALSE.prototype = Object.create( cBaseFunction.prototype );
cFALSE.prototype.Calculate = function () {
return this.value = new cBool( false );
......@@ -159,6 +162,7 @@ function cIF() {
// this.setArgumentsMin( 1 );
// this.setArgumentsMax( 3 );
}
cIF.prototype = Object.create( cBaseFunction.prototype );
cIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
......@@ -222,6 +226,7 @@ function cIFERROR() {
this.numFormat = this.formatType.def;
}
cIFERROR.prototype = Object.create( cBaseFunction.prototype );
cIFERROR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -267,6 +272,7 @@ function cNOT() {
this.numFormat = this.formatType.def;
}
cNOT.prototype = Object.create( cBaseFunction.prototype );
cNOT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -319,6 +325,7 @@ function cOR() {
this.numFormat = this.formatType.def;
}
cOR.prototype = Object.create( cBaseFunction.prototype );
cOR.prototype.Calculate = function ( arg ) {
var argResult = null;
......@@ -407,6 +414,7 @@ function cTRUE() {
this.numFormat = this.formatType.def;
}
cTRUE.prototype = Object.create( cBaseFunction.prototype );
cTRUE.prototype.Calculate = function () {
return this.value = new cBool( true );
......
......@@ -7,7 +7,8 @@
* Time: 15:21
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.LookupAndReference = {
cFormulaFunction.LookupAndReference = {
'groupName':"LookupAndReference",
'ADDRESS':cADDRESS,
'AREAS':cAREAS,
......@@ -47,6 +48,7 @@ function cADDRESS() {
this.numFormat = this.formatType.def;
}
cADDRESS.prototype = Object.create( cBaseFunction.prototype )
cADDRESS.prototype.Calculate = function ( arg ) {
......@@ -147,6 +149,7 @@ cADDRESS.prototype.getInfo = function () {
function cAREAS() {
cBaseFunction.call( this, "AREAS" );
}
cAREAS.prototype = Object.create( cBaseFunction.prototype )
function cCHOOSE() {
......@@ -167,6 +170,7 @@ function cCHOOSE() {
this.numFormat = this.formatType.def;
}
cCHOOSE.prototype = Object.create( cBaseFunction.prototype )
cCHOOSE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -215,6 +219,7 @@ function cCOLUMN() {
this.numFormat = this.formatType.def;
}
cCOLUMN.prototype = Object.create( cBaseFunction.prototype )
cCOLUMN.prototype.Calculate = function ( arg ) {
var arg0;
......@@ -267,6 +272,7 @@ function cCOLUMNS() {
this.numFormat = this.formatType.def;
}
cCOLUMNS.prototype = Object.create( cBaseFunction.prototype )
cCOLUMNS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -297,9 +303,10 @@ cCOLUMNS.prototype.getInfo = function () {
function cGETPIVOTDATA() {
cBaseFunction.call( this, "GETPIVOTDATA" );
}
cGETPIVOTDATA.prototype = Object.create( cBaseFunction.prototype )
var g_oHLOOKUPCache = new VHLOOKUPCache(true);
var g_oHLOOKUPCache = new VHLOOKUPCache( true );
function cHLOOKUP() {
// cBaseFunction.call( this, "HLOOKUP" );
......@@ -319,6 +326,7 @@ function cHLOOKUP() {
this.numFormat = this.formatType.def;
}
cHLOOKUP.prototype = Object.create( cBaseFunction.prototype )
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 );
......@@ -347,10 +355,9 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
bb = range.getBBox0();
if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache)
{
var oSearchRange = ws.getRange3( bb.r1, bb.c1, bb.r1, bb.c2 );
var oCache = g_oHLOOKUPCache.get( oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value );
if ( oCache ) {
resC = oCache.index;
min = oCache.min;
}
......@@ -362,10 +369,9 @@ cHLOOKUP.prototype.Calculate = function ( arg ) {
if ( numberRow > bb.r2 - bb.r1 )
return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r1, bb.c2);
var oCache = g_oHLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache)
{
var oSearchRange = ws.getRange3( bb.r1, bb.c1, bb.r1, bb.c2 );
var oCache = g_oHLOOKUPCache.get( oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value );
if ( oCache ) {
resC = oCache.index;
min = oCache.min;
}
......@@ -443,6 +449,7 @@ cHLOOKUP.prototype.getInfo = function () {
function cHYPERLINK() {
cBaseFunction.call( this, "HYPERLINK" );
}
cHYPERLINK.prototype = Object.create( cBaseFunction.prototype )
function cINDEX() {
......@@ -461,18 +468,19 @@ function cINDEX() {
this.numFormat = this.formatType.def;
}
cINDEX.prototype = Object.create( cBaseFunction.prototype )
cINDEX.prototype.Calculate = function ( arg ) {
var arg0 = arg[0],
arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : 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),
arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : 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 ),
isArrayForm = false, res;
if( arg0 instanceof cArea3D ){
if ( arg0 instanceof cArea3D ) {
return this.value = new cError( cErrorType.not_available );
}
else if( arg0 instanceof cError ){
else if ( arg0 instanceof cError ) {
return this.value = arg0;
}
......@@ -480,27 +488,29 @@ cINDEX.prototype.Calculate = function ( arg ) {
arg2 = arg2.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 );
}
if( arg1.getValue() < 0 || arg2.getValue() < 0 ){
if ( arg1.getValue() < 0 || arg2.getValue() < 0 ) {
return this.value = new cError( cErrorType.wrong_value_type );
}
if( arg0 instanceof cArray ){
if ( arg0 instanceof cArray ) {
arg0 = arg0.getMatrix();
}
else if( arg0 instanceof cArea ){
else if ( arg0 instanceof cArea ) {
arg0 = arg0.getMatrix();
}
else{
arg0 = [[arg0.tryConvert()]]
else {
arg0 = [
[arg0.tryConvert()]
]
}
res = arg0[arg1.getValue()-1];
if( res )
res = res[arg2.getValue()-1];
res = arg0[arg1.getValue() - 1];
if ( res )
res = res[arg2.getValue() - 1];
return this.value = res ? res : new cError( cErrorType.bad_reference );
......@@ -508,7 +518,7 @@ cINDEX.prototype.Calculate = function ( arg ) {
cINDEX.prototype.getInfo = function () {
return {
name:this.name,
args:"( array , [ row-number ] [ , [ column-number ] ] ) "+this.name+"( reference , [ row-number ] [ , [ column-number ] [ , [ area-number ] ] ] )"
args:"( array , [ row-number ] [ , [ column-number ] ] ) " + this.name + "( reference , [ row-number ] [ , [ column-number ] [ , [ area-number ] ] ] )"
};
}
......@@ -530,6 +540,7 @@ function cINDIRECT() {
this.numFormat = this.formatType.def;
}
cINDIRECT.prototype = Object.create( cBaseFunction.prototype )
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;
......@@ -639,6 +650,7 @@ function cLOOKUP() {
this.numFormat = this.formatType.def;
}
cLOOKUP.prototype = Object.create( cBaseFunction.prototype )
cLOOKUP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.argumentsCurrent == 2 ? arg1 : arg[2],
......@@ -786,65 +798,66 @@ function cMATCH() {
};
this.numFormat = this.formatType.def;
}
cMATCH.prototype = Object.create( cBaseFunction.prototype )
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,
a0Value = a0.getValue(), a2Value = a2.getValue(),
arr = [], res = new cError( cErrorType.not_available ),
index = -1;
if( a1RowCount > 1 && a1ColumnCount > 1 ){
if ( a1RowCount > 1 && a1ColumnCount > 1 ) {
return new cError( cErrorType.not_available );
}
else if( a1RowCount == 1 && a1ColumnCount > 1 ){
for(var i = 0; i < a1ColumnCount; i++){
else if ( a1RowCount == 1 && a1ColumnCount > 1 ) {
for ( var i = 0; i < a1ColumnCount; i++ ) {
arr[i] = a1[0][i].getValue();
}
}
else if( a1RowCount > 1 && a1ColumnCount == 1 ){
for(var i = 0; i < a1RowCount; i++){
else if ( a1RowCount > 1 && a1ColumnCount == 1 ) {
for ( var i = 0; i < a1RowCount; i++ ) {
arr[i] = a1[i][0].getValue();
}
}
else {
arr[0]=a1[0][0];
arr[0] = a1[0][0];
}
if( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ){
if ( !(a2Value == 1 || a2Value == 0 || a2Value == -1) ) {
return new cError( cErrorType.not_numeric );
}
if( a2Value == -1 ){
for(var i = 0; i<arr.length; i++){
if( arr[i] >= a0Value ){
if ( a2Value == -1 ) {
for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] >= a0Value ) {
index = i;
}
else
break;
}
}
else if( a2Value == 0 ){
if( a0 instanceof cString ){
for(var i = 0; i<arr.length; i++){
if( searchRegExp2(arr[i].toString(),a0Value) ){
else if ( a2Value == 0 ) {
if ( a0 instanceof cString ) {
for ( var i = 0; i < arr.length; i++ ) {
if ( searchRegExp2( arr[i].toString(), a0Value ) ) {
index = i;
}
}
}
else{
for(var i = 0; i<arr.length; i++){
if( arr[i] == a0Value ){
else {
for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] == a0Value ) {
index = i;
}
}
}
}
else if( a2Value == 1 ){
for(var i = 0; i<arr.length; i++){
if( arr[i] <= a0Value ){
else if ( a2Value == 1 ) {
for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] <= a0Value ) {
index = i;
}
else
......@@ -852,41 +865,41 @@ cMATCH.prototype.Calculate = function ( arg ) {
}
}
if( index > -1 )
res = new cNumber(index+1);
if ( index > -1 )
res = new cNumber( index + 1 );
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 );
}
else if( arg0 instanceof cError ){
else if ( arg0 instanceof cError ) {
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 );
}
else {
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;
}
else{
else {
return this.value = new cError( cErrorType.not_available );
}
return this.value = findMatch(arg0,arg1,arg2)
return this.value = findMatch( arg0, arg1, arg2 )
}
cMATCH.prototype.getInfo = function () {
......@@ -912,19 +925,20 @@ function cOFFSET() {
this.numFormat = this.formatType.def;
}
cOFFSET.prototype = Object.create( cBaseFunction.prototype )
/* 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){}
}
cOFFSET.prototype.getInfo = function () {
return {
name:this.name,
args:"( reference , rows , cols [ , [ height ] [ , [ width ] ] ] )"
};
} */
}
cOFFSET.prototype.getInfo = function () {
return {
name:this.name,
args:"( reference , rows , cols [ , [ height ] [ , [ width ] ] ] )"
};
} */
function cROW() {
// cBaseFunction.call( this, "ROW" );
......@@ -944,6 +958,7 @@ function cROW() {
this.numFormat = this.formatType.def;
}
cROW.prototype = Object.create( cBaseFunction.prototype )
cROW.prototype.Calculate = function ( arg ) {
var arg0;
......@@ -996,6 +1011,7 @@ function cROWS() {
this.numFormat = this.formatType.def;
}
cROWS.prototype = Object.create( cBaseFunction.prototype )
cROWS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1026,6 +1042,7 @@ cROWS.prototype.getInfo = function () {
function cRTD() {
cBaseFunction.call( this, "RTD" );
}
cRTD.prototype = Object.create( cBaseFunction.prototype )
function cTRANSPOSE() {
......@@ -1044,6 +1061,7 @@ function cTRANSPOSE() {
this.numFormat = this.formatType.noneFormat;
}
cTRANSPOSE.prototype = Object.create( cBaseFunction.prototype )
cTRANSPOSE.prototype.Calculate = function ( arg ) {
......@@ -1053,7 +1071,7 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
for ( var i = 0; i < A.length; i++ ) {
for ( var j = 0; j < A[i].length; j++ ) {
if(!tMatrix[j]) tMatrix[j] = [];
if ( !tMatrix[j] ) tMatrix[j] = [];
tMatrix[j][i] = A[i][j];
}
}
......@@ -1067,10 +1085,10 @@ cTRANSPOSE.prototype.Calculate = function ( arg ) {
if ( arg0 instanceof cArea || arg0 instanceof cArray ) {
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();
}
else if( arg0 instanceof cError ){
else if ( arg0 instanceof cError ) {
return this.value = arg0;
}
else
......@@ -1086,49 +1104,46 @@ cTRANSPOSE.prototype.getInfo = function () {
};
}
function VHLOOKUPCache(bHor){
function VHLOOKUPCache( bHor ) {
this.cacheId = {};
this.cacheRanges = {};
this.bHor = bHor;
this.cacheRanges = {};
this.bHor = bHor;
}
VHLOOKUPCache.prototype.get = function(range, valueForSearching, isValueString, arg3Value){
VHLOOKUPCache.prototype.get = function ( range, valueForSearching, isValueString, arg3Value ) {
var res = null;
var _this = this;
var wsId = range.getWorksheet().getId();
var _this = this;
var wsId = range.getWorksheet().getId();
var sRangeName = wsId + cCharDelimiter + range.getName();
var cacheElem = this.cacheId[sRangeName];
if(null == cacheElem)
{
cacheElem = {id: sRangeName, foreachArray: [], results: {}};
range._foreachNoEmpty( /*func for cell in col*/ function(cell, r, c, r1, c1){
if ( null == cacheElem ) {
cacheElem = {id:sRangeName, foreachArray:[], results:{}};
range._foreachNoEmpty( /*func for cell in col*/ function ( cell, r, c, r1, c1 ) {
var cv = cell.getValueWithoutFormat();
if(_this.bHor)
cacheElem.foreachArray.push({cv: cv, cvType: checkTypeCell( cv ), index: c, indexStart: c1});
else
cacheElem.foreachArray.push({cv: cv, cvType: checkTypeCell( cv ), index: r, indexStart: r1});
});
if ( _this.bHor )
cacheElem.foreachArray.push( {cv:cv, cvType:checkTypeCell( cv ), index:c, indexStart:c1} );
else
cacheElem.foreachArray.push( {cv:cv, cvType:checkTypeCell( cv ), index:r, indexStart:r1} );
} );
this.cacheId[sRangeName] = cacheElem;
var cacheRange = this.cacheRanges[wsId];
if(null == cacheRange)
{
cacheRange = new RangeDataManager(null);
this.cacheRanges[wsId] = cacheRange;
}
cacheRange.add(range.getBBox0(), cacheElem);
var cacheRange = this.cacheRanges[wsId];
if ( null == cacheRange ) {
cacheRange = new RangeDataManager( null );
this.cacheRanges[wsId] = cacheRange;
}
cacheRange.add( range.getBBox0(), cacheElem );
}
var sInputKey = valueForSearching + cCharDelimiter + isValueString + cCharDelimiter + arg3Value;
res = cacheElem.results[sInputKey];
if(null == res)
{
res = this._calculate(cacheElem.foreachArray, valueForSearching, isValueString, arg3Value);
if ( null == res ) {
res = this._calculate( cacheElem.foreachArray, valueForSearching, isValueString, arg3Value );
cacheElem.results[sInputKey] = res;
}
return res;
};
VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isValueString, arg3Value){
var res = {min: undefined, index: -1}, found = false, regexp = null;
for(var i = 0, length = cacheArray.length; i < length; i++)
{
VHLOOKUPCache.prototype._calculate = function ( cacheArray, valueForSearching, isValueString, arg3Value ) {
var res = {min:undefined, index:-1}, found = false, regexp = null;
for ( var i = 0, length = cacheArray.length; i < length; i++ ) {
var cache = cacheArray[i];
var cv = cache.cv;
var index = cache.index;
......@@ -1161,7 +1176,7 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV
}
else {
if ( isValueString ) {
if(null == regexp)
if ( null == regexp )
regexp = searchRegExp( valueForSearching );
if ( regexp.test( cv ) )
res.index = index;
......@@ -1173,24 +1188,22 @@ VHLOOKUPCache.prototype._calculate = function(cacheArray, valueForSearching, isV
}
return res;
};
VHLOOKUPCache.prototype.remove = function(cell){
var wsId = cell.ws.getId();
var cacheRange = this.cacheRanges[wsId];
if(null != cacheRange)
{
var oGetRes = cacheRange.get(new Asc.Range(cell.oId.getCol0(), cell.oId.getRow0(), cell.oId.getCol0(), cell.oId.getRow0()));
for(var i = 0, length = oGetRes.all.length; i < length; ++i)
{
var elem = oGetRes.all[i];
elem.data.results = {};
}
}
VHLOOKUPCache.prototype.remove = function ( cell ) {
var wsId = cell.ws.getId();
var cacheRange = this.cacheRanges[wsId];
if ( null != cacheRange ) {
var oGetRes = cacheRange.get( new Asc.Range( cell.oId.getCol0(), cell.oId.getRow0(), cell.oId.getCol0(), cell.oId.getRow0() ) );
for ( var i = 0, length = oGetRes.all.length; i < length; ++i ) {
var elem = oGetRes.all[i];
elem.data.results = {};
}
}
};
VHLOOKUPCache.prototype.clean = function(){
VHLOOKUPCache.prototype.clean = function () {
this.cacheId = {};
this.cacheRanges = {};
this.cacheRanges = {};
};
var g_oVLOOKUPCache = new VHLOOKUPCache(false);
var g_oVLOOKUPCache = new VHLOOKUPCache( false );
function cVLOOKUP() {
// cBaseFunction.call( this, "VLOOKUP" );
......@@ -1210,6 +1223,7 @@ function cVLOOKUP() {
// this.setArgumentsMin( 3 );
// this.setArgumentsMax( 4 );
}
cVLOOKUP.prototype = Object.create( cBaseFunction.prototype )
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 );
......@@ -1241,10 +1255,9 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
bb = range.getBBox0();
if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache)
{
var oSearchRange = ws.getRange3( bb.r1, bb.c1, bb.r2, bb.c1 );
var oCache = g_oVLOOKUPCache.get( oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value );
if ( oCache ) {
resR = oCache.index;
min = oCache.min;
}
......@@ -1255,10 +1268,9 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
if ( numberCol > bb.c2 - bb.c1 )
return this.value = new cError( cErrorType.bad_reference );
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache)
{
var oSearchRange = ws.getRange3( bb.r1, bb.c1, bb.r2, bb.c1 );
var oCache = g_oVLOOKUPCache.get( oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value );
if ( oCache ) {
resR = oCache.index;
min = oCache.min;
}
......@@ -1354,17 +1366,16 @@ cVLOOKUP.prototype.Calculate = function ( arg ) {
}
}*/
var oSearchRange = ws.getRange3(bb.r1, bb.c1, bb.r2, bb.c1);
var oCache = g_oVLOOKUPCache.get(oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value);
if(oCache)
{
var oSearchRange = ws.getRange3( bb.r1, bb.c1, bb.r2, bb.c1 );
var oCache = g_oVLOOKUPCache.get( oSearchRange, valueForSearching, arg0 instanceof cString, arg3.value );
if ( oCache ) {
resR = oCache.index;
min = oCache.min;
}
}
else if ( arg1 instanceof cArray ) {
if(arg0 instanceof cString)
if ( arg0 instanceof cString )
regexp = searchRegExp( valueForSearching );
arg1.foreach( function ( elem, r, c ) {
if ( r == 0 )
......
......@@ -7,7 +7,7 @@
* Time: 15:20
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Mathematic = {
cFormulaFunction.Mathematic = {
'groupName':"Mathematic",
'ABS':cABS,
'ACOS':cACOS,
......@@ -91,6 +91,7 @@ function cABS() {
this.numFormat = this.formatType.def;
}
cABS.prototype = Object.create( cBaseFunction.prototype )
cABS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -140,6 +141,7 @@ function cACOS() {
this.numFormat = this.formatType.def;
}
cACOS.prototype = Object.create( cBaseFunction.prototype )
cACOS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -191,6 +193,7 @@ function cACOSH() {
this.numFormat = this.formatType.def;
}
cACOSH.prototype = Object.create( cBaseFunction.prototype )
cACOSH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -242,6 +245,7 @@ function cASIN() {
this.numFormat = this.formatType.def;
}
cASIN.prototype = Object.create( cBaseFunction.prototype )
cASIN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -293,6 +297,7 @@ function cASINH() {
this.numFormat = this.formatType.def;
}
cASINH.prototype = Object.create( cBaseFunction.prototype )
cASINH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -344,6 +349,7 @@ function cATAN() {
this.numFormat = this.formatType.def;
}
cATAN.prototype = Object.create( cBaseFunction.prototype )
cATAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -396,6 +402,7 @@ function cATAN2() {
this.numFormat = this.formatType.def;
}
cATAN2.prototype = Object.create( cBaseFunction.prototype )
cATAN2.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -489,6 +496,7 @@ function cATANH() {
this.numFormat = this.formatType.def;
}
cATANH.prototype = Object.create( cBaseFunction.prototype )
cATANH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -540,6 +548,7 @@ function cCEILING() {
this.numFormat = this.formatType.def;
}
cCEILING.prototype = Object.create( cBaseFunction.prototype )
cCEILING.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -647,6 +656,7 @@ function cCOMBIN() {
this.numFormat = this.formatType.def;
}
cCOMBIN.prototype = Object.create( cBaseFunction.prototype )
cCOMBIN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -743,6 +753,7 @@ function cCOS() {
this.numFormat = this.formatType.def;
}
cCOS.prototype = Object.create( cBaseFunction.prototype )
cCOS.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -794,6 +805,7 @@ function cCOSH() {
this.numFormat = this.formatType.def;
}
cCOSH.prototype = Object.create( cBaseFunction.prototype )
cCOSH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -845,6 +857,7 @@ function cDEGREES() {
this.numFormat = this.formatType.def;
}
cDEGREES.prototype = Object.create( cBaseFunction.prototype )
cDEGREES.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -882,6 +895,7 @@ cDEGREES.prototype.getInfo = function () {
function cECMA_CEILING() {
cBaseFunction.call( this, "ECMA_CEILING" );
}
cECMA_CEILING.prototype = Object.create( cBaseFunction.prototype )
function cEVEN() {
......@@ -902,6 +916,7 @@ function cEVEN() {
this.numFormat = this.formatType.def;
}
cEVEN.prototype = Object.create( cBaseFunction.prototype )
cEVEN.prototype.Calculate = function ( arg ) {
......@@ -974,6 +989,7 @@ function cEXP() {
this.numFormat = this.formatType.def;
}
cEXP.prototype = Object.create( cBaseFunction.prototype )
cEXP.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1028,6 +1044,7 @@ function cFACT() {
this.numFormat = this.formatType.def;
}
cFACT.prototype = Object.create( cBaseFunction.prototype )
cFACT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1084,6 +1101,7 @@ function cFACTDOUBLE() {
this.numFormat = this.formatType.def;
}
cFACTDOUBLE.prototype = Object.create( cBaseFunction.prototype )
cFACTDOUBLE.prototype.Calculate = function ( arg ) {
function factDouble( n ) {
......@@ -1154,6 +1172,7 @@ function cFLOOR() {
this.numFormat = this.formatType.def;
}
cFLOOR.prototype = Object.create( cBaseFunction.prototype )
cFLOOR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -1260,6 +1279,7 @@ function cGCD() {
this.numFormat = this.formatType.def;
}
cGCD.prototype = Object.create( cBaseFunction.prototype )
cGCD.prototype.Calculate = function ( arg ) {
......@@ -1363,6 +1383,7 @@ function cINT() {
this.numFormat = this.formatType.def;
}
cINT.prototype = Object.create( cBaseFunction.prototype )
cINT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1399,6 +1420,7 @@ cINT.prototype.getInfo = function () {
function cISO_CEILING() {
cBaseFunction.call( this, "ISO_CEILING" );
}
cISO_CEILING.prototype = Object.create( cBaseFunction.prototype )
function cLCM() {
......@@ -1419,6 +1441,7 @@ function cLCM() {
this.numFormat = this.formatType.def;
}
cLCM.prototype = Object.create( cBaseFunction.prototype )
cLCM.prototype.Calculate = function ( arg ) {
......@@ -1526,6 +1549,7 @@ function cLN() {
this.numFormat = this.formatType.def;
}
cLN.prototype = Object.create( cBaseFunction.prototype )
cLN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1582,6 +1606,7 @@ function cLOG() {
this.numFormat = this.formatType.def;
}
cLOG.prototype = Object.create( cBaseFunction.prototype )
cLOG.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1] ? arg[1] : new cNumber( 10 );
......@@ -1681,6 +1706,7 @@ function cLOG10() {
this.numFormat = this.formatType.def;
}
cLOG10.prototype = Object.create( cBaseFunction.prototype )
cLOG10.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1738,6 +1764,7 @@ function cMDETERM() {
this.numFormat = this.formatType.noneFormat;
}
cMDETERM.prototype = Object.create( cBaseFunction.prototype )
cMDETERM.prototype.Calculate = function ( arg ) {
......@@ -1828,6 +1855,7 @@ function cMINVERSE() {
this.numFormat = this.formatType.noneFormat;
}
cMINVERSE.prototype = Object.create( cBaseFunction.prototype )
cMINVERSE.prototype.Calculate = function ( arg ) {
......@@ -1971,6 +1999,7 @@ function cMMULT() {
this.numFormat = this.formatType.noneFormat;
}
cMMULT.prototype = Object.create( cBaseFunction.prototype )
cMMULT.prototype.Calculate = function ( arg ) {
......@@ -2048,6 +2077,7 @@ function cMOD() {
this.numFormat = this.formatType.def;
}
cMOD.prototype = Object.create( cBaseFunction.prototype )
cMOD.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -2140,6 +2170,7 @@ function cMROUND() {
this.numFormat = this.formatType.def;
}
cMROUND.prototype = Object.create( cBaseFunction.prototype )
cMROUND.prototype.Calculate = function ( arg ) {
......@@ -2250,6 +2281,7 @@ function cMULTINOMIAL() {
this.numFormat = this.formatType.def;
}
cMULTINOMIAL.prototype = Object.create( cBaseFunction.prototype )
cMULTINOMIAL.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 ), fact = 1;
......@@ -2354,6 +2386,7 @@ function cODD() {
this.numFormat = this.formatType.def;
}
cODD.prototype = Object.create( cBaseFunction.prototype )
cODD.prototype.Calculate = function ( arg ) {
......@@ -2426,6 +2459,7 @@ function cPI() {
this.numFormat = this.formatType.def;
}
cPI.prototype = Object.create( cBaseFunction.prototype )
cPI.prototype.Calculate = function () {
return new cNumber( Math.PI );
......@@ -2455,6 +2489,7 @@ function cPOWER() {
this.numFormat = this.formatType.def;
}
cPOWER.prototype = Object.create( cBaseFunction.prototype )
cPOWER.prototype.Calculate = function ( arg ) {
......@@ -2543,6 +2578,7 @@ function cPRODUCT() {
this.numFormat = this.formatType.def;
}
cPRODUCT.prototype = Object.create( cBaseFunction.prototype )
cPRODUCT.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 1 ), _aVal = null;
......@@ -2602,6 +2638,7 @@ function cQUOTIENT() {
this.numFormat = this.formatType.def;
}
cQUOTIENT.prototype = Object.create( cBaseFunction.prototype )
cQUOTIENT.prototype.Calculate = function ( arg ) {
......@@ -2688,6 +2725,7 @@ function cRADIANS() {
this.numFormat = this.formatType.def;
}
cRADIANS.prototype = Object.create( cBaseFunction.prototype )
cRADIANS.prototype.Calculate = function ( arg ) {
......@@ -2743,6 +2781,7 @@ function cRAND() {
this.numFormat = this.formatType.def;
}
cRAND.prototype = Object.create( cBaseFunction.prototype )
cRAND.prototype.Calculate = function () {
return this.setCA( new cNumber( Math.random() ), true );
......@@ -2772,6 +2811,7 @@ function cRANDBETWEEN() {
this.numFormat = this.formatType.def;
}
cRANDBETWEEN.prototype = Object.create( cBaseFunction.prototype )
cRANDBETWEEN.prototype.Calculate = function ( arg ) {
......@@ -2855,6 +2895,7 @@ function cROMAN() {
this.numFormat = this.formatType.def;
}
cROMAN.prototype = Object.create( cBaseFunction.prototype )
cROMAN.prototype.Calculate = function ( arg ) {
function roman( num, mode ) {
......@@ -2979,6 +3020,7 @@ function cROUND() {
this.numFormat = this.formatType.def;
}
cROUND.prototype = Object.create( cBaseFunction.prototype )
cROUND.prototype.Calculate = function ( arg ) {
......@@ -3130,6 +3172,7 @@ function cROUNDDOWN() {
this.numFormat = this.formatType.def;
}
cROUNDDOWN.prototype = Object.create( cBaseFunction.prototype )
cROUNDDOWN.prototype.Calculate = function ( arg ) {
function rounddownHelper( number, num_digits ) {
......@@ -3254,6 +3297,7 @@ function cROUNDUP() {
this.numFormat = this.formatType.def;
}
cROUNDUP.prototype = Object.create( cBaseFunction.prototype )
cROUNDUP.prototype.Calculate = function ( arg ) {
function roundupHelper( number, num_digits ) {
......@@ -3378,6 +3422,7 @@ function cSERIESSUM() {
this.numFormat = this.formatType.def;
}
cSERIESSUM.prototype = Object.create( cBaseFunction.prototype )
cSERIESSUM.prototype.Calculate = function ( arg ) {
......@@ -3460,6 +3505,7 @@ function cSIGN() {
this.numFormat = this.formatType.def;
}
cSIGN.prototype = Object.create( cBaseFunction.prototype )
cSIGN.prototype.Calculate = function ( arg ) {
......@@ -3523,6 +3569,7 @@ function cSIN() {
this.numFormat = this.formatType.def;
}
cSIN.prototype = Object.create( cBaseFunction.prototype )
cSIN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -3571,6 +3618,7 @@ function cSINH() {
this.numFormat = this.formatType.def;
}
cSINH.prototype = Object.create( cBaseFunction.prototype )
cSINH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -3622,6 +3670,7 @@ function cSQRT() {
this.numFormat = this.formatType.def;
}
cSQRT.prototype = Object.create( cBaseFunction.prototype )
cSQRT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -3673,6 +3722,7 @@ function cSQRTPI() {
this.numFormat = this.formatType.def;
}
cSQRTPI.prototype = Object.create( cBaseFunction.prototype )
cSQRTPI.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -3709,6 +3759,7 @@ cSQRTPI.prototype.getInfo = function () {
function cSUBTOTAL() {
cBaseFunction.call( this, "SUBTOTAL" );
}
cSUBTOTAL.prototype = Object.create( cBaseFunction.prototype )
function cSUM() {
......@@ -3729,6 +3780,7 @@ function cSUM() {
this.numFormat = this.formatType.def;
}
cSUM.prototype = Object.create( cBaseFunction.prototype )
cSUM.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 ), _aVal = null;
......@@ -3791,6 +3843,7 @@ function cSUMIF() {
this.numFormat = this.formatType.def;
}
cSUMIF.prototype = Object.create( cBaseFunction.prototype )
cSUMIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, valueForSearching, regexpSearch;
......@@ -3864,6 +3917,7 @@ cSUMIF.prototype.getInfo = function () {
function cSUMIFS() {
cBaseFunction.call( this, "SUMIFS" );
}
cSUMIFS.prototype = Object.create( cBaseFunction.prototype )
function cSUMPRODUCT() {
......@@ -3884,6 +3938,7 @@ function cSUMPRODUCT() {
this.numFormat = this.formatType.def;
}
cSUMPRODUCT.prototype = Object.create( cBaseFunction.prototype )
cSUMPRODUCT.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 ), resArr = [], col = 0, row = 0, res = 1, _res = [];
......@@ -3968,6 +4023,7 @@ function cSUMSQ() {
this.numFormat = this.formatType.def;
}
cSUMSQ.prototype = Object.create( cBaseFunction.prototype )
cSUMSQ.prototype.Calculate = function ( arg ) {
var arg0 = new cNumber( 0 ), _aVal = null;
......@@ -4036,6 +4092,7 @@ function cSUMX2MY2() {
this.numFormat = this.formatType.def;
}
cSUMX2MY2.prototype = Object.create( cBaseFunction.prototype )
cSUMX2MY2.prototype.Calculate = function ( arg ) {
......@@ -4133,6 +4190,7 @@ function cSUMX2PY2() {
this.numFormat = this.formatType.def;
}
cSUMX2PY2.prototype = Object.create( cBaseFunction.prototype )
cSUMX2PY2.prototype.Calculate = function ( arg ) {
......@@ -4230,6 +4288,7 @@ function cSUMXMY2() {
this.numFormat = this.formatType.def;
}
cSUMXMY2.prototype = Object.create( cBaseFunction.prototype )
cSUMXMY2.prototype.Calculate = function ( arg ) {
......@@ -4327,6 +4386,7 @@ function cTAN() {
this.numFormat = this.formatType.def;
}
cTAN.prototype = Object.create( cBaseFunction.prototype )
cTAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -4378,6 +4438,7 @@ function cTANH() {
this.numFormat = this.formatType.def;
}
cTANH.prototype = Object.create( cBaseFunction.prototype )
cTANH.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -4429,6 +4490,7 @@ function cTRUNC() {
this.numFormat = this.formatType.def;
}
cTRUNC.prototype = Object.create( cBaseFunction.prototype )
cTRUNC.prototype.Calculate = function ( arg ) {
......@@ -4518,4 +4580,5 @@ cTRUNC.prototype.getInfo = function () {
name:this.name,
args:"( x [ , number-digits ] )"
};
}
\ No newline at end of file
}
"use strict";
var FormulaObjects = {};
/** @enum */
var cElementType = {
number:0,
......@@ -27,10 +26,10 @@ var cErrorType = {
not_available:7,
getting_data:8
};
var cExcelSignificantDigits = 15,//количество цифр в числе после запятой
var cExcelSignificantDigits = 15, //количество цифр в числе после запятой
cExcelMaxExponent = 308,
cExcelMinExponent = -308,
cExcelDateTimeDigits = 8,//количество цифр после запятой в числах отвечающих за время специализация $18.17.4.2
cExcelDateTimeDigits = 8, //количество цифр после запятой в числах отвечающих за время специализация $18.17.4.2
c_Date1904Const = 24107, //разница в днях между 01.01.1970 и 01.01.1904 годами
c_Date1900Const = 25568, //разница в днях между 01.01.1970 и 01.01.1900 годами
c_DateCorrectConst = c_Date1900Const,
......@@ -92,6 +91,10 @@ Date.prototype.addDays = function ( counts ) {
this.setUTCDate( this.getUTCDate() + counts );
};
Date.prototype.lastDayOfMonth = function ( ) {
return this.getDaysInMonth() == this.getUTCDate();
};
Math.sinh = function ( arg ) {
return (this.pow( this.E, arg ) - this.pow( this.E, -arg )) / 2;
};
......@@ -157,7 +160,7 @@ Math.approxEqual = function ( a, b ) {
};
/** @constructor */
FormulaObjects.cBaseType = function ( val ) {
function cBaseType( val ) {
this.needRecalc = false;
this.numFormat = null;
this.type = null;
......@@ -165,8 +168,8 @@ FormulaObjects.cBaseType = function ( val ) {
this.ca = false;
this.node = undefined;
}
FormulaObjects.cBaseType.prototype = {
constructor:FormulaObjects.cBaseType,
cBaseType.prototype = {
constructor:cBaseType,
cloneTo:function ( oRes ) {
oRes.needRecalc = this.needRecalc;
oRes.numFormat = this.numFormat;
......@@ -192,8 +195,8 @@ FormulaObjects.cBaseType.prototype = {
/*Basic types of an elements used into formulas*/
/** @constructor */
function cNumber( val ) {
// FormulaObjects.cBaseType.apply( this, arguments );
// FormulaObjects.cBaseType.call( this, val );
// cBaseType.apply( this, arguments );
// cBaseType.call( this, val );
this.needRecalc = false;
this.numFormat = null;
this.ca = false;
......@@ -206,12 +209,16 @@ function cNumber( val ) {
if ( !isNaN( this.value ) && Math.abs( this.value ) !== Infinity ) {
res = this;
}
else if( val instanceof cError ){
res = val;
}
else {
res = new cError( cErrorType.not_numeric );
}
return res;
}
cNumber.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cNumber.prototype = Object.create( cBaseType.prototype );
cNumber.prototype.getValue = function () {
return this.value;//.toFixed( cExcelSignificantDigits ) - 0;
};
......@@ -227,7 +234,7 @@ cNumber.prototype.tocBool = function () {
/** @constructor */
function cString( val ) {
// FormulaObjects.cBaseType.call( this, val );
// cBaseType.call( this, val );
this.needRecalc = false;
this.numFormat = null;
......@@ -237,7 +244,8 @@ function cString( val ) {
this.type = cElementType.string;
}
cString.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cString.prototype = Object.create( cBaseType.prototype );
cString.prototype.tocNumber = function () {
var res, m = this.value;
if ( this.value === "" ) {
......@@ -283,7 +291,7 @@ cString.prototype.tryConvert = function () {
/** @constructor */
function cBool( val ) {
FormulaObjects.cBaseType.call( this, val );
cBaseType.call( this, val );
this.needRecalc = false;
this.numFormat = null;
......@@ -294,7 +302,8 @@ function cBool( val ) {
var v = val.toString().toUpperCase();
this.value = v === "TRUE";
}
cBool.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cBool.prototype = Object.create( cBaseType.prototype );
cBool.prototype.toString = function () {
return this.value.toString().toUpperCase();
};
......@@ -316,7 +325,7 @@ cBool.prototype.toBool = function () {
/** @constructor */
function cError( val ) {
// FormulaObjects.cBaseType.call( this, val );
// cBaseType.call( this, val );
this.needRecalc = false;
this.numFormat = null;
......@@ -327,55 +336,64 @@ function cError( val ) {
this.type = cElementType.error;
this.errorType = -1;
switch(val){
switch ( val ) {
case "#VALUE!":
case cErrorType.wrong_value_type:{
case cErrorType.wrong_value_type:
{
this.value = "#VALUE!";
this.errorType = cErrorType.wrong_value_type;
break;
}
case "#NULL!":
case cErrorType.null_value:{
case cErrorType.null_value:
{
break;
}
case "#DIV/0!":
case cErrorType.division_by_zero:{
case cErrorType.division_by_zero:
{
this.value = "#DIV/0!";
this.errorType = cErrorType.division_by_zero;
break;
}
case "#REF!":
case cErrorType.bad_reference:{
case cErrorType.bad_reference:
{
this.value = "#REF!";
this.errorType = cErrorType.bad_reference;
break;
}
case "#NAME?":
case cErrorType.wrong_name:{
case cErrorType.wrong_name:
{
this.value = "#NAME?";
this.errorType = cErrorType.wrong_name;
break;
}
case "#NUM!":
case cErrorType.not_numeric:{
case cErrorType.not_numeric:
{
this.value = "#NUM!";
this.errorType = cErrorType.not_numeric;
break;
}
case "#N/A":
case cErrorType.not_available:{
case cErrorType.not_available:
{
this.value = "#N/A";
this.errorType = cErrorType.not_available;
break;
}
case "#GETTING_DATA":
case cErrorType.getting_data:{
case cErrorType.getting_data:
{
this.value = "#GETTING_DATA";
this.errorType = cErrorType.getting_data;
break;
}
case "#UNSUPPORTED_FUNCTION!":
case cErrorType.unsupported_function:{
case cErrorType.unsupported_function:
{
this.value = "#UNSUPPORTED_FUNCTION!";
this.errorType = cErrorType.unsupported_function;
break;
......@@ -385,14 +403,15 @@ function cError( val ) {
return this;
}
cError.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cError.prototype = Object.create( cBaseType.prototype );
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function () {
return this;
};
/** @constructor */
function cArea( val, ws ) {/*Area means "A1:E5" for example*/
// FormulaObjects.cBaseType.call( this, val, _ws );
// cBaseType.call( this, val, _ws );
this.needRecalc = false;
this.numFormat = null;
......@@ -408,10 +427,11 @@ function cArea( val, ws ) {/*Area means "A1:E5" for example*/
// this.range = this.wb.getWorksheetById(this.ws).getRange2(val);
// this._valid = this.range ? true : false;
}
cArea.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cArea.prototype = Object.create( cBaseType.prototype );
cArea.prototype.clone = function () {
var oRes = new cArea( this._cells, this.ws );
// FormulaObjects.cBaseType.prototype.cloneTo.call( this, oRes );
// cBaseType.prototype.cloneTo.call( this, oRes );
this.constructor.prototype.cloneTo.call( this, oRes );
oRes.isAbsolute = this.isAbsolute;
return oRes;
......@@ -630,8 +650,8 @@ cArea.prototype.getMatrix = function () {
/** @constructor */
function cRef( val, ws ) {/*Ref means A1 for example*/
// FormulaObjects.cBaseType.apply( this, arguments );
// FormulaObjects.cBaseType.call( this, val, _ws );
// cBaseType.apply( this, arguments );
// cBaseType.call( this, val, _ws );
this.needRecalc = false;
this.numFormat = null;
......@@ -654,10 +674,11 @@ function cRef( val, ws ) {/*Ref means A1 for example*/
this.range = ws.getRange3( 0, 0, 0, 0 );
}
}
cRef.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cRef.prototype = Object.create( cBaseType.prototype );
cRef.prototype.clone = function () {
var oRes = new cRef( this._cells, this.ws );
// FormulaObjects.cBaseType.prototype.cloneTo.call( this, oRes );
// cBaseType.prototype.cloneTo.call( this, oRes );
this.constructor.prototype.cloneTo.call( this, oRes );
oRes.isAbsolute = this.isAbsolute;
return oRes;
......@@ -719,7 +740,7 @@ cRef.prototype.isValid = function () {
/** @constructor */
function cArea3D( val, wsFrom, wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for example*/
// FormulaObjects.cBaseType.call( this, val, _wsFrom, _wsTo, wb );
// cBaseType.call( this, val, _wsFrom, _wsTo, wb );
this.needRecalc = false;
this.numFormat = null;
......@@ -734,12 +755,13 @@ function cArea3D( val, wsFrom, wsTo, wb ) {/*Area3D means "Sheat1!A1:E5" for exa
this.wsFrom = this._wb.getWorksheetByName( wsFrom ).getId();
this.wsTo = this._wb.getWorksheetByName( wsTo ).getId();
}
cArea3D.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cArea3D.prototype = Object.create( cBaseType.prototype );
cArea3D.prototype.clone = function () {
var wsFrom = this._wb.getWorksheetById( this.wsFrom ).getName(),
wsTo = this._wb.getWorksheetById( this.wsTo ).getName(),
oRes = new cArea3D( this._cells, wsFrom, wsTo, this._wb );
// FormulaObjects.cBaseType.prototype.cloneTo.call( this, oRes );
// cBaseType.prototype.cloneTo.call( this, oRes );
this.constructor.prototype.cloneTo.call( this, oRes );
oRes.isAbsolute = this.isAbsolute;
return oRes;
......@@ -1058,7 +1080,7 @@ cArea3D.prototype.foreach2 = function ( action ) {
/** @constructor */
function cRef3D( val, _wsFrom, wb ) {/*Ref means Sheat1!A1 for example*/
// FormulaObjects.cBaseType.call( this, val, _wsFrom, wb );
// cBaseType.call( this, val, _wsFrom, wb );
this.needRecalc = false;
this.numFormat = null;
......@@ -1072,10 +1094,11 @@ function cRef3D( val, _wsFrom, wb ) {/*Ref means Sheat1!A1 for example*/
this.type = cElementType.cell;
this.ws = this._wb.getWorksheetByName( _wsFrom );
}
cRef3D.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cRef3D.prototype = Object.create( cBaseType.prototype );
cRef3D.prototype.clone = function () {
var oRes = new cRef3D( this._cells, this.ws.getName(), this._wb );
// FormulaObjects.cBaseType.prototype.cloneTo.call( this, oRes );
// cBaseType.prototype.cloneTo.call( this, oRes );
this.constructor.prototype.cloneTo.call( this, oRes );
oRes.isAbsolute = this.isAbsolute;
return oRes;
......@@ -1154,7 +1177,7 @@ cRef3D.prototype.getWS = function () {
/** @constructor */
function cEmpty() {
// FormulaObjects.cBaseType.call( this );
// cBaseType.call( this );
this.needRecalc = false;
this.numFormat = null;
......@@ -1164,7 +1187,8 @@ function cEmpty() {
this.type = cElementType.empty;
}
cEmpty.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cEmpty.prototype = Object.create( cBaseType.prototype );
cEmpty.prototype.tocNumber = function () {
return new cNumber( 0 );
};
......@@ -1180,7 +1204,7 @@ cEmpty.prototype.toString = function () {
/** @constructor */
function cName( val, wb ) {
// FormulaObjects.cBaseType.call( this, val, wb );
// cBaseType.call( this, val, wb );
this.needRecalc = false;
this.numFormat = null;
......@@ -1191,7 +1215,8 @@ function cName( val, wb ) {
this.wb = wb;
this.type = cElementType.name;
}
cName.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cName.prototype = Object.create( cBaseType.prototype );
cName.prototype.toRef = function ( wsID ) {
var _3DRefTmp,
ref = this.wb.getDefinesNames( this.value, wsID ).Ref;
......@@ -1216,7 +1241,7 @@ cName.prototype.toRef = function ( wsID ) {
/** @constructor */
function cArray() {
// FormulaObjects.cBaseType.call( this );
// cBaseType.call( this );
this.needRecalc = false;
this.numFormat = null;
......@@ -1230,7 +1255,8 @@ function cArray() {
this.countElement = 0;
this.type = cElementType.array;
}
cArray.prototype = Object.create( FormulaObjects.cBaseType.prototype );
cArray.prototype = Object.create( cBaseType.prototype );
cArray.prototype.addRow = function () {
this.array[this.array.length] = [];
this.countElementInRow[this.rowCount++] = 0;
......@@ -1397,6 +1423,7 @@ function checkTypeCell( val ) {
return new cString( val );
}
}
/*--------------------------------------------------------------------------*/
/*Base classes for operators & functions */
/** @constructor */
......@@ -1428,6 +1455,7 @@ function cBaseOperator( name, priority, argumentCount ) {
};
this.numFormat = this.formatType.def;
}
cBaseOperator.prototype = {
constructor:cBaseOperator,
getArguments:function () {
......@@ -1465,6 +1493,7 @@ function cBaseFunction( name ) {
};
this.numFormat = this.formatType.def;
}
cBaseFunction.prototype = {
constructor:cBaseFunction,
Calculate:function () {
......@@ -1531,6 +1560,7 @@ function parentLeft() {
this.type = cElementType.operator;
this.argumentsCurrent = 1;
}
parentLeft.prototype.constructor = parentLeft;
parentLeft.prototype.DecrementArguments = function () {
--this.argumentsCurrent;
......@@ -1552,6 +1582,7 @@ function parentRight() {
this.name = ")";
this.type = cElementType.operator;
}
parentRight.prototype.constructor = parentRight;
parentRight.prototype.toString = function () {
return this.name;
......@@ -1561,6 +1592,7 @@ function cUnarMinusOperator() {
cBaseOperator.apply( this, ['un_minus'/**name operator*/, 50/**priority of operator*/, 1/**count arguments*/] );
this.isRightAssociative = true;
}
cUnarMinusOperator.prototype = Object.create( cBaseOperator.prototype );
cUnarMinusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1590,6 +1622,7 @@ function cUnarPlusOperator() {
cBaseOperator.apply( this, ['un_plus', 50, 1] );
this.isRightAssociative = true;
}
cUnarPlusOperator.prototype = Object.create( cBaseOperator.prototype );
cUnarPlusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1609,6 +1642,7 @@ cUnarPlusOperator.prototype.Assemble = function ( arg ) {
function cPlusOperator() {
cBaseOperator.apply( this, ['+', 20] );
}
cPlusOperator.prototype = Object.create( cBaseOperator.prototype );
cPlusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1618,6 +1652,7 @@ cPlusOperator.prototype.Calculate = function ( arg ) {
function cMinusOperator() {
cBaseOperator.apply( this, ['-', 20] );
}
cMinusOperator.prototype = Object.create( cBaseOperator.prototype );
cMinusOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1628,6 +1663,7 @@ function cPercentOperator() {
cBaseOperator.apply( this, ['%', 45, 1] );
this.isRightAssociative = true;
}
cPercentOperator.prototype = Object.create( cBaseOperator.prototype );
cPercentOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1655,6 +1691,7 @@ cPercentOperator.prototype.Assemble = function ( arg ) {
function cPowOperator() {
cBaseOperator.apply( this, ['^', 40] );
}
cPowOperator.prototype = Object.create( cBaseOperator.prototype );
cPowOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -1686,6 +1723,7 @@ cPowOperator.prototype.Calculate = function ( arg ) {
function cMultOperator() {
cBaseOperator.apply( this, ['*', 30] );
}
cMultOperator.prototype = Object.create( cBaseOperator.prototype );
cMultOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1695,6 +1733,7 @@ cMultOperator.prototype.Calculate = function ( arg ) {
function cDivOperator() {
cBaseOperator.apply( this, ['/', 30] );
}
cDivOperator.prototype = Object.create( cBaseOperator.prototype );
cDivOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1704,6 +1743,7 @@ cDivOperator.prototype.Calculate = function ( arg ) {
function cConcatSTROperator() {
cBaseOperator.apply( this, ['&', 15] );
}
cConcatSTROperator.prototype = Object.create( cBaseOperator.prototype );
cConcatSTROperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -1724,6 +1764,7 @@ cConcatSTROperator.prototype.Calculate = function ( arg ) {
function cEqualsOperator() {
cBaseOperator.apply( this, ['=', 10] );
}
cEqualsOperator.prototype = Object.create( cBaseOperator.prototype );
cEqualsOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1733,6 +1774,7 @@ cEqualsOperator.prototype.Calculate = function ( arg ) {
function cNotEqualsOperator() {
cBaseOperator.apply( this, ['<>', 10] );
}
cNotEqualsOperator.prototype = Object.create( cBaseOperator.prototype );
cNotEqualsOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1742,6 +1784,7 @@ cNotEqualsOperator.prototype.Calculate = function ( arg ) {
function cLessOperator() {
cBaseOperator.apply( this, ['<', 10] );
}
cLessOperator.prototype = Object.create( cBaseOperator.prototype );
cLessOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1751,6 +1794,7 @@ cLessOperator.prototype.Calculate = function ( arg ) {
function cLessOrEqualOperator() {
cBaseOperator.apply( this, ['<=', 10] );
}
cLessOrEqualOperator.prototype = Object.create( cBaseOperator.prototype );
cLessOrEqualOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1760,6 +1804,7 @@ cLessOrEqualOperator.prototype.Calculate = function ( arg ) {
function cGreaterOperator() {
cBaseOperator.apply( this, ['>', 10] );
}
cGreaterOperator.prototype = Object.create( cBaseOperator.prototype );
cGreaterOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1769,6 +1814,7 @@ cGreaterOperator.prototype.Calculate = function ( arg ) {
function cGreaterOrEqualOperator() {
cBaseOperator.apply( this, ['>=', 10] );
}
cGreaterOrEqualOperator.prototype = Object.create( cBaseOperator.prototype );
cGreaterOrEqualOperator.prototype.Calculate = function ( arg ) {
var arg0 = arg[0].tryConvert(), arg1 = arg[1].tryConvert();
......@@ -1814,7 +1860,7 @@ var cFormulaOperators = {
/* 10 is lowest priopity */
};
/* FormulaObjects.cFormulaFunction is container for holding all ECMA-376 function, see chapter $18.17.7 in "ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference" */
/* cFormulaFunction is container for holding all ECMA-376 function, see chapter $18.17.7 in "ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference" */
/*
Каждая формула представляет собой копию функции cBaseFunction.
Для реализации очередной функции необходимо указать количество (минимальное и максимальное) принимаемых аргументов. Берем в спецификации.
......@@ -1822,15 +1868,15 @@ var cFormulaOperators = {
В методе Calculate необходимо отслеживать тип принимаемых аргументов. Для примера, если мы обращаемся к ячейке A1, в которой лежит 123, то этот аргумент будет числом. Если же там лежит "123", то это уже строка. Для более подробной информации смотреть спецификацию.
Метод getInfo является обязательным, ибо через этот метод в интерфейс передается информация о реализованных функциях.
*/
FormulaObjects.cFormulaFunction = {};
var cFormulaFunction = {};
function getFormulasInfo() {
var list = [], a, b;
for ( var type in FormulaObjects.cFormulaFunction ) {
b = new Asc.asc_CFormulaGroup( FormulaObjects.cFormulaFunction[type]["groupName"] );
for ( var f in FormulaObjects.cFormulaFunction[type] ) {
for ( var type in cFormulaFunction ) {
b = new Asc.asc_CFormulaGroup( cFormulaFunction[type]["groupName"] );
for ( var f in cFormulaFunction[type] ) {
if ( f != "groupName" ) {
a = new FormulaObjects.cFormulaFunction[type][f]();
a = new cFormulaFunction[type][f]();
if ( a.getInfo )
b.asc_addFormulaElement( new Asc.asc_CFormula( a.getInfo() ) );
}
......@@ -1839,6 +1885,7 @@ function getFormulasInfo() {
}
return list;
}
/*--------------------------------------------------------------------------*/
......@@ -2976,6 +3023,7 @@ function parserFormula( formula, _cellId, _ws ) {
this.RefPos = [];
this.operand_str = null;
}
parserFormula.prototype = {
/** @type parserFormula */
......@@ -3352,38 +3400,38 @@ parserFormula.prototype = {
else if ( parserHelp.isFunc.call( this, this.Formula, this.pCurrPos ) ) {
var found_operator = null;
if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Mathematic )//Mathematic
found_operator = new FormulaObjects.cFormulaFunction.Mathematic[this.operand_str.toUpperCase()]();
if ( this.operand_str.toUpperCase() in cFormulaFunction.Mathematic )//Mathematic
found_operator = new cFormulaFunction.Mathematic[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Logical )//Logical
found_operator = new FormulaObjects.cFormulaFunction.Logical[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Logical )//Logical
found_operator = new cFormulaFunction.Logical[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Information )//Information
found_operator = new FormulaObjects.cFormulaFunction.Information[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Information )//Information
found_operator = new cFormulaFunction.Information[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Statistical )//Statistical
found_operator = new FormulaObjects.cFormulaFunction.Statistical[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Statistical )//Statistical
found_operator = new cFormulaFunction.Statistical[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.TextAndData )//Text and data
found_operator = new FormulaObjects.cFormulaFunction.TextAndData[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.TextAndData )//Text and data
found_operator = new cFormulaFunction.TextAndData[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Cube )//Cube
found_operator = new FormulaObjects.cFormulaFunction.Cube[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Cube )//Cube
found_operator = new cFormulaFunction.Cube[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Database )//Database
found_operator = new FormulaObjects.cFormulaFunction.Database[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Database )//Database
found_operator = new cFormulaFunction.Database[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.DateAndTime )//Date and time
found_operator = new FormulaObjects.cFormulaFunction.DateAndTime[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.DateAndTime )//Date and time
found_operator = new cFormulaFunction.DateAndTime[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Engineering )//Engineering
found_operator = new FormulaObjects.cFormulaFunction.Engineering[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Engineering )//Engineering
found_operator = new cFormulaFunction.Engineering[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.Financial )//Financial
found_operator = new FormulaObjects.cFormulaFunction.Financial[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.Financial )//Financial
found_operator = new cFormulaFunction.Financial[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in FormulaObjects.cFormulaFunction.LookupAndReference )//Lookup and reference
found_operator = new FormulaObjects.cFormulaFunction.LookupAndReference[this.operand_str.toUpperCase()]();
else if ( this.operand_str.toUpperCase() in cFormulaFunction.LookupAndReference )//Lookup and reference
found_operator = new cFormulaFunction.LookupAndReference[this.operand_str.toUpperCase()]();
if ( found_operator !== null && found_operator !== undefined )
this.elemArr.push( found_operator );
......@@ -4082,6 +4130,7 @@ function searchRegExp( str, flags ) {
return new RegExp( vFS + "$", flags ? flags : "i" );
}
function searchRegExp2( s, mask ) {
//todo протестировать
var bRes = true;
......@@ -4138,6 +4187,7 @@ function searchRegExp2( s, mask ) {
}
return bRes;
}
/*
Next code take from OpenOffice Source.
*/
......@@ -4606,4 +4656,5 @@ function getLogGamma( fZ ) {
if ( fZ >= 0.5 )
return Math.log( lcl_GetGammaHelper( fZ + 1 ) / fZ );
return lcl_GetLogGammaHelper( fZ + 2 ) - Math.log( fZ + 1 ) - Math.log( fZ );
}
\ No newline at end of file
}
......@@ -7,7 +7,8 @@
* Time: 15:18
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.Statistical = {
cFormulaFunction.Statistical = {
'groupName':"Statistical",
'AVEDEV':cAVEDEV,
'AVERAGE':cAVERAGE,
......@@ -111,6 +112,7 @@ function cAVEDEV() {
this.numFormat = this.formatType.def;
}
cAVEDEV.prototype = Object.create( cBaseFunction.prototype )
cAVEDEV.prototype.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 ), arrX = [];
......@@ -187,6 +189,7 @@ function cAVERAGE() {
this.numFormat = this.formatType.def;
}
cAVERAGE.prototype = Object.create( cBaseFunction.prototype )
cAVERAGE.prototype.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 );
......@@ -268,6 +271,7 @@ function cAVERAGEA() {
this.numFormat = this.formatType.def;
}
cAVERAGEA.prototype = Object.create( cBaseFunction.prototype )
cAVERAGEA.prototype.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 );
......@@ -351,6 +355,7 @@ function cAVERAGEIF() {
this.numFormat = this.formatType.def;
}
cAVERAGEIF.prototype = Object.create( cBaseFunction.prototype )
cAVERAGEIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : arg[0], _sum = 0, _count = 0, valueForSearching;
......@@ -430,16 +435,19 @@ cAVERAGEIF.prototype.getInfo = function () {
function cAVERAGEIFS() {
cBaseFunction.call( this, "AVERAGEIFS" );
}
cAVERAGEIFS.prototype = Object.create( cBaseFunction.prototype )
function cBETADIST() {/*Нет реализации в Google Docs*/
cBaseFunction.call( this, "BETADIST" );
}
cBETADIST.prototype = Object.create( cBaseFunction.prototype )
function cBETAINV() {/*Нет реализации в Google Docs*/
cBaseFunction.call( this, "BETAINV" );
}
cBETAINV.prototype = Object.create( cBaseFunction.prototype )
function cBINOMDIST() {
......@@ -460,6 +468,7 @@ function cBINOMDIST() {
this.numFormat = this.formatType.def;
}
cBINOMDIST.prototype = Object.create( cBaseFunction.prototype )
cBINOMDIST.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
......@@ -532,16 +541,19 @@ cBINOMDIST.prototype.getInfo = function () {
function cCHIDIST() {
cBaseFunction.call( this, "CHIDIST" );
}
cCHIDIST.prototype = Object.create( cBaseFunction.prototype )
function cCHIINV() {
cBaseFunction.call( this, "CHIINV" );
}
cCHIINV.prototype = Object.create( cBaseFunction.prototype )
function cCHITEST() {
cBaseFunction.call( this, "CHITEST" );
}
cCHITEST.prototype = Object.create( cBaseFunction.prototype )
function cCONFIDENCE() {
......@@ -562,6 +574,7 @@ function cCONFIDENCE() {
this.numFormat = this.formatType.def;
}
cCONFIDENCE.prototype = Object.create( cBaseFunction.prototype )
cCONFIDENCE.prototype.Calculate = function ( arg ) {
......@@ -626,6 +639,7 @@ function cCORREL() {
this.numFormat = this.formatType.def;
}
cCORREL.prototype = Object.create( cBaseFunction.prototype )
cCORREL.prototype.Calculate = function ( arg ) {
......@@ -719,6 +733,7 @@ function cCOUNT() {
this.numFormat = this.formatType.noneFormat;
}
cCOUNT.prototype = Object.create( cBaseFunction.prototype )
cCOUNT.prototype.Calculate = function ( arg ) {
var count = 0;
......@@ -782,6 +797,7 @@ function cCOUNTA() {
this.numFormat = this.formatType.noneFormat;
}
cCOUNTA.prototype = Object.create( cBaseFunction.prototype )
cCOUNTA.prototype.Calculate = function ( arg ) {
var count = 0;
......@@ -840,6 +856,7 @@ function cCOUNTBLANK() {
this.numFormat = this.formatType.noneFormat;
}
cCOUNTBLANK.prototype = Object.create( cBaseFunction.prototype )
cCOUNTBLANK.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -876,6 +893,7 @@ function cCOUNTIF() {
this.numFormat = this.formatType.def;
}
cCOUNTIF.prototype = Object.create( cBaseFunction.prototype )
cCOUNTIF.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], _count = 0, valueForSearching;
......@@ -936,6 +954,7 @@ cCOUNTIF.prototype.getInfo = function () {
function cCOUNTIFS() {
cBaseFunction.call( this, "COUNTIFS" );
}
cCOUNTIFS.prototype = Object.create( cBaseFunction.prototype )
function cCOVAR() {
......@@ -956,6 +975,7 @@ function cCOVAR() {
this.numFormat = this.formatType.def;
}
cCOVAR.prototype = Object.create( cBaseFunction.prototype )
cCOVAR.prototype.Calculate = function ( arg ) {
......@@ -1043,6 +1063,7 @@ function cCRITBINOM() {
this.numFormat = this.formatType.def;
}
cCRITBINOM.prototype = Object.create( cBaseFunction.prototype )
cCRITBINOM.prototype.Calculate = function ( arg ) {
var n = arg[0], p = arg[1], alpha = arg[2]; // alpha
......@@ -1136,6 +1157,7 @@ function cDEVSQ() {
this.numFormat = this.formatType.def;
}
cDEVSQ.prototype = Object.create( cBaseFunction.prototype )
cDEVSQ.prototype.Calculate = function ( arg ) {
......@@ -1223,6 +1245,7 @@ function cEXPONDIST() {
this.numFormat = this.formatType.def;
}
cEXPONDIST.prototype = Object.create( cBaseFunction.prototype )
cEXPONDIST.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
......@@ -1275,11 +1298,13 @@ cEXPONDIST.prototype.getInfo = function () {
function cFDIST() {
cBaseFunction.call( this, "FDIST" );
}
cFDIST.prototype = Object.create( cBaseFunction.prototype )
function cFINV() {
cBaseFunction.call( this, "FINV" );
}
cFINV.prototype = Object.create( cBaseFunction.prototype )
function cFISHER() {
......@@ -1300,6 +1325,7 @@ function cFISHER() {
this.numFormat = this.formatType.def;
}
cFISHER.prototype = Object.create( cBaseFunction.prototype )
cFISHER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1357,6 +1383,7 @@ function cFISHERINV() {
this.numFormat = this.formatType.def;
}
cFISHERINV.prototype = Object.create( cBaseFunction.prototype )
cFISHERINV.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1414,6 +1441,7 @@ function cFORECAST() {
this.numFormat = this.formatType.def;
}
cFORECAST.prototype = Object.create( cBaseFunction.prototype )
cFORECAST.prototype.Calculate = function ( arg ) {
......@@ -1520,12 +1548,13 @@ function cFREQUENCY() {
this.numFormat = this.formatType.noneFormat;
}
cFREQUENCY.prototype = Object.create( cBaseFunction.prototype )
cFREQUENCY.prototype.Calculate = function ( arg ) {
function frequency( A, B ) {
function sort(a,b){
function sort( a, b ) {
return a - b;
}
......@@ -1562,7 +1591,9 @@ cFREQUENCY.prototype.Calculate = function ( arg ) {
tB.push( Number.POSITIVE_INFINITY );
tB.sort( sort );
var C = [[]], k = 0;
var C = [
[]
], k = 0;
for ( var i = 1; i < tB.length; i++, k++ ) {
C[0][k] = new cNumber( 0 );
for ( var j = 0; j < tA.length; j++ ) {
......@@ -1614,11 +1645,13 @@ function cFTEST() {
function cGAMMADIST() {
cBaseFunction.call( this, "GAMMADIST" );
}
cGAMMADIST.prototype = Object.create( cBaseFunction.prototype )
function cGAMMAINV() {
cBaseFunction.call( this, "GAMMAINV" );
}
cGAMMAINV.prototype = Object.create( cBaseFunction.prototype )
function cGAMMALN() {
......@@ -1639,6 +1672,7 @@ function cGAMMALN() {
this.numFormat = this.formatType.def;
}
cGAMMALN.prototype = Object.create( cBaseFunction.prototype )
cGAMMALN.prototype.Calculate = function ( arg ) {
......@@ -1695,6 +1729,7 @@ function cGEOMEAN() {
this.numFormat = this.formatType.def;
}
cGEOMEAN.prototype = Object.create( cBaseFunction.prototype )
cGEOMEAN.prototype.Calculate = function ( arg ) {
......@@ -1764,6 +1799,7 @@ cGEOMEAN.prototype.getInfo = function () {
function cGROWTH() {
cBaseFunction.call( this, "GROWTH" );
}
cGROWTH.prototype = Object.create( cBaseFunction.prototype )
function cHARMEAN() {
......@@ -1784,6 +1820,7 @@ function cHARMEAN() {
this.numFormat = this.formatType.def;
}
cHARMEAN.prototype = Object.create( cBaseFunction.prototype )
cHARMEAN.prototype.Calculate = function ( arg ) {
......@@ -1872,6 +1909,7 @@ function cHYPGEOMDIST() {
this.numFormat = this.formatType.def;
}
cHYPGEOMDIST.prototype = Object.create( cBaseFunction.prototype )
cHYPGEOMDIST.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
......@@ -1952,6 +1990,7 @@ function cINTERCEPT() {
this.numFormat = this.formatType.def;
}
cINTERCEPT.prototype = Object.create( cBaseFunction.prototype )
cINTERCEPT.prototype.Calculate = function ( arg ) {
......@@ -2046,6 +2085,7 @@ function cKURT() {
this.numFormat = this.formatType.def;
}
cKURT.prototype = Object.create( cBaseFunction.prototype )
cKURT.prototype.Calculate = function ( arg ) {
......@@ -2145,6 +2185,7 @@ function cLARGE() {
this.numFormat = this.formatType.noneFormat;
}
cLARGE.prototype = Object.create( cBaseFunction.prototype )
cLARGE.prototype.Calculate = function ( arg ) {
......@@ -2211,11 +2252,13 @@ cLARGE.prototype.getInfo = function () {
function cLINEST() {
cBaseFunction.call( this, "LINEST" );
}
cLINEST.prototype = Object.create( cBaseFunction.prototype )
function cLOGEST() {
cBaseFunction.call( this, "LOGEST" );
}
cLOGEST.prototype = Object.create( cBaseFunction.prototype )
function cLOGINV() {
......@@ -2236,6 +2279,7 @@ function cLOGINV() {
this.numFormat = this.formatType.def;
}
cLOGINV.prototype = Object.create( cBaseFunction.prototype )
cLOGINV.prototype.Calculate = function ( arg ) {
......@@ -2304,6 +2348,7 @@ function cLOGNORMDIST() {
this.numFormat = this.formatType.def;
}
cLOGNORMDIST.prototype = Object.create( cBaseFunction.prototype )
cLOGNORMDIST.prototype.Calculate = function ( arg ) {
......@@ -2372,6 +2417,7 @@ function cMAX() {
this.numFormat = this.formatType.def;
}
cMAX.prototype = Object.create( cBaseFunction.prototype )
cMAX.prototype.Calculate = function ( arg ) {
var argI, argIVal, max = Number.NEGATIVE_INFINITY;
......@@ -2459,6 +2505,7 @@ function cMAXA() {
this.numFormat = this.formatType.def;
}
cMAXA.prototype = Object.create( cBaseFunction.prototype )
cMAXA.prototype.Calculate = function ( arg ) {
var argI, argIVal, max = Number.NEGATIVE_INFINITY;
......@@ -2548,6 +2595,7 @@ function cMEDIAN() {
this.numFormat = this.formatType.def;
}
cMEDIAN.prototype = Object.create( cBaseFunction.prototype )
cMEDIAN.prototype.Calculate = function ( arg ) {
......@@ -2635,6 +2683,7 @@ function cMIN() {
this.numFormat = this.formatType.def;
}
cMIN.prototype = Object.create( cBaseFunction.prototype )
cMIN.prototype.Calculate = function ( arg ) {
var argI, argIVal, min = Number.POSITIVE_INFINITY;
......@@ -2723,6 +2772,7 @@ function cMINA() {
this.numFormat = this.formatType.def;
}
cMINA.prototype = Object.create( cBaseFunction.prototype )
cMINA.prototype.Calculate = function ( arg ) {
var argI, argIVal, min = Number.POSITIVE_INFINITY;
......@@ -2814,6 +2864,7 @@ function cMODE() {
this.numFormat = this.formatType.def;
}
cMODE.prototype = Object.create( cBaseFunction.prototype )
cMODE.prototype.Calculate = function ( arg ) {
......@@ -2921,6 +2972,7 @@ function cNEGBINOMDIST() {
this.numFormat = this.formatType.def;
}
cNEGBINOMDIST.prototype = Object.create( cBaseFunction.prototype )
cNEGBINOMDIST.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
......@@ -2992,6 +3044,7 @@ function cNORMDIST() {
this.numFormat = this.formatType.def;
}
cNORMDIST.prototype = Object.create( cBaseFunction.prototype )
cNORMDIST.prototype.Calculate = function ( arg ) {
......@@ -3074,6 +3127,7 @@ function cNORMINV() {
this.numFormat = this.formatType.def;
}
cNORMINV.prototype = Object.create( cBaseFunction.prototype )
cNORMINV.prototype.Calculate = function ( arg ) {
......@@ -3142,6 +3196,7 @@ function cNORMSDIST() {
this.numFormat = this.formatType.def;
}
cNORMSDIST.prototype = Object.create( cBaseFunction.prototype )
cNORMSDIST.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -3193,6 +3248,7 @@ function cNORMSINV() {
this.numFormat = this.formatType.def;
}
cNORMSINV.prototype = Object.create( cBaseFunction.prototype )
cNORMSINV.prototype.Calculate = function ( arg ) {
......@@ -3252,6 +3308,7 @@ function cPEARSON() {
this.numFormat = this.formatType.def;
}
cPEARSON.prototype = Object.create( cBaseFunction.prototype )
cPEARSON.prototype.Calculate = function ( arg ) {
......@@ -3346,6 +3403,7 @@ function cPERCENTILE() {
this.numFormat = this.formatType.noneFormat;
}
cPERCENTILE.prototype = Object.create( cBaseFunction.prototype )
cPERCENTILE.prototype.Calculate = function ( arg ) {
......@@ -3441,6 +3499,7 @@ function cPERCENTRANK() {
this.numFormat = this.formatType.def;
}
cPERCENTRANK.prototype = Object.create( cBaseFunction.prototype )
cPERCENTRANK.prototype.Calculate = function ( arg ) {
......@@ -3565,6 +3624,7 @@ function cPERMUT() {
this.numFormat = this.formatType.def;
}
cPERMUT.prototype = Object.create( cBaseFunction.prototype )
cPERMUT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -3661,6 +3721,7 @@ function cPOISSON() {
this.numFormat = this.formatType.def;
}
cPOISSON.prototype = Object.create( cBaseFunction.prototype )
cPOISSON.prototype.Calculate = function ( arg ) {
......@@ -3744,6 +3805,7 @@ function cPROB() {
this.numFormat = this.formatType.noneFormat;
}
cPROB.prototype = Object.create( cBaseFunction.prototype )
cPROB.prototype.Calculate = function ( arg ) {
......@@ -3864,6 +3926,7 @@ function cQUARTILE() {
this.numFormat = this.formatType.noneFormat;
}
cQUARTILE.prototype = Object.create( cBaseFunction.prototype )
cQUARTILE.prototype.Calculate = function ( arg ) {
......@@ -3970,6 +4033,7 @@ cQUARTILE.prototype.getInfo = function () {
function cRANK() {
cBaseFunction.call( this, "RANK" );
}
cRANK.prototype = Object.create( cBaseFunction.prototype )
function cRSQ() {
......@@ -3990,6 +4054,7 @@ function cRSQ() {
this.numFormat = this.formatType.def;
}
cRSQ.prototype = Object.create( cBaseFunction.prototype )
cRSQ.prototype.Calculate = function ( arg ) {
......@@ -4084,6 +4149,7 @@ function cSKEW() {
this.numFormat = this.formatType.def;
}
cSKEW.prototype = Object.create( cBaseFunction.prototype )
cSKEW.prototype.Calculate = function ( arg ) {
......@@ -4185,6 +4251,7 @@ function cSLOPE() {
this.numFormat = this.formatType.def;
}
cSLOPE.prototype = Object.create( cBaseFunction.prototype )
cSLOPE.prototype.Calculate = function ( arg ) {
......@@ -4279,6 +4346,7 @@ function cSMALL() {
this.numFormat = this.formatType.noneFormat;
}
cSMALL.prototype = Object.create( cBaseFunction.prototype )
cSMALL.prototype.Calculate = function ( arg ) {
......@@ -4360,6 +4428,7 @@ function cSTANDARDIZE() {
this.numFormat = this.formatType.def;
}
cSTANDARDIZE.prototype = Object.create( cBaseFunction.prototype )
cSTANDARDIZE.prototype.Calculate = function ( arg ) {
......@@ -4429,6 +4498,7 @@ function cSTDEV() {
this.numFormat = this.formatType.noneFormat;
}
cSTDEV.prototype = Object.create( cBaseFunction.prototype )
cSTDEV.prototype.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 ), member = [];
......@@ -4505,6 +4575,7 @@ function cSTDEVA() {
this.numFormat = this.formatType.def;
}
cSTDEVA.prototype = Object.create( cBaseFunction.prototype )
cSTDEVA.prototype.Calculate = function ( arg ) {
var count = 0, sum = new cNumber( 0 ), member = [];
......@@ -4578,6 +4649,7 @@ function cSTDEVP() {
this.numFormat = this.formatType.def;
}
cSTDEVP.prototype = Object.create( cBaseFunction.prototype )
cSTDEVP.prototype.Calculate = function ( arg ) {
......@@ -4591,7 +4663,7 @@ cSTDEVP.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -4615,20 +4687,20 @@ cSTDEVP.prototype.Calculate = function ( arg ) {
if ( arg[j] instanceof cArea || arg[j] instanceof cArea3D ) {
arg[j].foreach2( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
} );
}
else if ( arg[j] instanceof cRef || arg[j] instanceof cRef3D ) {
var a = arg[j].getValue();
if ( a instanceof cNumber || a instanceof cError ){
if ( a instanceof cNumber || a instanceof cError ) {
arr0.push( a );
}
}
else if ( arg[j] instanceof cArray ) {
arg[j].foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
} );
......@@ -4637,7 +4709,7 @@ cSTDEVP.prototype.Calculate = function ( arg ) {
arr0.push( arg[j].tocNumber() );
}
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) {
arr0.push( new cNumber(0) );
arr0.push( new cNumber( 0 ) );
}
else
return this.value = cError( cErrorType.wrong_value_type )
......@@ -4668,6 +4740,7 @@ function cSTDEVPA() {
this.numFormat = this.formatType.def;
}
cSTDEVPA.prototype = Object.create( cBaseFunction.prototype )
cSTDEVPA.prototype.Calculate = function ( arg ) {
......@@ -4681,7 +4754,7 @@ cSTDEVPA.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -4705,39 +4778,39 @@ cSTDEVPA.prototype.Calculate = function ( arg ) {
if ( arg[j] instanceof cArea || arg[j] instanceof cArea3D ) {
arg[j].foreach2( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
else if ( arg[j] instanceof cRef || arg[j] instanceof cRef3D ) {
var a = arg[j].getValue();
if ( a instanceof cNumber || a instanceof cError ){
if ( a instanceof cNumber || a instanceof cError ) {
arr0.push( a );
}
else if ( a instanceof cBool ) {
arr0.push( a.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
}
else if ( arg[j] instanceof cArray ) {
arg[j].foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
......@@ -4745,7 +4818,7 @@ cSTDEVPA.prototype.Calculate = function ( arg ) {
arr0.push( arg[j].tocNumber() );
}
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) {
arr0.push( new cNumber(0) );
arr0.push( new cNumber( 0 ) );
}
else
return this.value = cError( cErrorType.wrong_value_type )
......@@ -4776,6 +4849,7 @@ function cSTEYX() {
this.numFormat = this.formatType.def;
}
cSTEYX.prototype = Object.create( cBaseFunction.prototype )
cSTEYX.prototype.Calculate = function ( arg ) {
......@@ -4812,11 +4886,10 @@ cSTEYX.prototype.Calculate = function ( arg ) {
}
if ( sqrXDelta == 0 || sqrYDelta == 0 || xLength < 3 )
return new cError( cErrorType.division_by_zero );
else
return new cNumber( Math.sqrt( (1/(xLength-2)) * (sqrYDelta - sumXDeltaYDelta * sumXDeltaYDelta / sqrXDelta) ) );
return new cNumber( Math.sqrt( (1 / (xLength - 2)) * (sqrYDelta - sumXDeltaYDelta * sumXDeltaYDelta / sqrXDelta) ) );
}
......@@ -4857,26 +4930,31 @@ cSTEYX.prototype.getInfo = function () {
function cTDIST() {
cBaseFunction.call( this, "TDIST" );
}
cTDIST.prototype = Object.create( cBaseFunction.prototype )
function cTINV() {
cBaseFunction.call( this, "TINV" );
}
cTINV.prototype = Object.create( cBaseFunction.prototype )
function cTREND() {
cBaseFunction.call( this, "TREND" );
}
cTREND.prototype = Object.create( cBaseFunction.prototype )
function cTRIMMEAN() {
cBaseFunction.call( this, "TRIMMEAN" );
}
cTRIMMEAN.prototype = Object.create( cBaseFunction.prototype )
function cTTEST() {
cBaseFunction.call( this, "TTEST" );
}
cTTEST.prototype = Object.create( cBaseFunction.prototype )
function cVAR() {
......@@ -4897,6 +4975,7 @@ function cVAR() {
this.numFormat = this.formatType.def;
}
cVAR.prototype = Object.create( cBaseFunction.prototype )
cVAR.prototype.Calculate = function ( arg ) {
......@@ -4910,7 +4989,7 @@ cVAR.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -4985,6 +5064,7 @@ function cVARA() {
this.numFormat = this.formatType.def;
}
cVARA.prototype = Object.create( cBaseFunction.prototype )
cVARA.prototype.Calculate = function ( arg ) {
......@@ -4998,7 +5078,7 @@ cVARA.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -5022,39 +5102,39 @@ cVARA.prototype.Calculate = function ( arg ) {
if ( arg[j] instanceof cArea || arg[j] instanceof cArea3D ) {
arg[j].foreach2( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
else if ( arg[j] instanceof cRef || arg[j] instanceof cRef3D ) {
var a = arg[j].getValue();
if ( a instanceof cNumber || a instanceof cError ){
if ( a instanceof cNumber || a instanceof cError ) {
arr0.push( a );
}
else if ( a instanceof cBool ) {
arr0.push( a.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
}
else if ( arg[j] instanceof cArray ) {
arg[j].foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
......@@ -5062,7 +5142,7 @@ cVARA.prototype.Calculate = function ( arg ) {
arr0.push( arg[j].tocNumber() );
}
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) {
arr0.push( new cNumber(0) );
arr0.push( new cNumber( 0 ) );
}
else
return this.value = cError( cErrorType.wrong_value_type )
......@@ -5093,6 +5173,7 @@ function cVARP() {
this.numFormat = this.formatType.def;
}
cVARP.prototype = Object.create( cBaseFunction.prototype )
cVARP.prototype.Calculate = function ( arg ) {
......@@ -5106,7 +5187,7 @@ cVARP.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -5130,29 +5211,29 @@ cVARP.prototype.Calculate = function ( arg ) {
if ( arg[j] instanceof cArea || arg[j] instanceof cArea3D ) {
arg[j].foreach2( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
} );
}
else if ( arg[j] instanceof cRef || arg[j] instanceof cRef3D ) {
var a = arg[j].getValue();
if ( a instanceof cNumber || a instanceof cError ){
if ( a instanceof cNumber || a instanceof cError ) {
arr0.push( a );
}
}
else if ( arg[j] instanceof cArray ) {
arg[j].foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
} );
} );
}
else if ( arg[j] instanceof cNumber || arg[j] instanceof cBool ) {
arr0.push( arg[j].tocNumber() );
}
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) {
arr0.push( new cNumber(0) );
arr0.push( new cNumber( 0 ) );
}
else
return this.value = cError( cErrorType.wrong_value_type )
......@@ -5183,6 +5264,7 @@ function cVARPA() {
this.numFormat = this.formatType.def;
}
cVARPA.prototype = Object.create( cBaseFunction.prototype )
cVARPA.prototype.Calculate = function ( arg ) {
......@@ -5196,7 +5278,7 @@ cVARPA.prototype.Calculate = function ( arg ) {
tA.push( x[i].getValue() )
xLength++;
}
else if( x[i] instanceof cError ){
else if ( x[i] instanceof cError ) {
return x[i];
}
......@@ -5220,39 +5302,39 @@ cVARPA.prototype.Calculate = function ( arg ) {
if ( arg[j] instanceof cArea || arg[j] instanceof cArea3D ) {
arg[j].foreach2( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
else if ( arg[j] instanceof cRef || arg[j] instanceof cRef3D ) {
var a = arg[j].getValue();
if ( a instanceof cNumber || a instanceof cError ){
if ( a instanceof cNumber || a instanceof cError ) {
arr0.push( a );
}
else if ( a instanceof cBool ) {
arr0.push( a.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
}
else if ( arg[j] instanceof cArray ) {
arg[j].foreach( function ( elem ) {
if ( elem instanceof cNumber || elem instanceof cError ){
if ( elem instanceof cNumber || elem instanceof cError ) {
arr0.push( elem );
}
else if ( elem instanceof cBool ) {
arr0.push( elem.tocNumber() );
}
else{
arr0.push( new cNumber(0) );
else {
arr0.push( new cNumber( 0 ) );
}
} );
}
......@@ -5260,7 +5342,7 @@ cVARPA.prototype.Calculate = function ( arg ) {
arr0.push( arg[j].tocNumber() );
}
else if ( arg[j] instanceof cString || arg[j] instanceof cEmpty ) {
arr0.push( new cNumber(0) );
arr0.push( new cNumber( 0 ) );
}
else
return this.value = cError( cErrorType.wrong_value_type )
......@@ -5278,9 +5360,11 @@ cVARPA.prototype.getInfo = function () {
function cWEIBULL() {
cBaseFunction.call( this, "WEIBULL" );
}
cWEIBULL.prototype = Object.create( cBaseFunction.prototype )
function cZTEST() {
cBaseFunction.call( this, "ZTEST" );
}
cZTEST.prototype = Object.create( cBaseFunction.prototype )
......@@ -7,7 +7,8 @@
* Time: 15:17
* To change this template use File | Settings | File Templates.
*/
FormulaObjects.cFormulaFunction.TextAndData = {
cFormulaFunction.TextAndData = {
'groupName':"TextAndData",
'ASC':cASC,
'BAHTTEXT':cBAHTTEXT,
......@@ -48,11 +49,13 @@ FormulaObjects.cFormulaFunction.TextAndData = {
function cASC() {
cBaseFunction.call( this, "ASC" );
}
cASC.prototype = Object.create( cBaseFunction.prototype )
function cBAHTTEXT() {
cBaseFunction.call( this, "BAHTTEXT" );
}
cBAHTTEXT.prototype = Object.create( cBaseFunction.prototype )
function cCHAR() {
......@@ -73,6 +76,7 @@ function cCHAR() {
this.numFormat = this.formatType.def;
}
cCHAR.prototype = Object.create( cBaseFunction.prototype )
cCHAR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -129,6 +133,7 @@ function cCLEAN() {
}
cCLEAN.prototype = Object.create( cBaseFunction.prototype )
cCLEAN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -176,6 +181,7 @@ function cCODE() {
this.numFormat = this.formatType.def;
}
cCODE.prototype = Object.create( cBaseFunction.prototype )
cCODE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -231,6 +237,7 @@ function cCONCATENATE() {
this.numFormat = this.formatType.def;
}
cCONCATENATE.prototype = Object.create( cBaseFunction.prototype )
cCONCATENATE.prototype.Calculate = function ( arg ) {
var arg0 = new cString( "" ), argI;
......@@ -288,6 +295,7 @@ function cDOLLAR() {
this.numFormat = this.formatType.noneFormat;
}
cDOLLAR.prototype = Object.create( cBaseFunction.prototype )
cDOLLAR.prototype.Calculate = function ( arg ) {
......@@ -484,6 +492,7 @@ function cEXACT() {
this.numFormat = this.formatType.def;
}
cEXACT.prototype = Object.create( cBaseFunction.prototype )
cEXACT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -539,6 +548,7 @@ function cFIND() {
this.numFormat = this.formatType.def;
}
cFIND.prototype = Object.create( cBaseFunction.prototype )
cFIND.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = this.getArguments() == 3 ? arg[2] : null, res, str, searchStr, pos = -1;
......@@ -609,7 +619,7 @@ cFIND.prototype.getInfo = function () {
}
function cFINDB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["FIND"]()
var r = new cFormulaFunction.TextAndData["FIND"]()
r.setName( "FINDB" );
return r;
}
......@@ -632,6 +642,7 @@ function cFIXED() {
this.numFormat = this.formatType.def;
}
cFIXED.prototype = Object.create( cBaseFunction.prototype )
cFIXED.prototype.Calculate = function ( arg ) {
......@@ -809,6 +820,7 @@ cFIXED.prototype.getInfo = function () {
function cJIS() {
cBaseFunction.call( this, "JIS" );
}
cJIS.prototype = Object.create( cBaseFunction.prototype )
function cLEFT() {
......@@ -829,6 +841,7 @@ function cLEFT() {
this.numFormat = this.formatType.def;
}
cLEFT.prototype = Object.create( cBaseFunction.prototype )
cLEFT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
......@@ -869,7 +882,7 @@ cLEFT.prototype.getInfo = function () {
}
function cLEFTB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["LEFT"]()
var r = new cFormulaFunction.TextAndData["LEFT"]()
r.setName( "LEFTB" );
return r;
}
......@@ -892,6 +905,7 @@ function cLEN() {
this.numFormat = this.formatType.def;
}
cLEN.prototype = Object.create( cBaseFunction.prototype )
cLEN.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -918,7 +932,7 @@ cLEN.prototype.getInfo = function () {
}
function cLENB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["LEN"]();
var r = new cFormulaFunction.TextAndData["LEN"]();
r.setName( "LENB" );
return r;
}
......@@ -941,6 +955,7 @@ function cLOWER() {
this.numFormat = this.formatType.def;
}
cLOWER.prototype = Object.create( cBaseFunction.prototype )
cLOWER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -981,6 +996,7 @@ function cMID() {
this.numFormat = this.formatType.def;
}
cMID.prototype = Object.create( cBaseFunction.prototype )
cMID.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2];
......@@ -1033,7 +1049,7 @@ cMID.prototype.getInfo = function () {
}
function cMIDB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["MID"]();
var r = new cFormulaFunction.TextAndData["MID"]();
r.setName( "MIDB" );
return r;
}
......@@ -1041,6 +1057,7 @@ function cMIDB() {
function cPHONETIC() {
cBaseFunction.call( this, "PHONETIC" );
}
cPHONETIC.prototype = Object.create( cBaseFunction.prototype )
function cPROPER() {
......@@ -1061,6 +1078,7 @@ function cPROPER() {
this.numFormat = this.formatType.def;
}
cPROPER.prototype = Object.create( cBaseFunction.prototype )
cPROPER.prototype.Calculate = function ( arg ) {
var reg_PROPER = new RegExp( "[-#$+*/^&%<\\[\\]='?_\\@!~`\">: ;.\\)\\(,]|\\d|\\s" ), arg0 = arg[0];
......@@ -1138,6 +1156,7 @@ function cREPLACE() {
this.numFormat = this.formatType.def;
}
cREPLACE.prototype = Object.create( cBaseFunction.prototype )
cREPLACE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3];
......@@ -1210,7 +1229,7 @@ cREPLACE.prototype.getInfo = function () {
}
function cREPLACEB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["REPLACE"]();
var r = new cFormulaFunction.TextAndData["REPLACE"]();
r.setName( "REPLACEB" );
return r;
}
......@@ -1233,6 +1252,7 @@ function cREPT() {
this.numFormat = this.formatType.def;
}
cREPT.prototype = Object.create( cBaseFunction.prototype )
cREPT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], res = "";
......@@ -1304,6 +1324,7 @@ function cRIGHT() {
this.numFormat = this.formatType.def;
}
cRIGHT.prototype = Object.create( cBaseFunction.prototype )
cRIGHT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = this.argumentsCurrent == 1 ? new cNumber( 1 ) : arg[1];
......@@ -1344,7 +1365,7 @@ cRIGHT.prototype.getInfo = function () {
}
function cRIGHTB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["RIGHT"]()
var r = new cFormulaFunction.TextAndData["RIGHT"]()
r.setName( "RIGHTB" );
return r;
}
......@@ -1367,6 +1388,7 @@ function cSEARCH() {
this.numFormat = this.formatType.def;
}
cSEARCH.prototype = Object.create( cBaseFunction.prototype )
cSEARCH.prototype.Calculate = function ( arg ) {
......@@ -1450,7 +1472,7 @@ cSEARCH.prototype.getInfo = function () {
}
function cSEARCHB() {
var r = new FormulaObjects.cFormulaFunction.TextAndData["SEARCH"]();
var r = new cFormulaFunction.TextAndData["SEARCH"]();
r.setName( "SEARCHB" );
return r;
}
......@@ -1473,6 +1495,7 @@ function cSUBSTITUTE() {
this.numFormat = this.formatType.def;
}
cSUBSTITUTE.prototype = Object.create( cBaseFunction.prototype )
cSUBSTITUTE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2], arg3 = arg[3] ? arg[3] : new cNumber( 0 );
......@@ -1565,6 +1588,7 @@ function cT() {
this.numFormat = this.formatType.def;
}
cT.prototype = Object.create( cBaseFunction.prototype )
cT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1610,6 +1634,7 @@ function cTEXT() {
this.numFormat = this.formatType.def;
}
cTEXT.prototype = Object.create( cBaseFunction.prototype )
cTEXT.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], arg1 = arg[1];
......@@ -1685,6 +1710,7 @@ function cTRIM() {
this.numFormat = this.formatType.def;
}
cTRIM.prototype = Object.create( cBaseFunction.prototype )
cTRIM.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1701,7 +1727,7 @@ cTRIM.prototype.Calculate = function ( arg ) {
if ( arg0 instanceof cError )
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;
rx_space.test( $2[$1 + 1] ) ? res = "" : res = $2[$1];
return res;
......@@ -1732,6 +1758,7 @@ function cUPPER() {
this.numFormat = this.formatType.def;
}
cUPPER.prototype = Object.create( cBaseFunction.prototype )
cUPPER.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......@@ -1772,6 +1799,7 @@ function cVALUE() {
this.numFormat = this.formatType.noneFormat;
}
cVALUE.prototype = Object.create( cBaseFunction.prototype )
cVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0];
......
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