File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,16 @@ module Data.Ord
8
8
, min , max
9
9
, clamp
10
10
, between
11
+ , abs
12
+ , signum
11
13
, module Data.Ordering
12
14
) where
13
15
14
16
import Data.Eq (class Eq )
15
17
import Data.Function (on )
16
18
import Data.Ord.Unsafe (unsafeCompare )
17
19
import Data.Ordering (Ordering (..))
18
- import Data.Ring (negate )
20
+ import Data.Ring (class Ring , zero , one , negate )
19
21
import Data.Unit (Unit )
20
22
import Data.Void (Void )
21
23
@@ -149,3 +151,13 @@ between low hi x
149
151
| x < low = false
150
152
| x > hi = false
151
153
| true = true
154
+
155
+ -- | The absolute value function. `abs x` is defined as `if x >= zero then x
156
+ -- | else negate x`.
157
+ abs :: forall a . (Ord a , Ring a ) => a -> a
158
+ abs x = if x >= zero then x else negate x
159
+
160
+ -- | The sign function; always evaluates to either `one` or `negate one`. For
161
+ -- | any `x`, we should have `signum x * abs x == x`.
162
+ signum :: forall a . (Ord a , Ring a ) => a -> a
163
+ signum x = if x >= zero then one else negate one
You can’t perform that action at this time.
0 commit comments