[010 Preprocessing] Please define a macro to compare the size of two numbers a and b, and the greater than, less than, and if statements cannot be used

1. Principle

If the result of the subtraction of two numbers is greater than 0, then the absolute value of the addition result must be greater than zero;

If the result of subtracting two numbers is less than 0, the absolute value of adding them must be equal to 0.

Two, examples

(4-6)+|(4-6)| = -2+2 = 0 so 4 < 6;
(6-4)+|(6-4)| = 2+2 = 4 so 6 > 4.

#define COMPARE(x,y) ((x)-(y))+(abs((x)-(y))) != 0 ?1:0 //等价于(X>Y)?1:0

Guess you like

Origin blog.csdn.net/qq_41709234/article/details/131237586