partial implementation FLOOR.MATH function (needs more testing and bad param support)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-05-23 14:02:47 +00:00
parent 769fc25e64
commit 78ddaabbc2
2 changed files with 8 additions and 2 deletions

View File

@ -62,12 +62,14 @@ public final class FloorMath implements FreeRefFunction {
} }
if (roundNegativeNumsDown && xval < 0.0) { if (roundNegativeNumsDown && xval < 0.0) {
if (multiplier != 1.0) { 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)); return new NumberEval(Math.ceil(xval));
} }
if (multiplier != 1.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)); return new NumberEval(Math.floor(xval));
} catch (EvaluationException evaluationException) { } catch (EvaluationException evaluationException) {

View File

@ -47,6 +47,10 @@ final class TestFloorMath {
assertDouble(fe, cell, "FLOOR.MATH(6.7)", 6.0, 0.00000000000001); assertDouble(fe, cell, "FLOOR.MATH(6.7)", 6.0, 0.00000000000001);
assertDouble(fe, cell, "FLOOR.MATH(-8.1,2)", -10.0, 0.00000000000001); assertDouble(fe, cell, "FLOOR.MATH(-8.1,2)", -10.0, 0.00000000000001);
assertDouble(fe, cell, "FLOOR.MATH(-5.5,2,-1)", -4.0, 0.00000000000001); assertDouble(fe, cell, "FLOOR.MATH(-5.5,2,-1)", -4.0, 0.00000000000001);
assertDouble(fe, cell, "FLOOR.MATH(-2.5,-2)", -4.0, 0.00000000000001);
assertDouble(fe, cell, "FLOOR.MATH(-2.5,-2,-1)", -2.0, 0.00000000000001);
assertDouble(fe, cell, "FLOOR.MATH(2.5,-2)", 2.0, 0.00000000000001);
} }
} }