> The only reasonable way to compare rationals is the decimal expansion of the string.
Why decimal? I don’t see why any other integer base wouldn’t work, and, on about any system, doing 2^n for any n > 0* will be both easier to implement and faster to run.
And that, more or less, is what the suggested solution does. It first compares the first 53 bits and, if that’s not conclusive, it compares 64 bits.
Also, of course, if your number has more than n bits, you’d only generate digits until you know the answer.
What exactly do you say is not commutative? This Wikipedia article claims that at least floating-point addition and multiplication are both commutative:
https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accu...
it is for finite values, but because IEEE did some dumb things it isn't specified to be for NaN values (and on several architectures, isn't).
> The only reasonable way to compare rationals is the decimal expansion of the string.
Careful, someone is liable to throw this in an LLM prompt and get back code expanding the ASCII characters for string values like "1/346".
It’s not straightforward to compare numerical ordering using the decimal expansion.
The only reasonable way to compare rationals is the decimal expansion of the string.