About Rational Number (PEP 239/PEP 240)

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Dec 16 01:09:06 EST 2007


On Sat, 15 Dec 2007 17:42:26 -0800, Dennis Lee Bieber wrote:

> On Sun, 16 Dec 2007 00:42:56 -0000, Steven D'Aprano
> <steve at REMOVE-THIS-cybersource.com.au> declaimed the following in
> comp.lang.python:
> 
>> In the real world, people use fractions all the time, e.g. plumbers.
>> (Not that I'm expecting plumbers to start taking laptops out to the
>> building site in order to calculate pipe sizes.)
>>
> Piping tends to come in a limited range of discrete diameters, with
> a slew of adapters to convert from one to another. As such, they fit
> more in the Ada "fixed point" system or can be treated as a scaled
> integer... One does not find random pipe diameters.

Yes, but my point (badly put, I admit) was that people find fractions far 
easier to work with than they find floating point numbers. And with any 
rational data type worth the name, you simply should never get anything 
as unintuitive as this:

>>> from __future__ import division
>>> 4/10 + 2/10 == 6/10
False



-- 
Steven



More information about the Python-list mailing list