Whilst writing a rather longer article related to floating point, and having recently been sensitized to these sorts of issues, I note the following behaviour:
>>> x=-0.0;y=0.0;print x,y -0.0 -0.0
To my mind this is beyond bonkers, but I’ve been convinced by others before that behaviour I used to think was bonkers may in fact be sensible. The behaviour is obviously caused by the compiler caching the constant values.
Anyone care to defend it?
2007-07-01 at 18:35:35
It’s clearly a bug but hard to fix portably in CPython; see this comp.lang.python thread. A couple of posters in that thread point out that the disassembler is useful in figuring out what’s going on:
>>> c = compile(‘(0.0,-0.0)’, ‘eval’, ‘eval’)
>>> import dis
>>> dis.dis(c)
1 0 LOAD_CONST 1 ((0.0, 0.0))
3 RETURN_VALUE
2007-07-01 at 20:17:41
Perhaps it is difficult, but it’s patched. Looks like the patch wasn’t made by the “in-crowd” though. Wonder if it’ll make it?
2007-07-01 at 20:31:18
I don’t know if the patch will make it, but the author of the patch is most certainly in the in-crowd.
2007-07-01 at 21:23:37
In-crowd: Oops. My misreading of an unfamiliar scene.