Implement the <=>
three-way comparison operator on numbersImplement the <=>
three-way comparison operator on numbers
Tags: code-golfnumbercomparison
In C++, there exists a a <=> b
three-way comparison operator that, for numerical types, does the following:
- If
a < b
, then return-1
. - If
a = b
, then return0
. - If
a > b
, then return1
.
The Challenge
Implement the shortest full program, function, method, or custom operator such that, when given two numbers of the same type a
and b
,
- If
a < b
, then return-1
. - If
a = b
, then return0
. - If
a > b
, then return1
.
Notes
- If you're writing in x86 assembly, this question may be of use to you.
- This is code-golf, so shortest answer wins!