3

Is there any simple math expression that returns $-1$ if $x > a$ or $1$ if $x < a$?

2 Answers2

4

To convert Daniel Fischer's perfectly good comment-answer into an actual answer: $$\frac{a-x}{|a-x|}$$

Cameron Buie
  • 102,994
3

The simplest I know is $$f(x)= \begin {cases} 1 &x \lt a\\-1&x\gt a \end {cases}$$ This is a fine expression

Ross Millikan
  • 374,822