For entertainment, suppose we want to compare two numbers of format double
using the c language, and we can only use mathematical equations that use the arithmetic operators +, -, *, /, %
, and fabs()
and pow()
to check equal to (==
), less than (<
), and greater than (>
). Similar to the real relational operators ==, <, and >
, the code we write must return True (1
) or False (0
) for each of the different kinds of checks.
For example, without using any other operators than +, -, *, /, %
, and fabs()
and pow()
, if we determine that two variables a
and b
are equal, we should return True or 1, otherwise, return False or 0. It is better to return integers 0 and 1 instead of boolean True and False. To complicate things, we cannot use the real relational operators, logical operators, bitwise operators, or any other operators. Further, we cannot use switch statements or conditional statements. How to do so?
I know how to find the smaller value of x and y, that is to say x < y
can be calculated as ((x + y) + fabs(x-y))/2
. Further, to find x > y
, it is ((x + y) - fabs(x-y))/2
. However, those equations return the value x or y depending on the comparisons equation, and I need them to return 0 or 1. Similarly, I need some code equation that returns a 0 or 1 if x and y are equal (==
) to each other, and must do so using only +, -, *, /, %
, and fabs()
and pow()
.