summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-05-01 15:37:04 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-05-01 15:37:04 (GMT)
commit33841c34896834daa8ee38d3ff54d7800b9723c2 (patch)
tree1de0e45e427cc30b610fb4813e201ddef264e251 /Lib
parentf489caf5daa2b0f3a1bd951b585c834aab1a54c6 (diff)
downloadcpython-33841c34896834daa8ee38d3ff54d7800b9723c2.zip
cpython-33841c34896834daa8ee38d3ff54d7800b9723c2.tar.gz
cpython-33841c34896834daa8ee38d3ff54d7800b9723c2.tar.bz2
Issue #5859: Remove '%f' to '%g' formatting switch for large floats.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/formatfloat_testcases.txt2
-rw-r--r--Lib/test/test_types.py23
2 files changed, 20 insertions, 5 deletions
diff --git a/Lib/test/formatfloat_testcases.txt b/Lib/test/formatfloat_testcases.txt
index 287019f..4cf20aa 100644
--- a/Lib/test/formatfloat_testcases.txt
+++ b/Lib/test/formatfloat_testcases.txt
@@ -22,8 +22,8 @@
%.0f 123.456 -> 123
%.0f 1234.56 -> 1235
%.0f 1e49 -> 9999999999999999464902769475481793196872414789632
--- %.0f 1e50 -> 100000000000000007629769841091887003294964970946560
%.0f 9.9999999999999987e+49 -> 99999999999999986860582406952576489172979654066176
+%.0f 1e50 -> 100000000000000007629769841091887003294964970946560
-- precision 1
%.1f 0.0001 -> 0.0
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 230b102..b85d337 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -538,10 +538,25 @@ class TypesTests(unittest.TestCase):
test(-1.0, ' f', '-1.000000')
test( 1.0, '+f', '+1.000000')
test(-1.0, '+f', '-1.000000')
- test(1.1234e90, 'f', '1.1234e+90')
- test(1.1234e90, 'F', '1.1234e+90')
- test(1.1234e200, 'f', '1.1234e+200')
- test(1.1234e200, 'F', '1.1234e+200')
+
+ # Python versions <= 3.0 switched from 'f' to 'g' formatting for
+ # values larger than 1e50. No longer.
+ f = 1.1234e90
+ for fmt in 'f', 'F':
+ # don't do a direct equality check, since on some
+ # platforms only the first few digits of dtoa
+ # will be reliable
+ result = f.__format__(fmt)
+ self.assertEqual(len(result), 98)
+ self.assertEqual(result[-7], '.')
+ self.assert_(result[:12] in ('112340000000', '112339999999'))
+ f = 1.1234e200
+ for fmt in 'f', 'F':
+ result = f.__format__(fmt)
+ self.assertEqual(len(result), 208)
+ self.assertEqual(result[-7], '.')
+ self.assert_(result[:12] in ('112340000000', '112339999999'))
+
test( 1.0, 'e', '1.000000e+00')
test(-1.0, 'e', '-1.000000e+00')