Is there a simple math function available that compares numbers x and y and returns -1 when x is less than y, 1 when x is more than y and 0 when they’re equal?
If not, would there be a elegant solution (without any if‘s) to convert the output of Math.Max(x, y) to these returns? I was thinking of dividing the numbers by themselves, e.g. 123/123 = 1 but that will introduce the problem of dividing by 0.
For your strict -1, 0 or 1 requirement, there’s no single method that is guaranteed to do this. However, you can use a combination of
Int32.CompareToandMath.Sign:Alternatively, if you’re happy with the normal
CompareTocontract which is just stated in terms of negative numbers, positive numbers and 0, you can useCompareToon its own.