for / while else doesn't make sense

Pete Forman petef4+usenet at gmail.com
Mon May 23 14:16:56 EDT 2016


Ian Kelly <ian.g.kelly at gmail.com> writes:

> On Mon, May 23, 2016 at 8:29 AM, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
>> Ian Kelly <ian.g.kelly at gmail.com> writes:
>>
>>> On Mon, May 23, 2016 at 2:09 AM, Steven D'Aprano
>>> <steve+comp.lang.python at pearwood.info> wrote:
>>>> Are you saying that the Egyptians, Babylonians and Greeks didn't
>>>> know how to work with fractions?
>>>>
>>>> http://mathworld.wolfram.com/EgyptianFraction.html
>>>>
>>>> http://nrich.maths.org/2515
>>>>
>>>> Okay, it's not quite 4000 years ago. Sometimes my historical sense
>>>> of the distant past is a tad inaccurate. Shall we say 2000 years
>>>> instead?
>>>
>>> Those links give dates of 1650 BC and 1800 BC respectively, so I'd
>>> say your initial guess was closer.
>>
>> Right, but this is to miss the point. Let's say that 4000 years have
>> defined 1/3 to be one third, but Python 3 (as do many programming
>> languages) defines 1/3 to be something very very very very close to
>> one third, and *that* idea is very very very very new! It's
>> unfortunate that the example in this thread does not illustrate the
>> main problem of shifting to binary floating point, because 1/2
>> happens to be exactly representable.
>
> I'm not going to dig back through the thread, but my recollection is
> that's exactly why that example was chosen. Since 1/2 can be
> represented exactly as a float, it *should* be represented as a float.
> Picking another value (0) that isn't even close to the exact value of
> 1/2 isn't helping anybody.

Something else which I do not think has been stated yet in this thread
is that floating point is an inexact representation. Just because
integers and binary fractions have an exact correspondence we ought not
to be affording them special significance. Floating point 1 is not the
integer 1, it stands for a range of numbers some fraction either side of
1.

There are other ways of handling non-integral numbers, such as fixed
point, rational and unum. However current computing hardware is very
much oriented to floating point, IEEE in particular.

-- 
Pete Forman



More information about the Python-list mailing list