In general, there is no evidence of what types the literals 1 and 2 have. In most languages ββthey will be the same, but in theory they can be different, and the results of two comparisons can be different. In addition, integers are not infinite in most languages, so behavior may differ from borders.
In plain C, if comparisons x <= -0x80000000 and x < -0x7fffffff (note that -0x80000000 < -0x7fffffff ) and x are of type int , the results depend on the value of x:
-0x80000000 : 1 1 -0x7fffffff .. -1 : 0 0 0 .. 0x7fffffff: 1 0
In other words, for all non-negative x results will be different.
Similarly, when comparing x <= 0x7fffffff and x < 0x80000000 (the ratio between the constants 0x7fffffff < 0x80000000 preserved), we obtain:
-0x80000000 .. -1 : 1 0 0 .. 0x7fffffff: 1 1
Now the results are different for all negative x values.
Obviously, there are some rules for input and type conversion (they are described in the C language standard), but the fact is that two comparisons cannot be replaced by boundary cases.
source share