copilot-bluespec
miscompiles negative zero, infinite, and NaN Float
values
#635
RyanGlScott
started this conversation in
General
Replies: 2 comments 4 replies
-
There is another suspicious use of I haven't figured out a way to get this use of |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've converted this into an issue for now until we figure out what the problem really is. We can then open one or more issues as needed. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Prompted by haskell/core-libraries-committee#338, I recently checked to see if Copilot has any problematic uses of the
realToFrac
function. There is one such use incopilot-bluespec
to convertFloat
s toDouble
s:copilot/copilot-bluespec/src/Copilot/Compile/Bluespec/Expr.hs
Line 539 in 894f0aa
As noted in haskell/core-libraries-committee#338,
realToFrac
currently mishandles certain special floating-point values. To see this in action, consider this Copilot specification:This defines a spec with a single trigger
rtf
, whose arguments sample fromFloat
streams containing several special values. We can see that the Copilot interpreter handles these special values correctly:Moreover, these special values are correctly translated to C99, as seen in this excerpt from the generated
test.c
file:The translation to Bluespec, on the other hand, produces malformed values, as seen in this excerpt from the generated
Test.bs
file:Note that NaN is mistranslated to
5.104235503814077e38
, both positive and negative infinity are mistranslated to3.402823669209385e38
, and negative zero is mistranslated to zero.There is an in-flight patch being proposed to fix haskell/core-libraries-committee#338 in the
base
library, but we should consider fixing this bug independently so thatcopilot-bluespec
can correctly translate specialFloat
values on all versions ofbase
that Copilot currently supports. My suspicion is that we could fix this bug by replacing the use ofrealToFrac
above withGHC.Float.float2Double
.Beta Was this translation helpful? Give feedback.
All reactions