Skip to content

Fix handling of special Float values. Refs #697.#722

Open
RyanGlScott wants to merge 4 commits intoCopilot-Language:masterfrom
GaloisInc:fix-697-bluespec-special-floats
Open

Fix handling of special Float values. Refs #697.#722
RyanGlScott wants to merge 4 commits intoCopilot-Language:masterfrom
GaloisInc:fix-697-bluespec-special-floats

Conversation

@RyanGlScott
Copy link
Copy Markdown
Collaborator

Both copilot-bluespec and copilot-theorem up-cast 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 Bluespec Float values and causing copilot-theorem to generate incorrect counterexamples.

This commit removes the use of realToFrac in favor of an alternative approach based on GHC.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.

@ivanperez-keera ivanperez-keera changed the title copilot-{bluespec,theorem}: Fix handling of special Float values. Refs #697. Fix handling of special Float values. Refs #697. Apr 3, 2026
Copy link
Copy Markdown
Member

@ivanperez-keera ivanperez-keera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Manager: See notes above about changes requested.

tkann-galois and others added 4 commits April 3, 2026 17:54
…. 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>
@RyanGlScott RyanGlScott force-pushed the fix-697-bluespec-special-floats branch from 66002c3 to 6e2fed2 Compare April 3, 2026 22:00
@RyanGlScott
Copy link
Copy Markdown
Collaborator Author

Implementor: Fix implemented, review requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Special Float values are translated incorrectly

3 participants