need clarification on -0
timr at probo.com
Sat Nov 28 21:39:05 CET 2009
moijes12 <moijes12 at gmail.com> wrote:
>I know the value -0 is quite meaningless and makes little sense.But I
>was just fiddling.I am unable to figure out the below result
>>>> -0 and True
>0 ----------> (Why is this 0 and not say True or False)
>>>> -0 and false
>>>> -0 or True
>Could someone please provide me some resources on how these operations
>take place.I'd wanna find it out myself
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. Having spent
10 years with Control Data (the 6000 and Cyber 70/170 mainframes were all
one's complement), I am particularly sensitive to this. Processors are
usually architected so that you don't normally see the -0, but it leads you
to think about arithmetic a bit differently.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list