There's a straightforward conversion to BBC BASIC: a <=> b is equivalent to SGN(a - b).
For example in PHP you might have:
Code: Select all
echo x <=> y;
Code: Select all
PRINT SGN(x - y)
Code: Select all
echo x <=> y;
Code: Select all
PRINT SGN(x - y)
The Wikipedia article correctly points out that if you are extremely unlucky you may have a pair of numbers a, b which can be legitimately compared but when subtracted may result in an overflow (and hence an error being reported). If this is a concern an alternative BBC BASIC formulation of a <=> b is (a < b) - (a > b).Richard Russell wrote: ↑Wed 06 Nov 2024, 22:41There's a straightforward conversion to BBC BASIC: a <=> b is equivalent to SGN(a - b).
Code: Select all
echo x <=> y;
Code: Select all
PRINT SGN(x - y)
Code: Select all
PRINT (x < y) - (x > y)