]> source.dussan.org Git - poi.git/commitdiff
support sqrtpi function
authorPJ Fanning <fanningpj@apache.org>
Sat, 30 Apr 2022 08:31:31 +0000 (08:31 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 30 Apr 2022 08:31:31 +0000 (08:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1900418 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/formula/functions/Sqrtpi.java
poi/src/test/java/org/apache/poi/ss/formula/functions/TestSqrtpi.java

index 18244c85043137a107c8fd7455ccaf39e221233a..dbd02b3c3bebfe9c0f7afbffca7145579fc0d735 100644 (file)
@@ -56,6 +56,8 @@ public class Sqrtpi implements FreeRefFunction {
                 return ErrorEval.NUM_ERROR;
             }
             final double result = Math.sqrt(Math.PI * d);
+            //NumberToTextConverter reduces the precision to what Excel uses internally
+            //without this conversion, `result` is too precise
             return new NumberEval(Double.parseDouble(NumberToTextConverter.toText(result)));
         } catch (EvaluationException e) {
             return e.getErrorEval();
index 4a2ed628c085eca1f59deafb6a6c981a4f42b1fb..7208f8dbcbeaad8d3f22420510aa589b19b6854f 100644 (file)
@@ -39,6 +39,7 @@ final class TestSqrtpi {
     //https://support.microsoft.com/en-us/office/sqrtpi-function-1fb4e63f-9b51-46d6-ad68-b3e7a8b519b4
     @Test
     void testBasic() {
+        //the expected values were observed in my copy of Excel
         confirmValue(Arrays.asList(1), 1.77245385090552);
         confirmValue(Arrays.asList(2), 2.506628274631);
     }