[issue26975] Decimal.from_float works incorrectly for non-binary floats
Serhiy Storchaka
report at bugs.python.org
Sun May 8 09:25:20 EDT 2016
Serhiy Storchaka added the comment:
Once I was going to propose to make as_integer_ratio() returning a pair (n, d) with minimal positive d that n/d (as float) is exactly equal to the original float. I think this is legitimate implementation and doesn't contradict the documentation.
I see following ways to resolve this issue:
1. Ignore it.
2. Ignore methods overriding:
2a) either convert float subclass to exact float with known behavior;
2b) or directly call static float.__abs__() and float.as_integer_ratio() instead of resolving dynamic methods.
3. Check that the denominator is a power of 2 and raise error otherwise.
4. Implement different different algorithm. Returns decimal n / 10**k with minimal k that after converting to float is exactly equal to the original float.
Most of these solutions will automatically fix issue26974, so it doesn't need special fix.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26975>
_______________________________________
More information about the Python-bugs-list
mailing list