-
Notifications
You must be signed in to change notification settings - Fork 17
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
Use scientific to fix floating point rounding problems #58
base: master
Are you sure you want to change the base?
Conversation
Testsuite fails, missing instances
|
instance FromYAML Double where | ||
instance FromYAML Scientific where | ||
parseYAML = withFloat "!!float" pure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for removing FromYAML
and ToYAML Double
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's an argument for going either way. My thought was that it's mainly there for the vales actually supported as scalar primitives, and since this PR changes the scalar numeric primitive from Double to Scientific, that seemed to be the obvious route to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we also provide instances for types like Int8
and tuples, so I think we ought to keep the Double
instances.
@@ -1,4 +1,4 @@ | |||
packages: . | |||
|
|||
package HsYAML | |||
flags: +exe | |||
flags: +exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you undo this change?
instance FromYAML Double where | ||
instance FromYAML Scientific where | ||
parseYAML = withFloat "!!float" pure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we also provide instances for types like Int8
and tuples, so I think we ought to keep the Double
instances.
encodeDouble :: Scientific -> T.Text | ||
encodeDouble d = T.pack . show $ d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be named encodeFloat
for consistency with encodeInt
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is there a more efficient way to perform this encoding?
I don't really have any experience with -XSafe. I'm fine with removing it for now and waiting until someone comes along who cares. :) |
What is the error if |
Here's a proof of concept. Do you have a preference about how to resolve the
LANGUAGE Safe
bit? I was unsure about that.