In article <mailman.96.1430761253.12865.python-l...@python.org>,
Chris Angelico  <ros...@gmail.com> wrote:
>On Tue, May 5, 2015 at 3:32 AM, Irmen de Jong <irmen.nos...@xs4all.nl> wrote:
>> That is a broad question, but one thing that comes to mind is the
>current (python 3)
>> behavior of integer division. It gives the exact result and doesn't
>truncate to integers:
>>
>>
>>>>> 5/4
>> 1.25
>
>Using the word "exact" around non-integer values can be a little
>ambiguous, since floats are often inexact. But yes, int/int -> float,
>and yes, it WILL bite C programmers.

This should not be presented as a somewhat arbitrary decision.

Formerly we had

3e0/4e0
0.75

and

3/4
0

So the / operator worked on reals giving reals and integers
giving integers. Great if you're used to it, but sometimes a pitfall.
Also in practice it sometimes leads to rounding in unexpected places.
The greatest disadvantage is when you have i and j and want their
ratio. You have to do something like (real)i/j which feels unnatural.
So we need two different division operators on the integers.

Solution:
introduce // for integer by integer given integer, giving the
quotient (with a possible remainder).
Now / is free to be used for the more rational  "i/j gives a ratio",
i.e. a real number.

Bottom line
3e0/4e0 and 3/4 gives the same result. It is nice to no longer
have to be very careful in floating point calculation to avoid
integer constants.

On the other hand integer division is still available to solve
the familiar egg-farm problems:

I have 103 eggs. 12 eggs go in a box. How many boxes can I fill?

(Similar problems crop up in graphics all the time.)

>
>ChrisA

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to