diff options
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/inc/interpre.hxx | 8 | ||||
-rw-r--r-- | sc/source/core/tool/interpr3.cxx | 91 | ||||
-rw-r--r-- | sc/source/core/tool/interpr4.cxx | 10 | ||||
-rw-r--r-- | sc/source/filter/excel/xlformula.cxx | 8 | ||||
-rw-r--r-- | sc/source/filter/oox/formulabase.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/src/scfuncs.src | 216 |
6 files changed, 311 insertions, 30 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 1902dadb949e..51d94e54fd9b 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -716,7 +716,7 @@ double GetChiDist(double fChi, double fDF); // for LEGACY.CHIDIST, returns r double GetChiSqDistCDF(double fX, double fDF); // for CHISQDIST, returns left tail double GetChiSqDistPDF(double fX, double fDF); // probability density function double GetFDist(double x, double fF1, double fF2); -double GetTDist(double T, double fDF); +double GetTDist( double T, double fDF, int nType ); double Fakultaet(double x); double BinomKoeff(double n, double k); double GetGamma(double x); @@ -750,6 +750,8 @@ void ScHypGeomDist_MS(); void ScLogNormDist( int nMinParamCount ); void ScLogNormInv(); void ScTDist(); +void ScTDist_MS(); +void ScTDist_T( int nTails ); void ScFDist(); void ScFDist_LT(); void ScChiDist(); // for LEGACY.CHIDIST, returns right tail @@ -761,7 +763,7 @@ void ScBetaDist(); void ScBetaDist_MS(); void ScFInv(); void ScFInv_LT(); -void ScTInv(); +void ScTInv( int nType ); void ScChiInv(); void ScBetaInv(); void ScCritBinom(); @@ -825,7 +827,7 @@ double GetUpRegIGamma(double fA,double fX); // upper regularized incomplete double GetGammaDistPDF(double fX, double fAlpha, double fLambda); // cumulative distribution function; fLambda is "scale" parameter double GetGammaDist(double fX, double fAlpha, double fLambda); -double GetTInv( double fAlpha, double fSize ); +double GetTInv( double fAlpha, double fSize, int nType ); public: ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc, diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx index dce896588b3f..2a5d77005849 100644 --- a/sc/source/core/tool/interpr3.cxx +++ b/sc/source/core/tool/interpr3.cxx @@ -633,9 +633,23 @@ double ScInterpreter::GetFDist(double x, double fF1, double fF2) return (GetBetaDist(arg, alpha, beta)); } -double ScInterpreter::GetTDist(double T, double fDF) +double ScInterpreter::GetTDist( double T, double fDF, int nType ) { - return 0.5 * GetBetaDist(fDF/(fDF+T*T), fDF/2.0, 0.5); + switch ( nType ) + { + case 1 : // 1-tailed T-distribution + return 0.5 * GetBetaDist( fDF / ( fDF + T * T ), fDF / 2.0, 0.5 ); + case 2 : // 2-tailed T-distribution + return GetBetaDist( fDF / ( fDF + T * T ), fDF / 2.0, 0.5); + case 3 : // left-tailed T-distribution (probability density function) + return pow( 1 + ( T * T / fDF ), -( fDF + 1 ) / 2 ) / ( sqrt( fDF ) * GetBeta( 0.5, fDF / 2.0 ) ); + case 4 : // left-tailed T-distribution (cumulative distribution function) + double X = fDF / ( T * T + fDF ); + double R = 0.5 * GetBetaDist( X, 0.5 * fDF, 0.5 ); + return ( T < 0 ? R : 1 - R ); + } + SetError( errIllegalArgument ); + return HUGE_VAL; } // for LEGACY.CHIDIST, returns right tail, fDF=degrees of freedom @@ -1614,11 +1628,36 @@ void ScInterpreter::ScTDist() PushIllegalArgument(); return; } - double R = GetTDist(T, fDF); - if (fFlag == 1.0) - PushDouble(R); - else - PushDouble(2.0*R); + PushDouble( GetTDist( T, fDF, ( int )fFlag ) ); +} + +void ScInterpreter::ScTDist_T( int nTails ) +{ + if ( !MustHaveParamCount( GetByte(), 2 ) ) + return; + double fDF = ::rtl::math::approxFloor( GetDouble() ); + double T = GetDouble(); + if ( fDF < 1.0 || T < 0.0 ) + { + PushIllegalArgument(); + return; + } + PushDouble( GetTDist( T, fDF, nTails ) ); +} + +void ScInterpreter::ScTDist_MS() +{ + if ( !MustHaveParamCount( GetByte(), 3 ) ) + return; + bool bCumulative = GetBool(); + double fDF = ::rtl::math::approxFloor( GetDouble() ); + double T = GetDouble(); + if ( fDF < 1.0 ) + { + PushIllegalArgument(); + return; + } + PushDouble( GetTDist( T, fDF, ( bCumulative ? 4 : 3 ) ) ); } void ScInterpreter::ScFDist() @@ -2214,34 +2253,43 @@ class ScTDistFunction : public ScDistFunc { ScInterpreter& rInt; double fp, fDF; + int nT; public: - ScTDistFunction( ScInterpreter& rI, double fpVal, double fDFVal ) : - rInt(rI), fp(fpVal), fDF(fDFVal) {} + ScTDistFunction( ScInterpreter& rI, double fpVal, double fDFVal, int nType ) : + rInt( rI ), fp( fpVal ), fDF( fDFVal ), nT( nType ) {} virtual ~ScTDistFunction() {} - double GetValue( double x ) const { return fp - 2 * rInt.GetTDist(x, fDF); } + double GetValue( double x ) const { return fp - rInt.GetTDist( x, fDF, nT ); } }; -void ScInterpreter::ScTInv() +void ScInterpreter::ScTInv( int nType ) { if ( !MustHaveParamCount( GetByte(), 2 ) ) return; double fDF = ::rtl::math::approxFloor(GetDouble()); double fP = GetDouble(); - if (fDF < 1.0 || fDF > 1.0E10 || fP <= 0.0 || fP > 1.0 ) + if (fDF < 1.0 || fP <= 0.0 || fP > 1.0 ) { PushIllegalArgument(); return; } - PushDouble( GetTInv( fP, fDF ) ); + if ( nType == 4 ) // left-tailed cumulative t-distribution + { + if ( fP < 0.5 ) + PushDouble( -GetTInv( 1 - fP, fDF, nType ) ); + else + PushDouble( GetTInv( fP, fDF, nType ) ); + } + else + PushDouble( GetTInv( fP, fDF, nType ) ); }; -double ScInterpreter::GetTInv( double fAlpha, double fSize ) +double ScInterpreter::GetTInv( double fAlpha, double fSize, int nType ) { bool bConvError; - ScTDistFunction aFunc( *this, fAlpha, fSize ); + ScTDistFunction aFunc( *this, fAlpha, fSize, nType ); double fVal = lcl_IterateInverse( aFunc, fSize * 0.5, fSize, bConvError ); if (bConvError) SetError(errNoConvergence); @@ -2397,7 +2445,7 @@ void ScInterpreter::ScConfidenceT() if (sigma <= 0.0 || alpha <= 0.0 || alpha >= 1.0 || n < 1.0) PushIllegalArgument(); else - PushDouble( sigma * GetTInv( alpha, n - 1 ) / sqrt( n ) ); + PushDouble( sigma * GetTInv( alpha, n - 1, 2 ) / sqrt( n ) ); } } @@ -2593,9 +2641,9 @@ void ScInterpreter::ScTTest() { if ( !MustHaveParamCount( GetByte(), 4 ) ) return; - double fTyp = ::rtl::math::approxFloor(GetDouble()); - double fAnz = ::rtl::math::approxFloor(GetDouble()); - if (fAnz != 1.0 && fAnz != 2.0) + double fTyp = ::rtl::math::approxFloor(GetDouble()); + double fTails = ::rtl::math::approxFloor(GetDouble()); + if (fTails != 1.0 && fTails != 2.0) { PushIllegalArgument(); return; @@ -2662,10 +2710,7 @@ void ScInterpreter::ScTTest() PushIllegalArgument(); return; } - if (fAnz == 1.0) - PushDouble(GetTDist(fT, fF)); - else - PushDouble(2.0*GetTDist(fT, fF)); + PushDouble( GetTDist( fT, fF, ( int )fTails ) ); } void ScInterpreter::ScFTest() diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index b77166d28f6d..6b38b5f202ea 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -4116,6 +4116,9 @@ StackVar ScInterpreter::Interpret() case ocLogNormDist : ScLogNormDist( 1 ); break; case ocLogNormDist_MS : ScLogNormDist( 4 ); break; case ocTDist : ScTDist(); break; + case ocTDist_MS : ScTDist_MS(); break; + case ocTDist_RT : ScTDist_T( 1 ); break; + case ocTDist_2T : ScTDist_T( 2 ); break; case ocFDist : case ocFDist_RT : ScFDist(); break; case ocFDist_LT : ScFDist_LT(); break; @@ -4141,7 +4144,8 @@ StackVar ScInterpreter::Interpret() case ocNoName : ScNoName(); break; case ocBad : ScBadName(); break; case ocZTest : ScZTest(); break; - case ocTTest : ScTTest(); break; + case ocTTest : + case ocTTest_MS : ScTTest(); break; case ocFTest : case ocFTest_MS : ScFTest(); break; case ocRank : ScRank(); break; @@ -4187,7 +4191,9 @@ StackVar ScInterpreter::Interpret() case ocChiInv_MS : ScChiInv(); break; case ocChiSqInv : case ocChiSqInv_MS : ScChiSqInv(); break; - case ocTInv : ScTInv(); break; + case ocTInv : + case ocTInv_2T : ScTInv( 2 ); break; + case ocTInv_MS : ScTInv( 4 ); break; case ocFInv : case ocFInv_RT : ScFInv(); break; case ocFInv_LT : ScFInv_LT(); break; diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx index bf335a7be149..66f0d10426ae 100644 --- a/sc/source/filter/excel/xlformula.cxx +++ b/sc/source/filter/excel/xlformula.cxx @@ -463,7 +463,13 @@ static const XclFunctionInfo saFuncTable_2010[] = EXC_FUNCENTRY_V_VR( ocNormDist_MS, 4, 4, 0, "NORM.DIST" ), EXC_FUNCENTRY_V_VR( ocNormInv_MS, 3, 3, 0, "NORM.INV" ), EXC_FUNCENTRY_V_VR( ocStdNormDist_MS, 2, 2, 0, "NORM.S.DIST" ), - EXC_FUNCENTRY_V_VR( ocSNormInv_MS, 1, 1, 0, "NORM.S.INV" ) + EXC_FUNCENTRY_V_VR( ocSNormInv_MS, 1, 1, 0, "NORM.S.INV" ), + EXC_FUNCENTRY_V_VR( ocTDist_2T, 2, 2, 0, "T.DIST.2T" ), + EXC_FUNCENTRY_V_VR( ocTDist_MS, 3, 3, 0, "T.DIST" ), + EXC_FUNCENTRY_V_VR( ocTDist_RT, 2, 2, 0, "T.DIST.RT" ), + EXC_FUNCENTRY_V_VR( ocTInv_2T, 2, 2, 0, "T.INV.2T" ), + EXC_FUNCENTRY_V_VR( ocTInv_MS, 2, 2, 0, "T.INV" ), + EXC_FUNCENTRY_V_VR( ocTTest_MS, 4, 4, 0, "T.TEST" ) }; /** Functions new in Excel 2013. diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx index 63d5006467be..f0dd1ed1eac2 100644 --- a/sc/source/filter/oox/formulabase.cxx +++ b/sc/source/filter/oox/formulabase.cxx @@ -781,7 +781,13 @@ static const FunctionData saFuncTable2010[] = { "COM.MICROSOFT.NORM.DIST", "NORM.DIST", NOID, NOID, 4, 4, V, { VR }, FUNCFLAG_MACROCALL_NEW }, { "COM.MICROSOFT.NORM.INV", "NORM.INV", NOID, NOID, 3, 3, V, { VR }, FUNCFLAG_MACROCALL_NEW }, { "COM.MICROSOFT.NORM.S.DIST", "NORM.S.DIST", NOID, NOID, 2, 2, V, { VR }, FUNCFLAG_MACROCALL_NEW }, - { "COM.MICROSOFT.NORM.S.INV", "NORM.S.INV", NOID, NOID, 1, 1, V, { VR }, FUNCFLAG_MACROCALL_NEW } + { "COM.MICROSOFT.NORM.S.INV", "NORM.S.INV", NOID, NOID, 1, 1, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.DIST", "T.DIST", NOID, NOID, 3, 3, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.DIST.2T", "T.DIST.2T", NOID, NOID, 2, 2, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.DIST.RT", "T.DIST.RT", NOID, NOID, 2, 2, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.INV", "T.INV", NOID, NOID, 2, 2, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.INV.2T", "T.INV.2T", NOID, NOID, 2, 2, V, { VR }, FUNCFLAG_MACROCALL_NEW }, + { "COM.MICROSOFT.T.TEST", "T.TEST", NOID, NOID, 4, 4, V, { VA, VA, VR }, FUNCFLAG_MACROCALL_NEW } }; /** Functions new in Excel 2013. diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src index 3f2e710956e2..cedf6328868d 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -7601,6 +7601,110 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 Text [ en-US ] = "Mode = 1 calculates the one-tailed test, 2 = two-tailed distribution." ; }; }; + // -=*# Resource for function T.DIST.2T #*=- + Resource SC_OPCODE_T_DIST_2T + { + String 1 // Description + { + Text [ en-US ] = "Returns the two-tailed t-distribution." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TDIST_2T ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The value for which the T distribution is to be calculated." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "degrees_freedom" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The degrees of freedom of the T distribution." ; + }; + }; + // -=*# Resource for function T.DIST #*=- + Resource SC_OPCODE_T_DIST_MS + { + String 1 // Description + { + Text [ en-US ] = "Returns the t-distribution." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TDIST_MS ); + 3; 0; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The value for which the T distribution is to be calculated." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "degrees_freedom" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The degrees of freedom of the T distribution." ; + }; + String 6 // Name of Parameter 3 + { + Text [ en-US ] = "cumulative" ; + }; + String 7 // Description of Parameter 3 + { + Text [ en-US ] = "True calculates the cumulative distribution function, false the probability density function." ; + }; + }; + // -=*# Resource for function T.DIST.RT #*=- + Resource SC_OPCODE_T_DIST_RT + { + String 1 // Description + { + Text [ en-US ] = "Returns the right-tailed t-distribution." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TDIST_RT ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "Number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The value for which the T distribution is to be calculated." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "degrees_freedom" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The degrees of freedom of the T distribution." ; + }; + }; // -=*# Resource for function TINV #*=- Resource SC_OPCODE_T_INV { @@ -7633,6 +7737,70 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 Text [ en-US ] = "The degrees of freedom of the T distribution." ; }; }; + // -=*# Resource for function T.INV #*=- + Resource SC_OPCODE_T_INV_MS + { + String 1 // Description + { + Text [ en-US ] = "Values of the left-tailed inverse t-distribution." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TINV_MS ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The probability value for which the inverse T distribution is to be calculated." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "degrees_freedom" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The degrees of freedom of the T distribution." ; + }; + }; + // -=*# Resource for function T.INV.2T #*=- + Resource SC_OPCODE_T_INV_2T + { + String 1 // Description + { + Text [ en-US ] = "Values of the two-tailed inverse t-distribution." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TINV_2T ); + 2; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "number" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The probability value for which the inverse T distribution is to be calculated." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "degrees_freedom" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The degrees of freedom of the T distribution." ; + }; + }; // -=*# Resource for function FVERT #*=- Resource SC_OPCODE_F_DIST { @@ -8602,6 +8770,54 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 Text [ en-US ] = "The type of the T test." ; }; }; + // -=*# Resource for function T.TEST #*=- + Resource SC_OPCODE_T_TEST_MS + { + String 1 // Description + { + Text [ en-US ] = "Calculates the T test." ; + }; + ExtraData = + { + 0; + ID_FUNCTION_GRP_STATISTIC; + U2S( HID_FUNC_TTEST_MS ); + 4; 0; 0; 0; 0; + 0; + }; + String 2 // Name of Parameter 1 + { + Text [ en-US ] = "data_1" ; + }; + String 3 // Description of Parameter 1 + { + Text [ en-US ] = "The first record array." ; + }; + String 4 // Name of Parameter 2 + { + Text [ en-US ] = "data_2" ; + }; + String 5 // Description of Parameter 2 + { + Text [ en-US ] = "The second record array." ; + }; + String 6 // Name of Parameter 3 + { + Text [ en-US ] = "mode" ; + }; + String 7 // Description of Parameter 3 + { + Text [ en-US ] = "Mode specifies the number of distribution tails to return. 1= one-tailed, 2 = two-tailed distribution" ; + }; + String 8 // Name of Parameter 4 + { + Text [ en-US ] = "Type" ; + }; + String 9 // Description of Parameter 4 + { + Text [ en-US ] = "The type of the T test." ; + }; + }; // -=*# Resource for function BESTIMMTHEITSMASS #*=- Resource SC_OPCODE_RSQ { |