]> source.dussan.org Git - poi.git/commitdiff
partial implementation CEILING.MATH function (needs more testing and bad param support)
authorPJ Fanning <fanningpj@apache.org>
Mon, 23 May 2022 14:09:07 +0000 (14:09 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 23 May 2022 14:09:07 +0000 (14:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901174 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/formula/functions/CeilingMath.java
poi/src/test/java/org/apache/poi/ss/formula/functions/TestCeilingMath.java

index 6c84abfea0879f5628546c6349e68f2cf96c5012..a5784c5f32c50cb922cb5434ec0ffb7c6ffe716b 100644 (file)
@@ -62,12 +62,14 @@ public final class CeilingMath implements FreeRefFunction {
             }
             if (roundNegativeNumsDown && xval < 0.0) {
                 if (multiplier != 1.0) {
-                    return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, RoundingMode.FLOOR));
+                    RoundingMode mode = multiplier < 0.0 ? RoundingMode.CEILING : RoundingMode.FLOOR;
+                    return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, mode));
                 }
                 return new NumberEval(Math.floor(xval));
             }
             if (multiplier != 1.0) {
-                return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, RoundingMode.CEILING));
+                RoundingMode mode = multiplier < 0.0 ? RoundingMode.FLOOR : RoundingMode.CEILING;
+                return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, mode));
             }
             return new NumberEval(Math.ceil(xval));
         } catch (EvaluationException evaluationException) {
index 5780f58562ac4d45a7391e302d621fb7e9ae0fdb..9eb744ccb6ffa550aca0f46876e53766fab97a1a 100644 (file)
@@ -47,6 +47,11 @@ final class TestCeilingMath {
             assertDouble(fe, cell, "CEILING.MATH(6.7)", 7.0, 0.00000000000001);
             assertDouble(fe, cell, "CEILING.MATH(-8.1,2)", -8.0, 0.00000000000001);
             assertDouble(fe, cell, "CEILING.MATH(-5.5,2,-1)", -6.0, 0.00000000000001);
+
+            assertDouble(fe, cell, "CEILING.MATH(2.5,-2)", 4.0, 0.00000000000001);
+            assertDouble(fe, cell, "CEILING.MATH(-2.5,-2)", -2.0, 0.00000000000001);
+            assertDouble(fe, cell, "CEILING.MATH(-2.5,-2,-1)", -4.0, 0.00000000000001);
+            assertDouble(fe, cell, "CEILING.MATH(0.234, 0.01)", 0.24, 0.00000000000001);
         }
     }