fix: don't show NaN sign info in Float.toString
#1459
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
lean_float_to_uint8
to avoid UB #1458 (it adds a test to the same file)This is another issue identified in the Zulip thread: Because the NaN sign bit and payload bits are architecture-dependent and not specified by IEEE 754, the simplest way to prevent this from affecting Lean code is to treat
Float
as a quotient type with respect to the various NaN values. Because the actual type is opaque to lean, it is possible to do this "in our hearts" with no code changes. The only exception to this isFloat.toString
, which becomes a non-function under this model as it distinguishes equal values.This is still not really observable without
native_decide
because the kernel doesn't know how any of these functions compute, but we should still try to keepnative_decide
sound where possible, so the fix implemented here is to makeFloat.toString
print all NaNs the same, as the string"nan"
. (Some languages like to write itNaN
; bikeshed away.)