2 ms·
Because all those other things are either identity types (handles, closures, etc) or are value types where the only possible way to represent them is with a sin
by derefr 4y ago
Because all those other things are either identity types (handles, closures, etc) or are value types where the only possible way to represent them is with a single "canonical form."
But IEEE754 allows not only NaNs, but also "negative zero" and denormals. Floating-point numbers, in other words, allow for multiple different bit-encodings that represent mathematically equal, but not identical, number values. There are non-canonical forms of the "same" numbers. And programming-language runtimes don't do anything to prevent CPUs from returning these non-canonical numbers; nor do they massage them back into canonical forms upon receiving them. They just end up blindly holding these non-canonical numbers — numbers which, if they ask the CPU if they're equal, they are; but if they look at the bit-patterns and compare those for equality, they're not.
> A compiler could use a floating-point-keyed hash table for deduplicating identical floating-point constants.
Bad example. A compiler wouldn't want a hash table whose key type is a floating-point number, because that would imply that the hash table is operating using IEEE754 definition of equality via-a-vis key presence collision checking.
Rather, a compiler would use a bitstring key type, where the keys are the bit patterns representing either the target ISA's native FP-register encodings of the given floating-point numbers; or the abstract/formal bit-packed form of those floating-point numbers according to IEEE754.
The difference between the two is that the latter uses bitstring collation (ordering and equality), not floating-point collation.
- wruza 4y agovalue types where the only possible way to represent them is with a single "canonical form." But IEEE754 allows not only NaNs, but also "negative zero" and denormals Unicore strings also have normalization forms. Not to make an argument, just a reminder.
- derefr 4y agoTrue — but Unicode strings that are not bit-equal aren't collation-equal either, so that doesn't usually matter. A non-canonicalized Unicode string won't "find" its canonical counterpart in a hashtable. IEEE754 floats (and doubles) are kind of unique among scalar types, in that the answer to "are these equal" in pretty much every programming language is delegated directly to the CPU to answer; and, in obeying IEEE754 semantics, the CPU's definition of equality for FP numbers makes things equal that aren't bit-representation-equal.