Skip to content

Correct signum function according to the Haskell report.#60

Merged
dmjio merged 1 commit intoarrayfire:masterfrom
leftaroundabout:bug/incorrect-signum-convention
Mar 31, 2026
Merged

Correct signum function according to the Haskell report.#60
dmjio merged 1 commit intoarrayfire:masterfrom
leftaroundabout:bug/incorrect-signum-convention

Conversation

@leftaroundabout
Copy link
Copy Markdown
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.
@dmjio dmjio merged commit 6e3c23a into arrayfire:master Mar 31, 2026
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.

2 participants