Mark Dickinson <[email protected]> added the comment:
Instead of the repeated divisions and Inexact tests, how about a direct
approach: n/2**k = (n*5**k)/10**k, so something like:
sign = 0 if copysign(1.0, self) == 1.0 else 1
n, d = abs(self).as_integer_ratio()
k = d.bit_length() - 1
return _dec_from_triple(sign, str(n*5**k), -k)
should work, and would likely be faster too.
I also think the sign of 0 should be preserved: i.e.,
>>> Decimal.from_float(-0.0)
Decimal('-0')
Am still reviewing---more comments to come.
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue4796>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com