Preferences

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:

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.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal