On Nov 28, 8:39 pm, Tim Roberts <t...@probo.com> wrote: > moijes12 <moije...@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 > >>>> -0 or True > >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.
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. At least that's certainly the intention: there are bits of CPython's source code that are deliberately written in convoluted ways in order to avoid the assumption of two's complement. But I have a nasty suspicion that, were Python ever unlucky enough to meet a ones' complement machine, we'd quickly find that there were many *other* bits of the source code that tacitly (and incorrectly) assumed a two's complement representation. Mark -- http://mail.python.org/mailman/listinfo/python-list