[Pythonmac-SIG] Re: Number format in IDE

Mark Day mday@mac.com
Mon, 27 Aug 2001 11:17:18 -0700


On Monday, August 27, 2001, at 10:29  AM, Jon Bradley wrote:

> Maybe it would be ideal if the calculation were (as in typical
> calculators) rounded off to a pre-set accuracy.

and

> But, in most 3d applications they
> do use decimal floating point.  I wonder how much aspirin the developer 
> of a
> radiosity Python implementation (can't remember the name at the moment) 
> took
> while building his application. :)

This behavior isn't unique to Python.  You'd get exactly the same 
numeric results in a typical C implementation.  Python is just using the 
C implementation for calculations anyway.  The interesting difference is 
that in C you have to decide in advance how much precision to display 
(which might not be the same as the precision of the underlying 
calculation...), where Python's repr function defaults to displaying a 
lot of digits.

Python's print statement does some rounding before it displays a float, 
but it does not replace the float's value with the rounded value it 
displays (what you see is *not* what you get!).  If you round 
intermediate results, you limit meaningful precision each time you 
round.  If you do that a lot (eg., in a loop), it can make a dramatic 
difference in the meaningful precision of the end result.

I'd say it's important for relatively new students to understand that 
the issue exists, and that they may need to use a better controlled 
numeric implementation in some cases.  But you could probably leave more 
of the details and solutions to a numeric computation class.

-Mark