Why "<" but not "!="?

According to the logic design
Comparator of "<" or ">" would need a lot of adders
But "==" or "!=" would be cheaper than "<" or ">"
If this is true, why most of the programmer still keen to "<" or ">" in for loop?
Do I make any mistake?
Thanks a lot
what is 'adder' in this context?

anyway, (for integers) for comparison a function cmp a, b is used. It basically performs subtraction, but does not modify it's arguments. This function sets the flags that show whether a > b, a == b or a < b. What the operators do in c++ is call cmp and then check the appropriate flag, so the process is exactly the same.

also, < is a lot easier to understand.
what is 'adder' in this context?

"adder" in this context related to the field of electronics
"<", ">" or "==", if their performance are same
then I have no reason to worry about it

I am just a bit curious since "==" or "!=" could be done by
"exclusive or" in an easy way
Last edited on
It doesn't need any adders. The design of the logic circuits is nearly as simple as a bit-equality circuit. The cost in cycles is insignificant.
a == b will be equivalent to a xor b if they are integer types. Also < is shorter than !=
There's no difference in cycle cost with modern processors and compilers always have transformed simple/obvious loops so that comparison for equality is used, even if you used the < operator.
Thanks a lot
Topic archived. No new replies allowed.