This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <>
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)

Am still reviewing---more comments to come.
Date User Action Args
2009-01-03 10:40:43mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, steven.daprano
2009-01-03 10:40:43mark.dickinsonsetmessageid: <>
2009-01-03 10:40:42mark.dickinsonlinkissue4796 messages
2009-01-03 10:40:42mark.dickinsoncreate