News for hackers. Stuff that matters.
Re:Comparing Integers and Doubles by millipede on Wednesday November 19, 2025 @03:52PM (#45984985)
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.

Re:Comparing Integers and Doubles by threeducks on Wednesday November 19, 2025 @04:05PM (#45985174)
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...

Re:Comparing Integers and Doubles by adgjlsfhk1 on Wednesday November 19, 2025 @04:17PM (#45985339)
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).
Re:Comparing Integers and Doubles by tadfisher on Wednesday November 19, 2025 @04:47PM (#45985728)
> 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".

Re:Comparing Integers and Doubles by layer8 on Wednesday November 19, 2025 @06:20PM (#45986679)
It’s not straightforward to compare numerical ordering using the decimal expansion.
Re:Comparing Integers and Doubles by Someone on Thursday November 20, 2025 @01:21AM (#45989555)
> 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.