Future division patch available (PEP 238)

Stephen Horne steve at lurking.demon.co.uk
Mon Jul 23 03:20:08 EDT 2001


On 23 Jul 2001 06:28:48 GMT, Marcin 'Qrczak' Kowalczyk
<qrczak at knm.org.pl> wrote:

>Integers are exact!!! That's the point: if numbers represent inexact
>quantities, they should be expressed as floats. Since working with
>integers and rationals is predictable and +-*/div,mod give correct
>(with int/int->rational), they should be used when we want to know the
>true answer. If it's not possible anyway, use floats and don't waste
>computation time for the 100th decimal place which is wrong anyway.

If I say my local shop is 1 mile away, is that exact? I don't thinks
so ;-)

Rounding to an integer is much more common even than rounding to
decimal places. The problem comes when people confuse this with dealin
with an integer measure. Distance is a real measure which is most
conveniently and accurately approximated using floats - so use floats
and be done with it.

If you are working with naturally integer measures then yes, integers
are exact - and integer division is the only division that makes
sense. If you are working with measures that are inherently real, than
using an integer to represent the value is no more exact than if you
used a float - less so, in fact, as the float has much more precision.
In such cases float division makes sense, but you should have been
using floats anyway because it was naturally a real arithmetic
problem.




More information about the Python-list mailing list