[Python-ideas] string codes & substring equality

Andrew Barnert abarnert at yahoo.com
Mon Dec 2 09:45:06 CET 2013


On Dec 1, 2013, at 23:37, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 2 December 2013 11:45, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>> The newbie says it should be 4.5 but gets 4.499999999999999999999 so raises
>> issue on bug tracker stating that Python can't do arithmetic properly.
>> 
>> In [5]: 9/2
>> Out[5]: 4.5
>> 
>> Blast, lousy example :)
> 
> Getting a modern Python to fall into that trap at all is actually
> quite difficult - the way str.__repr__ works was changed a while ago
> to favour the nearest terminating approximation that is represented
> using the same IEEE754 bit pattern :)

I think the trap you're looking for is "9/2 == 4.5". Except that one doesn't fail either.


More information about the Python-ideas mailing list