Comment on PEP-0238

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Jul 12 00:43:34 EDT 2001


Tim Peters wrote:
> 
> If precision is adjustable, seems to me it's "usually explicit" (which you
> just said you don't want) or "usually implicit" (which you just said you
> don't want).  If you have another idea, let's hear it -- but remember I said
> at the start that the issue can't be wished away.

I don't want it implicit on some global or dynamically-scoped 
state. Some sort of lexically-scoped precision-setting statement
might be acceptable, but I'm not sure that's really appropriate
either.

It seems to me that, if you want adjustable precision at
all, you want to adjust it in a very fine-grained way
based on the kind of data you're using and what you're
doing with it.

For example, if you're adding up amounts of money, you
want 2 decimal places. But you *only* want to apply that
to the numbers which represent money, not the ones which
represent the rate of GST or the price per metre of the
material you're costing, etc.

So the notion of precision being part of some sort of
context that you establish and then go off and do your
calculations seems fundamentally wrong-headed. You'd
be changing the context almost operation-by-operation.

I don't know what the best solution to this is. I feel
it lies somewhere in the direction of using specialised
data types which know their own precision and also
what precisions are needed for various combinations
of them.

For example, a Money type would have a precision of
2dp, GSTRate maybe 4dp. They would know that
Money * GSTRate --> Money, so the result should have
2dp. Etc.

> Haven't used it, and didn't find any reference docs on the web that admitted
> to such a thing in Hypertalk; seemed to imply it handled 19-digit
> arithmetic, with a numberFormat property to control (only) *display*
> precision.

That's the problem -- it *wasn't* just used for display!
The only data type in Hypertalk was the string, so storing
a number anywhere counted as "displaying" it, and the
numberFormat got used.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list