1 > 0 == True -> False

Chris Angelico rosuav at gmail.com
Thu Jan 30 17:29:12 EST 2014


On Fri, Jan 31, 2014 at 9:09 AM, Roy Smith <roy at panix.com> wrote:
> On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote:
>> `(x+1 > 0) and (y >= 5)`
>
> Me:
>> this is even simpler:
>> (x > -1) and (y >= 5)
>
> On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote:
>> Be careful; that's not the same thing.
>
> In what way?  I'm assuming x is some numeric type.  And further assuming it's not some humungous floating point value, so we run into precision issues.

Now you're changing the problem domain :) Like I said, if it's an
integer, you definitely will get the same result from each of the
above; but that doesn't mean the expressions are equivalent. They just
might happen to produce the same result for values within some
particular domain. (I wouldn't even be 100% confident that it's valid
for any numeric type, though I can't think of any float values that it
would break on, and complex and int are unorderable anyway.)

ChrisA



More information about the Python-list mailing list