top | item 45984985

(no title)

millipede | 3 months ago

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.

discuss

order

Someone|3 months ago

> 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.

tadfisher|3 months ago

> 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".

layer8|3 months ago

It’s not straightforward to compare numerical ordering using the decimal expansion.