need clarification on -0
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Nov 28 19:58:27 EST 2009
On Sat, 28 Nov 2009 15:14:31 -0800, Mark Dickinson wrote:
>> Actually, there ARE computers where you might not see this result.
>> Virtually all of the processors on which Python runs use two's
>> complement arithmetic. In two's complement, there is no separate value
>> called -0. 0 and -0 have the same bit representation.
>>
>> In one's complement, -0 and 0 have different representations.
>
> While that's true, I think the implementation of Python is such that the
> Python objects -0 and 0 should always be indistinguishable even on
> machines where the underlying architecture represents integers using
> ones' complement or sign-magnitude.
I don't think that really has any bearing on the Original Poster's
question -- presumably on such machines, Python should treat both -0 and
+0 as false in a boolean context and generate the same result.
When it comes to integers, I'm not aware of any mathematical or
programming system which treats -0 and +0 as distinct entities, even if
they have different internal representations. But the same doesn't apply
for floats, where the IEEE standard requires that -0.0 and +0.0 be
distinct and distinguishable (although it also requires that they compare
as equal).
--
Steven
More information about the Python-list
mailing list