aboutsummaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
authorDamien George2017-06-13 13:36:56 +1000
committerDamien George2017-06-13 13:36:56 +1000
commit6ed4581f545069488446682ee9b052798626327d (patch)
tree757e98d329b1afa57c7b31d68b85709141d74dd9 /tests/float
parentd42b80fd648d74e2c6f66626e904103091ee9334 (diff)
py/formatfloat: Fix number of digits and exponent sign when rounding.
This patch fixes 2 things when printing a floating-point number that requires rounding up of the mantissa: - retain the correct precision; eg 0.99 becomes 1.0, not 1.00 - if the exponent goes from -1 to 0 then render it as +0, not -0
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/string_format_modulo.py3
-rw-r--r--tests/float/string_format_modulo3.py3
-rw-r--r--tests/float/string_format_modulo3.py.exp3
3 files changed, 5 insertions, 4 deletions
diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py
index 03c8dd00a..aea534247 100644
--- a/tests/float/string_format_modulo.py
+++ b/tests/float/string_format_modulo.py
@@ -44,3 +44,6 @@ print(('%.40g' % 1e-3)[:2])
print(('%.40g' % 1e-4)[:2])
print("%.0g" % 1) # 0 precision 'g'
+
+print('%.1e' % 9.99) # round up with positive exponent
+print('%.1e' % 0.999) # round up with negative exponent
diff --git a/tests/float/string_format_modulo3.py b/tests/float/string_format_modulo3.py
index 563964786..5d26f2575 100644
--- a/tests/float/string_format_modulo3.py
+++ b/tests/float/string_format_modulo3.py
@@ -1,4 +1,3 @@
# uPy and CPython outputs differ for the following
print("%.1g" % -9.9) # round up 'g' with '-' sign
-print("%.1e" % 9.99) # round up with positive exponent
-print("%.1e" % 0.999) # round up with negative exponent
+print("%.2g" % 99.9) # round up
diff --git a/tests/float/string_format_modulo3.py.exp b/tests/float/string_format_modulo3.py.exp
index b158c7d7f..71432b340 100644
--- a/tests/float/string_format_modulo3.py.exp
+++ b/tests/float/string_format_modulo3.py.exp
@@ -1,3 +1,2 @@
-10
-1.00e+01
-1.00e-00
+100