Exactly.
Though, I would note, that such “caching” seldom useful for floats (c.f. ints, for instance).
Indeed. The language define default behavior for equality comparison:
The default behavior for equality comparison (
==and!=) is based on the identity of the objects. Hence, equality comparison of instances with the same identity results in equality, and equality comparison of instances with different identities results in inequality.
But then float(‘nan’) and Decimal(‘nan’) noted as special (snowflakes) in this regard. So, implication “nans are unequal” => “they should be different objects wrt to id()” — will be wrong.
NaN could be like None. This harm compatibility with the IEEE 754, however.