On Sat, Aug 24, 2013 at 1:37 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
>
> I time this function at about 33% faster than your version for a
> six-digit decimal, and almost 50% faster for a 12-digit decimal.  My
> guess would be because it's not calling str() on every individual
> digit.
>
> def convert(d):
>     exp = d.as_tuple().exponent
>     num = int(d.scaleb(-exp))
>     return num, 10**-exp

Although, you would need to be careful with handling the decimal
context for the scaleb operation to make sure the result is exact.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to