[New-bugs-announce] [issue26975] Decimal.from_float works incorrectly for non-binary floats
Serhiy Storchaka
report at bugs.python.org
Sun May 8 02:45:45 EDT 2016
New submission from Serhiy Storchaka:
Decimal.from_float() works correctly only if the denominator of as_integer_ratio() of argument is the power of two. Example:
>>> from decimal import Decimal
>>> class DecimalFloat(float):
... def as_integer_ratio(self):
... return Decimal(str(self)).as_integer_ratio()
... def __abs__(self):
... return self
...
>>> DecimalFloat(1.2).as_integer_ratio()
(6, 5)
>>> Decimal.from_float(DecimalFloat(1.2))
Decimal('1.50')
----------
components: Extension Modules, Library (Lib)
messages: 265116
nosy: facundobatista, mark.dickinson, rhettinger, serhiy.storchaka, skrah
priority: normal
severity: normal
status: open
title: Decimal.from_float works incorrectly for non-binary floats
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26975>
_______________________________________
More information about the New-bugs-announce
mailing list