mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
Issue #1996: float.as_integer_ratio() should return fraction in lowest terms.
This commit is contained in:
parent
a51f61b555
commit
04c96d52a4
2 changed files with 26 additions and 85 deletions
|
@ -689,6 +689,14 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, float, Foo4(42))
|
||||
|
||||
def test_floatasratio(self):
|
||||
for f, ratio in [
|
||||
(0.875, (7, 8)),
|
||||
(-0.875, (-7, 8)),
|
||||
(0.0, (0, 1)),
|
||||
(11.5, (23, 2)),
|
||||
]:
|
||||
self.assertEqual(f.as_integer_ratio(), ratio)
|
||||
|
||||
R = rational.Rational
|
||||
self.assertEqual(R(0, 1),
|
||||
R(*float(0.0).as_integer_ratio()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue