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
abs functions and standard arithmetic (
*) available to me.
I'd like to create these three functions (as
G(a, b) and
E(a, b) respectively, which will output
true. So, for example,
L(3, 7) would return
G(3, 7) would return
E(3, 7) would also return
max functions only allow you to pass two parameters,
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)
max(a,b) = G(a,b) * a + (1 - G(a,b)) * b
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
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
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
G(), otherwise output the original equations I have derived, and also be able to provide code for
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.