[Python-Dev] Decimal data type issues (original) (raw)

Tim Peters tim_one at email.msn.com
Wed Apr 14 23:13:45 EDT 2004


[Facundo Batista, on max exponent]

But it's still an artificial restriction. We have no-limit longs, should have limited Decimal?

Nobody has a use for unbounded exponents, so it's a silly thing to support if there are costs. There are costs, including:

And also implies more code and complexity in the module. But this is a side effect and not the primary concern in the decision.

I don't know how it's implemented now. "The natural way" to check exponent bounds is in a common routine called at the end of every operation; in that case, the "more code and complexity" doesn't amount to anything worth mentioning.

...

#- In any case, fromstring() should be subsumed by #- Decimal(string), perhaps with via an optional "usecontext" flag #- argument.

You mean something like Decimal(string, usecontext=True)?

Yes.

And when creating from long, for example?

Sure.

Remember that the spec says that the context affect the operations,

Yes.

not creations (with the exception of fromstring).

I don't understand. The only place the spec uses the word "creation" is in regard to the creation of context objects. What do you mean by "creations"? Context does affect every way of creating a decimal number in the spec; the only ways to create numbers covered by the spec are via operations (and from_string isn't a special case here, from_string is just one of the required operations in the spec, and all operations covered by the spec respect context).

#- It's quite arguable that str() should be exactly the standard's #- toscistring() (and for those who haven't read the spec, do #- before you complain about that -- no, you don't always get an #- exponent under toscistring()).

I'm lost here. Are you saying that str() should have the same behaviour that toscistring()?

Yes, that str(Decimal) should produce exactly the string the spec specifies as being the result of its abstract to-sci-string operation. There's no requirement to have a method named "to_sci_string", the only requirement is that some way to spell to-sci-string's functionality be supplied. The meaning of to-sci-string is precisely specified by the standard, and is a good choice for both str(Decimal) and repr(Decimal). (It's both human-readable and exact.)



More information about the Python-Dev mailing list