[FXJS] Use double precision when converting textboxes
The conversion of string to a floating point number was using single
precision, which introduced noticeable precision error. Change to use
double precision so less error is introduced.
Bug: chromium:611744
Change-Id: I5af14aacef3f19bc62f96c23cb6f1c0254631246
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60811
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index b97c2af..bd17de0 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -1312,7 +1312,7 @@
WideString trimmed = pFormField->GetValue();
trimmed.TrimRight();
trimmed.TrimLeft();
- dTemp = StringToFloat(trimmed.AsStringView());
+ dTemp = StringToDouble(trimmed.AsStringView());
break;
}
case FormFieldType::kPushButton:
diff --git a/testing/resources/javascript/public_methods.in b/testing/resources/javascript/public_methods.in
index 8fd9ee9..200b8ec 100644
--- a/testing/resources/javascript/public_methods.in
+++ b/testing/resources/javascript/public_methods.in
@@ -480,17 +480,13 @@
expectEventValue('', "AFSimple_Calculate('MIN', ['Text2', 'Text3'])", 123);
expectEventValue('', "AFSimple_Calculate('MAX', ['Text2', 'Text3'])", 456);
expectEventValue('', "AFSimple_Calculate('AVG', 'Text2, Text3')", (123 + 456) / 2);
- // The next 6 currently have rounding issues. https://crbug.com/611744.
expectEventValue('', "AFSimple_Calculate('AVG', ['Text4'])", 407.96);
expectEventValue('', "AFSimple_Calculate('SUM', ['Text4'])", 407.96);
expectEventValue('', "AFSimple_Calculate('MIN', ['Text4'])", 407.96);
expectEventValue('', "AFSimple_Calculate('MAX', ['Text4'])", 407.96);
expectEventValue('', "AFSimple_Calculate('AVG', ['Text2', 'Text4'])", (123 + 407.96) / 2);
expectEventValue('', "AFSimple_Calculate('SUM', ['Text2', 'Text4'])", 123 + 407.96);
- // Note: 123 * 407.96 = 50179.08, but Acrobat has rounding artifacts in
- // its implementation as well. It returns 50179.0799999999994, which is
- // effectively 50179.08.
- expectEventValue('', "AFSimple_Calculate('PRD', ['Text2', 'Text4'])", 50179.0799999999994);
+ expectEventValue('', "AFSimple_Calculate('PRD', ['Text2', 'Text4'])", 50179.08);
app.alert("**********************");
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt
index b7b60e6..c0ee226 100644
--- a/testing/resources/javascript/public_methods_expected.txt
+++ b/testing/resources/javascript/public_methods_expected.txt
@@ -318,13 +318,13 @@
Alert: PASS: AFSimple_Calculate('MIN', ['Text2', 'Text3']) = 123
Alert: PASS: AFSimple_Calculate('MAX', ['Text2', 'Text3']) = 456
Alert: PASS: AFSimple_Calculate('AVG', 'Text2, Text3') = 289.5
-Alert: FAIL: AFSimple_Calculate('AVG', ['Text4']) = 407.959991, expected 407.96
-Alert: FAIL: AFSimple_Calculate('SUM', ['Text4']) = 407.959991, expected 407.96
-Alert: FAIL: AFSimple_Calculate('MIN', ['Text4']) = 407.959991, expected 407.96
-Alert: FAIL: AFSimple_Calculate('MAX', ['Text4']) = 407.959991, expected 407.96
-Alert: FAIL: AFSimple_Calculate('AVG', ['Text2', 'Text4']) = 265.479996, expected 265.48
-Alert: FAIL: AFSimple_Calculate('SUM', ['Text2', 'Text4']) = 530.959991, expected 530.96
-Alert: FAIL: AFSimple_Calculate('PRD', ['Text2', 'Text4']) = 50179.078949, expected 50179.08
+Alert: PASS: AFSimple_Calculate('AVG', ['Text4']) = 407.96
+Alert: PASS: AFSimple_Calculate('SUM', ['Text4']) = 407.96
+Alert: PASS: AFSimple_Calculate('MIN', ['Text4']) = 407.96
+Alert: PASS: AFSimple_Calculate('MAX', ['Text4']) = 407.96
+Alert: PASS: AFSimple_Calculate('AVG', ['Text2', 'Text4']) = 265.48
+Alert: PASS: AFSimple_Calculate('SUM', ['Text2', 'Text4']) = 530.96
+Alert: PASS: AFSimple_Calculate('PRD', ['Text2', 'Text4']) = 50179.08
Alert: **********************
Alert: PASS: AFSpecial_Format() threw AFSpecial_Format: Incorrect number of parameters passed to function.
Alert: PASS: AFSpecial_Format(1, 2) threw AFSpecial_Format: Incorrect number of parameters passed to function.