-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix signum implementation #280
Conversation
Co-authored-by: Harry Garrood <[email protected]>
Co-authored-by: Harry Garrood <[email protected]>
test/Test/Main.purs
Outdated
testSignum :: AlmostEff | ||
testSignum = do | ||
assert "signum positive zero" $ signum 0.0 == 0.0 | ||
assert "signum negative zero" $ signum (-0.0) == (-0.0) |
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 doesn't work unfortunately - positive zero compares equal to negative zero. Maybe try show
-ing the result?
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.
Changing the test to
assert ("signum negative zero: " <> show (signum (-0.0))) $ show (signum (-0.0)) == "-0.0"
produces this error:
Error: signum negative zero: 0.0
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.
And assert (show (-0.0)) $ false
produces Error: 0.0
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.
Looks like Object.is
is a way to verify this.
Co-authored-by: Harry Garrood <[email protected]>
test/Test/Main.purs
Outdated
assert "signum positive zero" $ objectIs (signum 0.0) 0.0 | ||
assert "signum negative zero" $ objectIs (signum (-0.0)) (-0.0) | ||
|
||
-- Seems to be only way to check whether zero is `-0.0` or `0.0` |
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 forgot that our show
doesn't distinguish negative and positive zero. But, you can still distinguish them without the FFI:
show (1.0/0.0) == "Infinity"
show (1.0/(-0.0)) == "-Infinity"
Description of the change
Fixes #263. This is a breaking change that shouldn't be merged until we start the v0.15.x release cycle.
Checklist: