You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/10/19 16:18:53 UTC

svn commit: r1894384 - in /poi/trunk/poi/src: main/java/org/apache/poi/ss/formula/atp/ main/java/org/apache/poi/ss/formula/functions/ test/java/org/apache/poi/ss/formula/functions/

Author: fanningpj
Date: Tue Oct 19 16:18:52 2021
New Revision: 1894384

URL: http://svn.apache.org/viewvc?rev=1894384&view=rev
Log:
add TDIST.2T support

Added:
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist2t.java
      - copied, changed from r1894383, 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/TestTDist2t.java
      - copied, changed from r1894383, 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
    poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist.java
    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
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java?rev=1894384&r1=1894383&r2=1894384&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 Tue Oct 19 16:18:52 2021
@@ -173,6 +173,7 @@ public final class AnalysisToolPak imple
         r(m, "TBILLEQ", null);
         r(m, "TBILLPRICE", null);
         r(m, "TBILLYIELD", null);
+        r(m, "TDIST.2T", TDist2t.instance);
         r(m, "TDIST.RT", TDistRt.instance);
         r(m, "TEXTJOIN", TextJoinFunction.instance);
         r(m, "WEEKNUM", WeekNum.instance);

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist.java?rev=1894384&r1=1894383&r2=1894384&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist.java Tue Oct 19 16:18:52 2021
@@ -45,6 +45,8 @@ import org.apache.poi.ss.formula.eval.*;
  *     <li>If Tails is any value other than 1 or 2, TDIST returns the #NUM! error value.</li>
  *     <li>If x &lt; 0, then TDIST returns the #NUM! error value.</li>
  * </ul>
+ *
+ * https://support.microsoft.com/en-us/office/tdist-function-630a7695-4021-4853-9468-4a1f9dcdd192
  */
 public final class TDist extends Fixed3ArgFunction implements FreeRefFunction {
 

Copied: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist2t.java (from r1894383, 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/TDist2t.java?p2=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDist2t.java&p1=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TDistRt.java&r1=1894383&r2=1894384&rev=1894384&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/TDist2t.java Tue Oct 19 16:18:52 2021
@@ -17,18 +17,17 @@
 
 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 TDIST.RT() function.
+ * Implementation for Excel TDIST.2T() function.
  * <p>
- * <b>Syntax</b>:<br> <b>TDIST.RT </b>(<b>X</b>,<b>Deg_freedom</b>)<br>
+ * <b>Syntax</b>:<br> <b>TDIST.2T </b>(<b>X</b>,<b>Deg_freedom</b>)<br>
  * <p>
- * Returns the right-tailed Student's t-distribution.
+ * Returns the two-tailed Student's t-distribution.
  *
- * The t-distribution is used in the hypothesis testing of small sample data sets.
+ * The Student's 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.
  *
  * <ul>
@@ -37,14 +36,17 @@ import org.apache.poi.ss.formula.eval.*;
  * </ul>
  *
  * <ul>
- *     <li>If any argument is non-numeric, TDIST.RT returns the #VALUE! error value.</li>
- *     <li>If Deg_freedom &lt; 1, TDIST.RT returns the #NUM! error value.</li>
+ *     <li>If any argument is non-numeric, TDIST.2T returns the #VALUE! error value.</li>
+ *     <li>If Deg_freedom &lt; 1, TDIST.2T returns the #NUM! error value.</li>
+ *     <li>If x &lt; 0, then T.DIST.2T 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-2t-function-198e9340-e360-4230-bd21-f52f22ff5c28
  */
-public final class TDistRt extends Fixed2ArgFunction implements FreeRefFunction {
+public final class TDist2t extends Fixed2ArgFunction implements FreeRefFunction {
 
-    public static final TDistRt instance = new TDistRt();
+    public static final TDist2t instance = new TDist2t();
 
     @Override
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg1, ValueEval arg2) {
@@ -52,6 +54,8 @@ public final class TDistRt extends Fixed
             Double number1 = evaluateValue(arg1, srcRowIndex, srcColumnIndex);
             if (number1 == null) {
                 return ErrorEval.VALUE_INVALID;
+            } else if (number1 < 0) {
+                return ErrorEval.NUM_ERROR;
             }
             Double number2 = evaluateValue(arg2, srcRowIndex, srcColumnIndex);
             if (number2 == null) {
@@ -61,7 +65,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.tdistTwoTails(Math.abs(number1), degreesOfFreedom));
         } catch (EvaluationException e) {
             return e.getErrorEval();
         }

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=1894384&r1=1894383&r2=1894384&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 Tue Oct 19 16:18:52 2021
@@ -41,6 +41,8 @@ import org.apache.poi.ss.formula.eval.*;
  *     <li>If Deg_freedom &lt; 1, TDIST.RT 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 {
 

Copied: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDist2t.java (from r1894383, 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/TestTDist2t.java?p2=poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDist2t.java&p1=poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTDistRt.java&r1=1894383&r2=1894384&rev=1894384&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/TestTDist2t.java Tue Oct 19 16:18:52 2021
@@ -35,18 +35,17 @@ import static org.apache.poi.ss.util.Uti
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
- * Tests for {@link TDistRt}
+ * Tests for {@link TDist2t}
  */
-final class TestTDistRt {
+final class TestTDist2t {
 
     private static final OperationEvaluationContext ec = new OperationEvaluationContext(null, null, 0, 0, 0, null);
 
     @Test
     void testBasic() {
-        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.00033508360530620784);
+        confirmValue("5.968191467", "8.2", 0.00033508360530620784);
+        confirmValue("5.968191467", "8.9", 0.00033508360530620784);
     }
 
     @Test
@@ -58,10 +57,11 @@ final class TestTDistRt {
 
     @Test
     void testNumError() {
-        confirmNumError("-5.968191467", "-8");
+        confirmNumError("-5.968191467", "8");
+        confirmNumError("5.968191467", "-8");
     }
 
-    //https://support.microsoft.com/en-us/office/t-dist-rt-function-20a30020-86f9-4b35-af1f-7ef6ae683eda
+    //https://support.microsoft.com/en-us/office/t-dist-2t-function-198e9340-e360-4230-bd21-f52f22ff5c28
     @Test
     void testMicrosoftExample1() throws IOException {
         try (HSSFWorkbook wb = new HSSFWorkbook()) {
@@ -71,14 +71,13 @@ final class TestTDistRt {
             addRow(sheet, 2, 60, "Degrees of freedom");
             HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
             HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100);
-            assertDouble(fe, cell, "TDIST.RT(A2,A3)", 0.027322465, 0.01);
-            assertDouble(fe, cell, "TDIST.RT(-A2,A3)", 0.027322465, 0.01);
+            assertDouble(fe, cell, "TDIST.2T(A2,A3)", 0.054644930, 0.01);
         }
     }
 
     private static ValueEval invokeValue(String number1, String number2) {
         ValueEval[] args = new ValueEval[] { new StringEval(number1), new StringEval(number2) };
-        return TDistRt.instance.evaluate(args, ec);
+        return TDist2t.instance.evaluate(args, ec);
     }
 
     private static void confirmValue(String number1, String number2, double expected) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org