-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect signum
translation
#14
Comments
This ensures that the translation of Copilot `signum` expressions results in Bluespec code that is semantically equivalent. In particular, it ensures that `signum e` behaves correctly when `e` is zero, negative zero, or `NaN` (if `e` is a floating-point type). The new translation is heavily inspired by the existing approach in `copilot-c99`: https://github.com/Copilot-Language/copilot/blob/6034e6d4d95464397ba81e346f40f71213c0ffbd/copilot-c99/src/Copilot/Compile/C99/Expr.hs#L233-L272
I attempted the |
It turns out that the evaluation-time error is expected behavior—see B-Lang-org/bsc#711 (comment). As such, I will need to redefine |
I've opened #15 to track the |
This ensures that the translation of Copilot `signum` expressions results in Bluespec code that is semantically equivalent. In particular, it ensures that `signum e` behaves correctly when `e` is zero, negative zero, or `NaN` (if `e` is a floating-point type). The new translation is heavily inspired by the existing approach in `copilot-c99`: https://github.com/Copilot-Language/copilot/blob/6034e6d4d95464397ba81e346f40f71213c0ffbd/copilot-c99/src/Copilot/Compile/C99/Expr.hs#L233-L272
This ensures that the translation of Copilot `signum` expressions results in Bluespec code that is semantically equivalent. In particular, it ensures that `signum e` behaves correctly when `e` is zero, negative zero, or `NaN` (if `e` is a floating-point type). The new translation is heavily inspired by the existing approach in `copilot-c99`: https://github.com/Copilot-Language/copilot/blob/6034e6d4d95464397ba81e346f40f71213c0ffbd/copilot-c99/src/Copilot/Compile/C99/Expr.hs#L233-L272
Fixed in #17. |
copilot-bluespec
incorrectly translates the Copilotsignum
function to Bluespec.signum @Int8
In Copilot,
signum @Int8 0
should return0
. In Bluespec, however, it returns1
:signum @Double
In Copilot,
signum @Double x
returnsx
wheneverx
is0.0
,-0.0
, orNaN
. In Bluespec, however, it will return1.0
if the sign bit is clear and-1.0
if the sign bit is set. Here are some examples demonstrating this in action:(Note that
0x3ff0000000000000
is the hexadecimal representation of1.0 :: Double
as bits, and0xbff0000000000000
is the hexadecimal representation of-1.0 :: Double
as bits.)Proposed fix
In order to make these translations faithful to Copilot's semantics, I think we will need to translate
signum e
to something likeif e > 0 then 1 else (if e < 0 then -1 else e)
in Bluespec. This is similar to howcopilot-c99
translatessignum
(see this code).The text was updated successfully, but these errors were encountered: