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 <rep...@bugs.python.org> <http://bugs.python.org/issue26975> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com