Skip to content
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

Merged
merged 12 commits into from
Mar 16, 2022
Merged

Fix signum implementation #280

merged 12 commits into from
Mar 16, 2022

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Feb 13, 2022

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:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@JordanMartinez JordanMartinez added type: breaking change A change that requires a major version bump. purs-0.15 A reminder to address this issue or merge this PR before we release PureScript v0.15.0 labels Feb 13, 2022
JordanMartinez and others added 2 commits March 2, 2022 18:00
Co-authored-by: Harry Garrood <[email protected]>
testSignum :: AlmostEff
testSignum = do
assert "signum positive zero" $ signum 0.0 == 0.0
assert "signum negative zero" $ signum (-0.0) == (-0.0)
Copy link
Contributor

@hdgarrood hdgarrood Mar 3, 2022

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

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`
Copy link
Contributor

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"

@JordanMartinez
Copy link
Contributor Author

🏓 @thomashoneyman

@JordanMartinez JordanMartinez merged commit ab5ebda into purescript:master Mar 16, 2022
@JordanMartinez JordanMartinez deleted the fix-signum branch March 16, 2022 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
purs-0.15 A reminder to address this issue or merge this PR before we release PureScript v0.15.0 type: breaking change A change that requires a major version bump.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

signum should return zero when given zero (currently returns one)
4 participants