[Python-ideas] string codes & substring equality

Nick Coghlan ncoghlan at gmail.com
Mon Dec 2 08:37:37 CET 2013


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 :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list