Fix handling of special Float values. Refs #697.#722
Open
RyanGlScott wants to merge 4 commits intoCopilot-Language:masterfrom
Open
Fix handling of special Float values. Refs #697.#722RyanGlScott wants to merge 4 commits intoCopilot-Language:masterfrom
Float values. Refs #697.#722RyanGlScott wants to merge 4 commits intoCopilot-Language:masterfrom
Conversation
copilot-{bluespec,theorem}: Fix handling of special Float values. Refs #697.Float values. Refs #697.
ivanperez-keera
requested changes
Apr 3, 2026
Member
ivanperez-keera
left a comment
There was a problem hiding this comment.
Change Manager: See notes above about changes requested.
…. Refs Copilot-Language#697. `copilot-bluespec`'s translation from Copilot to Bluespec up-casts `Float` values to `Double` values using the `realToFrac` function. `realToFrac` incorrectly handles special floating-point values such as negative zero, infinity, and NaN values, causing `copilot-bluespec` to generate the wrong `Float` values on the Bluespec end. This commit removes the use of `realToFrac` in favor of an alternative approach based on `GHC.Float.float2Double`, which correctly handles most special floating-point values. A notable exception is NaN values, as `float2Double` does not reliably preserve the payload of a NaN value. As such, we include a special case for NaN values that takes care to preserve payloads. Co-authored-by: Ryan Scott <rscott@galois.com>
…mples. Refs Copilot-Language#697. `copilot-theorem`'s counterexample-reporting machinery up-casts `Float` values to `Double` values using the `realToFrac` function. `realToFrac` incorrectly handles special floating-point values such as negative zero, infinity, and NaN values, causing `copilot-theorem` to generate incorrect counterexamples when these special values are involved. This commit removes the use of `realToFrac` in favor of an alternative approach based on `GHC.Float.double2Float`, which correctly handles most special floating-point values. A notable exception is NaN values, as `double2Float` does not reliably preserve the payload of a NaN value. As such, we include a special case for NaN values that takes care to preserve payloads. Co-authored-by: Ryan Scott <rscott@galois.com>
…e#697. Co-authored-by: Ryan Scott <rscott@galois.com>
…#697. Co-authored-by: Ryan Scott <rscott@galois.com>
66002c3 to
6e2fed2
Compare
Collaborator
Author
|
Implementor: Fix implemented, review requested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Both
copilot-bluespecandcopilot-theoremup-castFloatvalues toDoublevalues using therealToFracfunction.realToFracincorrectly handles special floating-point values such as negative zero, infinity, and NaN values, causingcopilot-bluespecto generate the wrong BluespecFloatvalues and causingcopilot-theoremto generate incorrect counterexamples.This commit removes the use of
realToFracin favor of an alternative approach based onGHC.Float.{float2Double,double2Float}, which correctly handles most special floating-point values. A notable exception is NaN values, as{float2Double,double2Float}does not reliably preserve the payload of a NaN value. As such, we include a special case for NaN values that takes care to preserve payloads.Fixes #697.