Signed zeros: is this a bug?

Scott David Daniels scott.daniels at acm.org
Sun Mar 11 15:12:27 EDT 2007


Alex Martelli wrote:
> Alas, here is the problem...: 0.0 and -0.0 are NOT separate as dict
> keys!  They are == to each other.  So are 0, 0L, and 0+j0, but the
> compiler smartly distinguishes these cases by using (obj, type) as the
> key (the *types* are distinguished, even though the *values*) are; this
> doesn't help with 0.0 and -0.0 since both have type float....
> If you know the proper way to test for -0.0 in portable C code (or some
> feature macro to use in a #if to protect nonportable code) ....

Perhaps you could add a type "NegativeFloat" -- a subtype of float,
and distinguish negative zero from zero that way.  Not saying I know how
in portable C, but ....

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list