I'm currently working with a branchless language which does not have native Less-Than, Greater-Than or Equal-To functions. I do however have min, max and abs functions and standard arithmetic (+, -, / and *) available to me.
I'd like to create these three functions (as L(a, b), G(a, b) and E(a, b) respectively, which will output 0 for false and 1 for true. So, for example, L(3, 7) would return 1 for true whereas G(3, 7) would return 0 for false, and E(3, 7) would also return 0, etc.
The min and max functions only allow you to pass two parameters, a and b, and then spits out the respective minimum or maximum of the two parameters. The abs function takes the one parameter and returns the absolute value.
I've postulated that given that the min(a, b) is equivalent to:
L(a,b) * a + (1 - L(a,b)) * b
It would stand to reason that:
L(a,b) = (min(a,b) - b) / (a - b)
and similarly:
max(a,b) = G(a,b) * a + (1 - G(a,b)) * b
therefore:
G(a,b) = (max(a,b) - b) / (a - b)
But this is where I get stumped because, I'm not sure how to account for the possibility of a-b equalling 0 in both instances, which as a result stumps me on how to approach the E(a, b) function.
So my question is this... Given that I only currently have access to basic arithmetic functions as well as min(a,b), max(a,b) and abs(a), and because of the language being branchless (therefore no loops), is there a way to programmatically account for the a-b divide-by-zero issue such that if I do have a scenario where a == b that these functions can return zero for either L() or G(), otherwise output the original equations I have derived, and also be able to provide code for E(a, b)?
Given that this is fairly generic (hey, I've written it in psuedocode!) I'd appreciate some insight on how to proceed. In this case, the solution needs to work with both integers as well as floats.
Context: This is research for a personal project I'm working on relating to binary registers, thus the need for 1's and 0's for output and I'm kinda stuck at this point.
/defined exactly? If the numbers are integers, is it floored division or round-towards-zero? \$\endgroup\$