Fix FormCalc Pmt() results.
Match the values from Acrobat Reader by performing the calculations
using doubles. Add more sample test cases, which now all pass.
Change-Id: Ibf3a2ebed591bd363e3c0bfa04e8f7610e6e4489
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90191
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 2d2dbb9..8bbecbb 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -2917,17 +2917,17 @@
return;
}
- float nPrincipal = ValueToFloat(info.GetIsolate(), argOne);
- float nRate = ValueToFloat(info.GetIsolate(), argTwo);
- float nPeriods = ValueToFloat(info.GetIsolate(), argThree);
+ double nPrincipal = ValueToDouble(info.GetIsolate(), argOne);
+ double nRate = ValueToDouble(info.GetIsolate(), argTwo);
+ double nPeriods = ValueToDouble(info.GetIsolate(), argThree);
if (nPrincipal <= 0 || nRate <= 0 || nPeriods <= 0 ||
- nPeriods > static_cast<float>(std::numeric_limits<int32_t>::max())) {
+ nPeriods > static_cast<double>(std::numeric_limits<int32_t>::max())) {
pContext->ThrowArgumentMismatchException();
return;
}
- float nTmp = 1 + nRate;
- float nSum = nTmp;
+ double nTmp = 1 + nRate;
+ double nSum = nTmp;
for (int32_t i = 0; i < nPeriods - 1; ++i)
nSum *= nTmp;
diff --git a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
index 79c8939..b5cca29 100644
--- a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
@@ -501,14 +501,13 @@
ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
ExecuteExpectFloat("Pmt(25000, 0.085, 12)", 3403.82145169876f);
+ ExecuteExpectFloat("Pmt(5000, 0.01, 1)", 5050);
+ ExecuteExpectFloat("Pmt(30000.00, .085 / 12, 12 * 12)", 333.01666929435f);
+ ExecuteExpectFloat("Pmt(10000, .08 / 12, 10)", 1037.03208935916f);
+ ExecuteExpectFloat("Pmt(150000, 0.0475 / 12, 25 * 12)", 855.17604207164f);
// https://crbug.com/1293179
ExecuteExpectError("Pmt(2, 2, 99999997952)");
-
-#if 0
- // TODO(thestig): Investigate this case.
- ExecuteExpectFloat("Pmt(150000, 0.0475 / 12, 25 * 12)", 855.17604207164f);
-#endif
}
TEST_F(CFXJSE_FormCalcContextEmbedderTest, PPmt) {