mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
bpo-40780: Fix failure of _Py_dg_dtoa to remove trailing zeros (GH-20435) (GH-20514)
* Fix failure of _Py_dg_dtoa to remove trailing zeros
* Add regression test and news entry
* Add explanation about why it's safe to strip trailing zeros
* Make code safer, clean up comments, add change note at top of file
* Nitpick: avoid implicit int-to-float conversion in tests
(cherry picked from commit 895c9c1d43
)
Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
This commit is contained in:
parent
8fcc1474ef
commit
ad088ca5c6
3 changed files with 24 additions and 0 deletions
|
@ -484,6 +484,17 @@ class FormatTest(unittest.TestCase):
|
|||
with self.assertRaises(ValueError) as cm:
|
||||
format(c, ".%sf" % (INT_MAX + 1))
|
||||
|
||||
def test_g_format_has_no_trailing_zeros(self):
|
||||
# regression test for bugs.python.org/issue40780
|
||||
self.assertEqual("%.3g" % 1505.0, "1.5e+03")
|
||||
self.assertEqual("%#.3g" % 1505.0, "1.50e+03")
|
||||
|
||||
self.assertEqual(format(1505.0, ".3g"), "1.5e+03")
|
||||
self.assertEqual(format(1505.0, "#.3g"), "1.50e+03")
|
||||
|
||||
self.assertEqual(format(12300050.0, ".6g"), "1.23e+07")
|
||||
self.assertEqual(format(12300050.0, "#.6g"), "1.23000e+07")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue