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

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

ODDLPRICE, ODDLYIELD, DURATION, MDURATION.
DURATION, MDURATION - отличаются от результата SCALC и EXCEL уже с тысячных.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55280 954022d7-b5bf-4e40-9824-e11837661b57
parent 4fcf34e9
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
*/ */
function yearFrac(d1, d2, mode) { function yearFrac(d1, d2, mode) {
d1.truncate();
d2.truncate();
var date1 = d1.getDate(), var date1 = d1.getDate(),
month1 = d1.getMonth()+1, month1 = d1.getMonth()+1,
year1 = d1.getFullYear(), year1 = d1.getFullYear(),
......
...@@ -568,7 +568,7 @@ cCEILING.prototype.Calculate = function ( arg ) { ...@@ -568,7 +568,7 @@ cCEILING.prototype.Calculate = function ( arg ) {
} }
var quotientTr = Math.floor( quotient ); var quotientTr = Math.floor( quotient );
var nolpiat = 5 * ( quotient < 0 ? -1.0 : quotient > 0 ? 1.0 : 0.0 ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * ( quotient < 0 ? -1.0 : quotient > 0 ? 1.0 : 0.0 ) * Math.pow( 10, Math.floor( Math.log10( Math.abs( quotient ) ) ) - cExcelSignificantDigits );
if ( Math.abs( quotient - quotientTr ) > nolpiat ) { if ( Math.abs( quotient - quotientTr ) > nolpiat ) {
++quotientTr; ++quotientTr;
...@@ -1182,7 +1182,7 @@ cFLOOR.prototype.Calculate = function ( arg ) { ...@@ -1182,7 +1182,7 @@ cFLOOR.prototype.Calculate = function ( arg ) {
return new cNumber( 0.0 ); return new cNumber( 0.0 );
} }
var nolpiat = 5 * ( quotient < 0 ? -1.0 : quotient > 0 ? 1.0 : 0.0 ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * ( quotient < 0 ? -1.0 : quotient > 0 ? 1.0 : 0.0 ) * Math.pow( 10, Math.floor( Math.log10( Math.abs( quotient ) ) ) - cExcelSignificantDigits );
return new cNumber( Math.floor( quotient + nolpiat ) * significance ); return new cNumber( Math.floor( quotient + nolpiat ) * significance );
} }
...@@ -1698,7 +1698,7 @@ cLOG10.prototype.Calculate = function ( arg ) { ...@@ -1698,7 +1698,7 @@ cLOG10.prototype.Calculate = function ( arg ) {
if ( elem.getValue() <= 0 ) if ( elem.getValue() <= 0 )
this.array[r][c] = new cError( cErrorType.not_numeric ); this.array[r][c] = new cError( cErrorType.not_numeric );
else else
this.array[r][c] = new cNumber( Math.log( elem.getValue() ) / Math.log( 10 ) ); this.array[r][c] = new cNumber( Math.log10( elem.getValue() ) );
} }
else { else {
this.array[r][c] = new cError( cErrorType.wrong_value_type ); this.array[r][c] = new cError( cErrorType.wrong_value_type );
...@@ -1709,7 +1709,7 @@ cLOG10.prototype.Calculate = function ( arg ) { ...@@ -1709,7 +1709,7 @@ cLOG10.prototype.Calculate = function ( arg ) {
if ( arg0.getValue() <= 0 ) if ( arg0.getValue() <= 0 )
return this.value = new cError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
else else
return this.value = new cNumber( Math.log( arg0.getValue() ) / Math.log( 10 ) ); return this.value = new cNumber( Math.log10( arg0.getValue() ) );
} }
} }
cLOG10.prototype.getInfo = function () { cLOG10.prototype.getInfo = function () {
...@@ -2146,14 +2146,14 @@ cMROUND.prototype.Calculate = function ( arg ) { ...@@ -2146,14 +2146,14 @@ cMROUND.prototype.Calculate = function ( arg ) {
var multiple; var multiple;
function mroundHelper( num ) { function mroundHelper( num ) {
var multiplier = Math.pow( 10, Math.floor( Math.log( Math.abs( num ) ) / Math.log( 10 ) ) - cExcelSignificantDigits + 1 ); var multiplier = Math.pow( 10, Math.floor( Math.log10( Math.abs( num ) ) ) - cExcelSignificantDigits + 1 );
var nolpiat = 0.5 * (num > 0 ? 1 : num < 0 ? -1 : 0) * multiplier; var nolpiat = 0.5 * (num > 0 ? 1 : num < 0 ? -1 : 0) * multiplier;
var y = (num + nolpiat) / multiplier; var y = (num + nolpiat) / multiplier;
y = y / Math.abs( y ) * Math.floor( Math.abs( y ) ) y = y / Math.abs( y ) * Math.floor( Math.abs( y ) )
var x = y * multiplier / multiple var x = y * multiplier / multiple
// var x = number / multiple; // var x = number / multiple;
var nolpiat = 5 * (x / Math.abs( x )) * Math.pow( 10, Math.floor( Math.log( Math.abs( x ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * (x / Math.abs( x )) * Math.pow( 10, Math.floor( Math.log10( Math.abs( x ) ) ) - cExcelSignificantDigits );
x = x + nolpiat; x = x + nolpiat;
x = x | x; x = x | x;
...@@ -3002,7 +3002,7 @@ cROUND.prototype.Calculate = function ( arg ) { ...@@ -3002,7 +3002,7 @@ cROUND.prototype.Calculate = function ( arg ) {
if ( quotient == 0 ) { if ( quotient == 0 ) {
return 0; return 0;
} }
var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log10( Math.abs( quotient ) ) ) - cExcelSignificantDigits );
return truncate( quotient + nolpiat ) * significance; return truncate( quotient + nolpiat ) * significance;
} }
......
...@@ -63,6 +63,10 @@ Date.prototype.getDaysInMonth.R = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3 ...@@ -63,6 +63,10 @@ Date.prototype.getDaysInMonth.R = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3
// durations of months for the leap year // durations of months for the leap year
Date.prototype.getDaysInMonth.L = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; Date.prototype.getDaysInMonth.L = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
Date.prototype.truncate = function() {
this.setHours(0,0,0,0);
}
Date.prototype.getExcelDate = function () { Date.prototype.getExcelDate = function () {
return Math.floor( ( this.getTime() / 1000 - this.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) ) return Math.floor( ( this.getTime() / 1000 - this.getTimezoneOffset() * 60 ) / c_sPerDay + ( c_DateCorrectConst + (g_bDate1904 ? 0 : 1) ) )
} }
...@@ -127,10 +131,16 @@ Math.fact = function ( n ) { ...@@ -127,10 +131,16 @@ Math.fact = function ( n ) {
return res; return res;
} }
Math.ln = function ( x ) { Math.ln = Math.log;
return Math.log( x ) / Math.log( Math.E );
Math.log10 = function( x ){
return Math.log( x ) / Math.log( 10 );
} }
Math.fmod = function (a,b) {
return Number( (a - (Math.floor( a / b ) * b)).toPrecision( cExcelSignificantDigits ) );
};
Math.binomCoeff = function ( n, k ) { Math.binomCoeff = function ( n, k ) {
return this.fact( n ) / (this.fact( k ) * this.fact( n - k )); return this.fact( n ) / (this.fact( k ) * this.fact( n - k ));
} }
......
...@@ -308,7 +308,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) { ...@@ -308,7 +308,7 @@ cDOLLAR.prototype.Calculate = function ( arg ) {
if ( quotient == 0 ) { if ( quotient == 0 ) {
return 0; return 0;
} }
var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log10( Math.abs( quotient ) ) ) - cExcelSignificantDigits );
return truncate( quotient + nolpiat ) * significance; return truncate( quotient + nolpiat ) * significance;
} }
...@@ -652,7 +652,7 @@ cFIXED.prototype.Calculate = function ( arg ) { ...@@ -652,7 +652,7 @@ cFIXED.prototype.Calculate = function ( arg ) {
if ( quotient == 0 ) { if ( quotient == 0 ) {
return 0; return 0;
} }
var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits ); var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log10( Math.abs( quotient ) ) ) - cExcelSignificantDigits );
return truncate( quotient + nolpiat ) * significance; return truncate( quotient + nolpiat ) * significance;
} }
......
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