aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George2018-03-01 15:47:17 +1100
committerDamien George2018-03-01 15:51:03 +1100
commitbc12eca461a317df842ce2e616afa97670cd0ce3 (patch)
tree58d6bfd2ab1ba6e7ecd41730c03923f1dac932d2 /tests
parent90e719a232dbf4039085d4fea2faf1358e408e40 (diff)
py/formatfloat: Fix rounding of %f format with edge-case FP values.
Prior to this patch the %f formatting of some FP values could be off by up to 1, eg '%.0f' % 123 would return "122" (unix x64). Depending on the FP precision (single vs double) certain numbers would format correctly, but others wolud not. This patch should fix all cases of rounding for %f.
Diffstat (limited to 'tests')
-rw-r--r--tests/float/float_format.py11
-rw-r--r--tests/unix/extra_coverage.py.exp2
2 files changed, 12 insertions, 1 deletions
diff --git a/tests/float/float_format.py b/tests/float/float_format.py
new file mode 100644
index 000000000..4d5ad1d69
--- /dev/null
+++ b/tests/float/float_format.py
@@ -0,0 +1,11 @@
+# test float formatting
+
+# general rounding
+for val in (116, 1111, 1234, 5010, 11111):
+ print('%.0f' % val)
+ print('%.1f' % val)
+ print('%.3f' % val)
+
+# make sure rounding is done at the correct precision
+for prec in range(8):
+ print(('%%.%df' % prec) % 6e-5)
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index a030155ba..54e19d14a 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -56,7 +56,7 @@ Warning: test
+1e+00
+1e+00
# binary
-122
+123
456
# VM
2 1