Author: fanningpj
Date: Fri Oct 22 09:03:46 2021
New Revision: 1894469

URL: http://svn.apache.org/viewvc?rev=1894469&view=rev
Log:
fix negative X on T.DIST.RT

Added:
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistLt.java
      - copied, changed from r1894468, 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java
Modified:
    
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java
    
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java?rev=1894469&r1=1894468&r2=1894469&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java 
(original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java 
Fri Oct 22 09:03:46 2021
@@ -173,6 +173,7 @@ public final class AnalysisToolPak imple
         r(m, "TBILLEQ", null);
         r(m, "TBILLPRICE", null);
         r(m, "TBILLYIELD", null);
+        r(m, "T.DIST", TDistLt.instance);
         r(m, "T.DIST.2T", TDist2t.instance);
         r(m, "T.DIST.RT", TDistRt.instance);
         r(m, "TEXTJOIN", TextJoinFunction.instance);

Copied: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistLt.java 
(from r1894468, 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java)
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistLt.java?p2=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistLt.java&p1=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java&r1=1894468&r2=1894469&rev=1894469&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java 
(original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistLt.java 
Fri Oct 22 09:03:46 2021
@@ -17,16 +17,15 @@
 
 package org.apache.poi.ss.formula.functions;
 
-import org.apache.commons.math3.distribution.TDistribution;
 import org.apache.poi.ss.formula.OperationEvaluationContext;
 import org.apache.poi.ss.formula.eval.*;
 
 /**
- * Implementation for Excel T.DIST.RT() function.
+ * Implementation for Excel T.DIST() function.
  * <p>
- * <b>Syntax</b>:<br> <b>T.DIST.RT </b>(<b>X</b>,<b>Deg_freedom</b>)<br>
+ * <b>Syntax</b>:<br> <b>T.DIST 
</b>(<b>X</b>,<b>Deg_freedom</b>,<b>Cumulative</b>)<br>
  * <p>
- * Returns the right-tailed Student's t-distribution.
+ * Returns the Student's left-tailed t-distribution.
  *
  * The t-distribution is used in the hypothesis testing of small sample data 
sets.
  * Use this function in place of a table of critical values for the 
t-distribution.
@@ -34,22 +33,24 @@ import org.apache.poi.ss.formula.eval.*;
  * <ul>
  *     <li>X     Required. The numeric value at which to evaluate the 
distribution.</li>
  *     <li>Deg_freedom     Required. An integer indicating the number of 
degrees of freedom.</li>
+ *     <li>Cumulative      Required. A logical value that determines the form 
of the function. If cumulative is TRUE,
+ *     T.DIST returns the cumulative distribution function; if FALSE, it 
returns the probability density function.</li>
  * </ul>
  *
  * <ul>
- *     <li>If any argument is non-numeric, T.DIST.RT returns the #VALUE! error 
value.</li>
- *     <li>If Deg_freedom &lt; 1, T.DIST.RT returns the #NUM! error value.</li>
+ *     <li>If any argument is non-numeric, T.DIST returns the #VALUE! error 
value.</li>
+ *     <li>If Deg_freedom &lt; 1, T.DIST returns the #NUM! error value.</li>
  *     <li>The Deg_freedom argument is truncated to an integer.
  * </ul>
  *
  * 
https://support.microsoft.com/en-us/office/t-dist-rt-function-20a30020-86f9-4b35-af1f-7ef6ae683eda
  */
-public final class TDistRt extends Fixed2ArgFunction implements 
FreeRefFunction {
+public final class TDistLt extends Fixed3ArgFunction implements 
FreeRefFunction {
 
-    public static final TDistRt instance = new TDistRt();
+    public static final TDistLt instance = new TDistLt();
 
     @Override
-    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval 
arg1, ValueEval arg2) {
+    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval 
arg1, ValueEval arg2, ValueEval arg3) {
         try {
             Double number1 = evaluateValue(arg1, srcRowIndex, srcColumnIndex);
             if (number1 == null) {
@@ -71,8 +72,8 @@ public final class TDistRt extends Fixed
 
     @Override
     public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) 
{
-         if (args.length == 2) {
-            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], 
args[1]);
+         if (args.length == 3) {
+            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], 
args[1], args[2]);
         }
 
         return ErrorEval.VALUE_INVALID;

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java?rev=1894469&r1=1894468&r2=1894469&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java 
(original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java 
Fri Oct 22 09:03:46 2021
@@ -17,7 +17,6 @@
 
 package org.apache.poi.ss.formula.functions;
 
-import org.apache.commons.math3.distribution.TDistribution;
 import org.apache.poi.ss.formula.OperationEvaluationContext;
 import org.apache.poi.ss.formula.eval.*;
 
@@ -63,7 +62,7 @@ public final class TDistRt extends Fixed
             if (degreesOfFreedom < 1) {
                 return ErrorEval.NUM_ERROR;
             }
-            return new NumberEval(TDist.tdistOneTail(Math.abs(number1), 
degreesOfFreedom));
+            return new NumberEval(TDist.tdistOneTail(number1, 
degreesOfFreedom));
         } catch (EvaluationException e) {
             return e.getErrorEval();
         }

Modified: 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java?rev=1894469&r1=1894468&r2=1894469&view=diff
==============================================================================
--- 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java
 (original)
+++ 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java
 Fri Oct 22 09:03:46 2021
@@ -46,7 +46,7 @@ final class TestTDistRt {
         confirmValue("5.968191467", "8", 0.00016754180265310392);
         confirmValue("5.968191467", "8.2", 0.00016754180265310392);
         confirmValue("5.968191467", "8.9", 0.00016754180265310392);
-        confirmValue("-5.968191467", "8", 0.00016754180265310392);
+        confirmValue("-5.968191467", "8", 0.999832458, 0.01);
     }
 
     @Test
@@ -72,7 +72,7 @@ final class TestTDistRt {
             HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
             HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100);
             assertDouble(fe, cell, "T.DIST.RT(A2,A3)", 0.027322465, 0.01);
-            assertDouble(fe, cell, "T.DIST.RT(-A2,A3)", 0.027322465, 0.01);
+            assertDouble(fe, cell, "T.DIST.RT(-A2,A3)", 0.972677535, 0.01);
         }
     }
 
@@ -82,9 +82,13 @@ final class TestTDistRt {
     }
 
     private static void confirmValue(String number1, String number2, double 
expected) {
+        confirmValue(number1, number2, expected, 0.0);
+    }
+
+    private static void confirmValue(String number1, String number2, double 
expected, double tolerance) {
         ValueEval result = invokeValue(number1, number2);
         assertEquals(NumberEval.class, result.getClass());
-        assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
+        assertEquals(expected, ((NumberEval) result).getNumberValue(), 
tolerance);
     }
 
     private static void confirmInvalidError(String number1, String number2) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to