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

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

View 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) {

View 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);
}
}