mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Backport of r59456:59458 from py3k to trunk
Issue #1580: New free format floating point representation based on "Floating-Point Printer Sample Code", by Robert G. Burger. For example repr(11./5) now returns '2.2' instead of '2.2000000000000002'. Thanks to noam for the patch! I had to modify doubledigits.c slightly to support X64 and IA64 machines on Windows. I also added the new file to the three project files.
This commit is contained in:
parent
8c3d0f7839
commit
284d927625
10 changed files with 1764 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
import unittest, struct
|
||||
import os
|
||||
from test import test_support
|
||||
|
||||
class FormatFunctionsTestCase(unittest.TestCase):
|
||||
|
|
@ -115,11 +116,25 @@ class IEEEFormatTestCase(unittest.TestCase):
|
|||
self.assertEquals(pos_neg(), neg_neg())
|
||||
|
||||
|
||||
class ReprTestCase(unittest.TestCase):
|
||||
def test_repr(self):
|
||||
floats_file = open(os.path.join(os.path.split(__file__)[0],
|
||||
'floating_points.txt'))
|
||||
for line in floats_file:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
v = eval(line)
|
||||
self.assertEqual(v, eval(repr(v)))
|
||||
floats_file.close()
|
||||
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(
|
||||
FormatFunctionsTestCase,
|
||||
UnknownFormatTestCase,
|
||||
IEEEFormatTestCase)
|
||||
IEEEFormatTestCase,
|
||||
ReprTestCase)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue