Message78942
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. |
|
Date |
User |
Action |
Args |
2009-01-03 10:40:43 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, steven.daprano |
2009-01-03 10:40:43 | mark.dickinson | set | messageid: <1230979243.38.0.906207633131.issue4796@psf.upfronthosting.co.za> |
2009-01-03 10:40:42 | mark.dickinson | link | issue4796 messages |
2009-01-03 10:40:42 | mark.dickinson | create | |
|