Re: Signed zeros: is this a bug?



"Mark Dickinson" <dickinsm@xxxxxxxxx> wrote:

I guess what's happening is that there's some optimization that avoids
creating two separate float objects for a float literal that appears
twice, and that optimization doesn't see the difference between 0. and
-0.

Don't guess. Test.

def f():
x = 0.0
y = -0.0
return x, y

dis.dis(f)
2 0 LOAD_CONST 1 (0.0)
3 STORE_FAST 0 (x)

3 6 LOAD_CONST 1 (0.0)
9 STORE_FAST 1 (y)

4 12 LOAD_FAST 0 (x)
15 LOAD_FAST 1 (y)
18 BUILD_TUPLE 2
21 RETURN_VALUE

Yes. Just the one constant there.


Tim Peters wrote in
http://blog.gmane.org/gmane.comp.python.devel/day=20050409:

All Python behavior in the presence of a NaN, infinity, or signed zero
is a platform-dependent accident. This is because C89 has no such
concepts, and Python is written to the C89 standard. It's not easy to
fix across all platforms (because there is no portable way to do so in
standard C), although it may be reasonably easy to fix if all anyone
cares about is gcc and MSVC (every platform C compiler has its own set
of gimmicks for "dealing with" these things).

.