Skip to content

Fix signum implementation #280

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

Merged
merged 12 commits into from
Mar 16, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based
## [Unreleased]

Breaking changes:
- Fix `signum` to return `one` when `x > zero` (#280 by @JordanMartinez)

New features:

Expand Down
8 changes: 5 additions & 3 deletions src/Data/Ord.purs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ between low hi x
abs :: forall a. Ord a => Ring a => a -> a
abs x = if x >= zero then x else negate x

-- | The sign function; always evaluates to either `one` or `negate one`. For
-- | any `x`, we should have `signum x * abs x == x`.
-- | The sign function; always evaluates to `negate one`, `zero` or `one`.
signum :: forall a. Ord a => Ring a => a -> a
signum x = if x >= zero then one else negate one
signum x =
if x < zero then negate one
else if x > zero then one
else zero

-- | The `Ord1` type class represents totally ordered type constructors.
class Eq1 f <= Ord1 f where
Expand Down