Commit 38f6881b authored by GoshaZotov's avatar GoshaZotov

add T.INV formula

parent ef2f6b5f
......@@ -1039,6 +1039,12 @@ $( function () {
strictEqual( oParser.calculate().getValue().toFixed(5) - 0, 15.20686, "F.INV.RT(A2,A3,A4)" );
} );
test( "Test: \"T.INV\"", function () {
oParser = new parserFormula( "T.INV(0.75,2)", "A1", ws );
ok( oParser.parse(), "T.INV(0.75,2)" );
strictEqual( oParser.calculate().getValue().toFixed(7) - 0, 0.8164966, "T.INV(0.75,2)" );
} );
test( "Test: \"GAMMA\"", function () {
oParser = new parserFormula( "GAMMA(2.5)", "A1", ws );
ok( oParser.parse(), "GAMMA(2.5)" );
......
......@@ -67,7 +67,7 @@
cLINEST, cLOGEST, cLOGINV, cLOGNORMDIST, cMAX, cMAXA, cMEDIAN, cMIN, cMINA, cMODE, cNEGBINOMDIST, cNORMDIST,
cNORMINV, cNORMSDIST, cNORMSINV, cPEARSON, cPERCENTILE, cPERCENTRANK, cPERMUT, cPOISSON, cPROB, cQUARTILE,
cRANK, cRSQ, cSKEW, cSLOPE, cSMALL, cSTANDARDIZE, cSTDEV, cSTDEVA, cSTDEVP, cSTDEVPA, cSTEYX, cTDIST, cT_DIST,
cT_DIST_2T, cT_DIST_RT, cTINV, cTREND, cTRIMMEAN, cTTEST, cVAR, cVARA, cVARP, cVARPA, cWEIBULL, cZTEST);
cT_DIST_2T, cT_DIST_RT, cT_INV, cTINV, cTREND, cTRIMMEAN, cTTEST, cVAR, cVARA, cVARP, cVARPA, cWEIBULL, cZTEST);
function isInteger(value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
......@@ -955,6 +955,18 @@
return res;
};
function TDISTFUNCTION(fp, fDF, nT){
this.fp = fp;
this.fDF = fDF;
this.nT = nT;
}
TDISTFUNCTION.prototype.GetValue = function(x){
var res;
var betaDistVal = getTDist(x, this.fDF, this.nT);
res = this.fp - betaDistVal;
return res;
};
/**
* @constructor
......@@ -6752,6 +6764,68 @@
};
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cT_INV() {
cBaseFunction.call(this, "T.INV");
}
cT_INV.prototype = Object.create(cBaseFunction.prototype);
cT_INV.prototype.constructor = cT_INV;
cT_INV.prototype.argumentsMin = 2;
cT_INV.prototype.argumentsMax = 2;
cT_INV.prototype.Calculate = function (arg) {
var oArguments = this._prepareArguments(arg, arguments[1], true);
var argClone = oArguments.args;
argClone[0] = argClone[0].tocNumber();
argClone[1] = argClone[1].tocNumber();
var argError;
if (argError = this._checkErrorArg(argClone)) {
return this.value = argError;
}
var calcTDist = function(argArray){
var fP = argArray[0];
var fDF = parseInt(argArray[1]);
if ( fDF < 1.0 || fP <= 0.0 || fP > 1.0 ){
return new cError(cErrorType.not_numeric);
}
var aFunc, oVal, bConvError, res = null;
if ( fP === 1.0 ){
return new cError(cErrorType.not_numeric);
}else if(fP < 0.5){
aFunc = new TDISTFUNCTION(1 - fP, fDF, 4);
oVal = iterateInverse(aFunc, fDF * 0.5, fDF);
bConvError = oVal.bError;
res = - oVal.val;
}else{
aFunc = new TDISTFUNCTION(fP, fDF, 4);
oVal = iterateInverse(aFunc, fDF * 0.5, fDF);
bConvError = oVal.bError;
res = oVal.val;
}
if (bConvError){
return new cError(cErrorType.not_numeric);
}
return null !== res && !isNaN(res) ? new cNumber(res) : new cError(cErrorType.wrong_value_type);
};
return this.value = this._findArrayInNumberArguments(oArguments, calcTDist);
};
cT_INV.prototype.getInfo = function () {
return {
name: this.name, args: "(probability, deg_freedom)"
};
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
......
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