Skip to content

signum should return zero when given zero (currently returns one) #263

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

Closed
triallax opened this issue Jun 21, 2021 · 3 comments · Fixed by #280
Closed

signum should return zero when given zero (currently returns one) #263

triallax opened this issue Jun 21, 2021 · 3 comments · Fixed by #280
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.

Comments

@triallax
Copy link
Contributor

So I asked about this on the Slack channel, and @hdgarrood said that this was probably an oversight and that he thinks this should be fixed, based on the assumption that the function is not widely used, as this question was not asked before as far as he is aware.

@hdgarrood
Copy link
Contributor

hdgarrood commented Jun 21, 2021

See e.g. https://en.wikipedia.org/wiki/Sign_function. I think PureScript is pretty much unique in believing that signum 0 = 1.

@thomashoneyman thomashoneyman added the type: breaking change A change that requires a major version bump. label Jun 21, 2021
@JordanMartinez JordanMartinez added the purs-0.15 A reminder to address this issue or merge this PR before we release PureScript v0.15.0 label Dec 1, 2021
@JamieBallingall
Copy link
Contributor

JamieBallingall commented Mar 2, 2022

How would you feel about changing the implementation to:

signum x =
  if x < zero then negate one
  else if x > zero then one
  else x

I.e., returning x if x equals zero rather than returning zero. In any sane instance of Ring this would be the same but Number instantiates Ring and has two zero-like values: +0.0 and -0.0. The Javascript implementation of Math.sign makes this distinction and I think it would be nice to have signum and sign work the same way on Number.

In fact, perhaps we should implement this new function as sign and depreciate signum.

@JordanMartinez
Copy link
Contributor

@JamieBallingall That implementation is what I have in #280.

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 a pull request may close this issue.

5 participants