Closed RyanGlScott closed 2 months ago
I attempted the if e > 0 then 1 else (if e < 0 then -1 else e)
fix as above, but that led me to discover another strange Bluespec quirk: compiling e > 0
(where e
is a Double
) will cause a Bluespec evaluation-time error. This time, I'm wondering if Bluespec is at fault. I've opened https://github.com/B-Lang-org/bsc/discussions/711 to discuss this.
It turns out that the evaluation-time error is expected behavior—see https://github.com/B-Lang-org/bsc/discussions/711#discussioncomment-10003586. As such, I will need to redefine <
, <=
, >
, and >=
such that instead of erroring when one of the arguments is a NaN, they instead return False
(as is the case in Copilot). For example, I think we should translate the Copilot expression x < y
to compareFP x y == LT
in Bluespec (where compareFP
is defined here).
I've opened https://github.com/Copilot-Language/copilot-bluespec/issues/15 to track the (<)
issue mentioned above, as it is really a separate problem.
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).