Making a "larger than" function with only basic arithmetic

105 Views Asked by At

Is it possible to make a function using only arithmetic (no logic operators), that can return 1 if it's input x is larger than a given number a, and 0 if it's less than a?

If it is, how would one construct it for any arbitrary value of a?

How could a "less than" function be constructed in a similar fashion?

Edit: If this is not possible, is it possible to construct a function that tends to 0 for all values of x below a, and tends to 1 for all values of x above a?

1

There are 1 best solutions below

1
On

This is my solution for $a>0, x > 0$. Note this solution uses the floor operator ($\lfloor \rfloor$), which rounds a number down to the nearest integer, and the ceiling operator ($\lceil \rceil$), which rounds a number up to the nearest integer. Note this function returns $1$ if $x \le a$ and $0$ otherwise. $$f(x,a)=\left \lceil\left( \left\lfloor\frac{x}{a} \right\rfloor \right)\frac{1}{x}\right \rceil $$