On Apr 9, 3:57 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Naive question: why not just use a long + an exponent? > > e.g. 132560 -> (13256, 1) > 0.534 -> (534, -3) > 5.23e10 -> (523, 8) >
It's a good question. The standard answer is that if the coefficient is a long then it's awkward to get at individual digits; looking up a digit becomes an O(n^2) operation (involving a division and a remainder) instead of the O(1) that it should be. And you need access to the digits for rounding operations, which are pretty darn common (one round at the end of each arithmetic operation, as a rule). But I could easily be convinced that storing the coefficient as a long speeds things up for the usual use cases, even if it gives horrible asymptotics for those trying to do really high-precision calculations. And it would certainly make the code slightly simpler in places. It would be great if someone could try converting Decimal so that the coefficient is stored as a long, to see if there's any noticeable impact on speed one way or the other. It wouldn't be such a hard change: a few hours of work at most. It's on my todo list to try this, but so far down that it's not looking like it'll end up at the top of the list before Christmas 20??. Mark -- http://mail.python.org/mailman/listinfo/python-list