Future division patch available (PEP 238)

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Jul 22 05:55:50 EDT 2001


Sun, 22 Jul 2001 09:35:27 +0100, Stephen Horne <steve at lurking.demon.co.uk> pisze:

> And as it happens, I remember my first experience with Pascal led
> to the question "why does Pascal need two division operators when
> BASIC works perfectly well with one?"

The Basic I used didn't have integer division at all, which is hardly
an improvement.

All arithmetic operators and functions like divmod, except /, have the
property that the value of the result, as long as it's not an error,
depends only on the values of arguments - not on their types.

Python implicitly converts numbers between types - it doesn't treat
numeric types as independent (like e.g. Haskell and OCaml do). So
it makes sense to extend the idea that 2 can be used to mean "two"
also in floating point contexts to the / operator.

			*	*	*

My taste suggests the following:

- div and mod should be operators which return components of divmod.
  divmod works as currently.

- / applied to ints or longs should return the exact result as a rational.
  % should remain only in its sprintf meaning.

- When rationals and floats are mixed, the result is a float.

- Given the above assumptions, I'm not sure what literals like
  1.2 should produce. All possibilities have reasons: rationals,
  floats, or decimal floats. Anyway, the question is what should be
  the default, because other possibilities can be formed by using
  a letter suffix. I would either let 1.2 mean a rational and 1.2f
  a float, or 1.2 a float and 1.2r a rational. More probably the
  former. Decimal floats should not be necessary: they are inexact
  like binary floats and slow like rationals.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list