Author mark.dickinson
Recipients mark.dickinson, rhettinger, steven.daprano
Date 2009-01-03.10:40:42
SpamBayes Score 0.000907542
Marked as misclassified No
Message-id <1230979243.38.0.906207633131.issue4796@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-01-03 10:40:43mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, steven.daprano
2009-01-03 10:40:43mark.dickinsonsetmessageid: <1230979243.38.0.906207633131.issue4796@psf.upfronthosting.co.za>
2009-01-03 10:40:42mark.dickinsonlinkissue4796 messages
2009-01-03 10:40:42mark.dickinsoncreate