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

Correct signum function according to the Haskell report. #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leftaroundabout
Copy link
Contributor

In Haskell, signum x is defined to be -1 if x is negative, 1 if it is positive, and 0 if x is 0.

(In particular, signum x * abs x ≡ x should hold.)

This is different from ArrayFire's sign function (which yields 1 for a negative number and 0 else), but it can be implemented in terms of that function:

  • For negative x, we have A.sign (-x) - A.sign x = 0 - 1 = -1
  • For x=0, we have A.sign (-x) - A.sign x = 1 - 1 = 0
  • For positive x, we have A.sign (-x) - A.sign x = 1 - 0 = 1

In Haskell, `signum x` is defined to be -1 if x is negative, 1 if it is positive,
and 0 if x is 0.
This is different from ArrayFire's `sign` function, but it can be implemented
in terms of this function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant