Comment on PEP-0238

Guido van Rossum guido at python.org
Sun Jul 8 08:27:11 EDT 2001


"Emile van Sebille" <emile at fenx.com> writes:

> # default setting
> precision 0    # everything behaves as it does now
> print 2 / 7    # -> 0, ie to precision 0 decimal places
> print 2/7.0   # -> 0.285714285714
> 
> precision 1    # all calculations yield 1 decimal point precision interim
> results
> print 2 / 7    # -> 0.2, ie to precision 1 decimal places
> 
> precision 2
> print 2 / 7    # -> 0.28, ie to precision 2 decimal places
> 
> precision 3
> print 2 / 7    # -> 0.285, ie to precision 3 decimal places
> 
> This seems to me to break no existing code other than where precision is
> currently used as a label, and allows us to teach others, when they get
> stung by unexpected results, that they need to set precision appropriately.
> Once explained, integer division would not be a surprise to newbies, nor
> would the precision of floating point be lost to those who understand and
> benefit from its use.  And those of us that just want to write business
> accounting applications will be able to set precision 2 at the top of each
> module and be done with it.

Your examples don't show what should happen in this example:

  precision 0
  x = 2/7
  precision 4
  print x

In other words, is the precision a property of the printing or a
property of the value stored?

There are lots of other ways to get this effect for printing ("%.4f"%x
comes to mind); if you intended the effect to apply to computation
results, there are questions about the scope of the calculation.  If I
write

  precision 3
  x = f()	# some function that uses int division

should every calculation in f() be affected by the precision
statement?

Etc., etc.

This is exactly why I was asking you to write a PEP.  I don't mean
that you have to write an implementation.  (Despite the seeming
requirement in PEP 2, that's not a requirement before a PEP is
accepted for review -- that's only required before a standard PEP is
finally approved for inclusion in the language.  There are plenty of
PEPs without a shred of implementation.)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list