[Python-checkins] r68189 - in python/branches/release30-maint: Lib/fractions.py Lib/test/test_fractions.py Misc/NEWS
raymond.hettinger
python-checkins at python.org
Sat Jan 3 10:27:09 CET 2009
Author: raymond.hettinger
Date: Sat Jan 3 10:27:08 2009
New Revision: 68189
Log:
Fractions.from_float() no longer loses precision with large integer inputs.
Modified:
python/branches/release30-maint/Lib/fractions.py
python/branches/release30-maint/Lib/test/test_fractions.py
python/branches/release30-maint/Misc/NEWS
Modified: python/branches/release30-maint/Lib/fractions.py
==============================================================================
--- python/branches/release30-maint/Lib/fractions.py (original)
+++ python/branches/release30-maint/Lib/fractions.py Sat Jan 3 10:27:08 2009
@@ -109,7 +109,7 @@
"""
if isinstance(f, numbers.Integral):
- f = float(f)
+ return cls(f)
elif not isinstance(f, float):
raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
(cls.__name__, f, type(f).__name__))
Modified: python/branches/release30-maint/Lib/test/test_fractions.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_fractions.py (original)
+++ python/branches/release30-maint/Lib/test/test_fractions.py Sat Jan 3 10:27:08 2009
@@ -136,6 +136,8 @@
def testFromFloat(self):
self.assertRaises(TypeError, F.from_float, 3+4j)
self.assertEquals((10, 1), _components(F.from_float(10)))
+ bigint = 1234567890123456789
+ self.assertEquals((bigint, 1), _components(F.from_float(bigint)))
self.assertEquals((0, 1), _components(F.from_float(-0.0)))
self.assertEquals((10, 1), _components(F.from_float(10.0)))
self.assertEquals((-5, 2), _components(F.from_float(-2.5)))
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Sat Jan 3 10:27:08 2009
@@ -48,6 +48,9 @@
Library
-------
+- Fractions.from_float() no longer loses precision for integers too big to
+ cast as floats.
+
- Issue #4812: add missing underscore prefix to some internal-use-only
constants in the decimal module. (Dec_0 becomes _Dec_0, etc.)
More information about the Python-checkins
mailing list