Both ints and floats represent real, rational values, but every operation in no way matches math. Associative? No. Commutative? No. Partially Ordered? No. Weakly Ordered? No. Symmetric? No. Reflexive? No. Antisymmetric? No. Nothing.
The only reasonable way to compare rationals is the decimal expansion of the string.
> 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:
Someone|3 months ago
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.
threeducks|3 months ago
https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accu...
adgjlsfhk1|3 months ago
tadfisher|3 months ago
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".
layer8|3 months ago