Skip to content

Commit

Permalink
Add abs.
Browse files Browse the repository at this point in the history
Closes #2.
  • Loading branch information
rgrempel committed Apr 10, 2016
1 parent b2c5d2e commit 612b5bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Data/Int53.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
-- | etc., in the usual way, since the ordinary classes for arithmetic are
-- | implemented. It should feel pretty much like using an ordinary integer.
-- |
-- | There are also functions for [`even`](#v:even), [`odd`](#v:odd), and [`pow`](#v:pow).
-- | There are also functions for [`even`](#v:even), [`odd`](#v:odd), [`pow`](#v:pow),
-- | and [`abs`](#v:abs).
-- |
-- | ### Converting an `Int53` to something else
-- |
Expand All @@ -44,7 +45,7 @@ module Data.Int53
, fromString, toString
, ceil, floor, round, truncate
, even, odd
, pow
, pow, abs
) where


Expand Down Expand Up @@ -312,6 +313,15 @@ pow (Int53 base) (Int53 exponent) =
else Int53 $ Math.pow base exponent


-- | Takes the absolute value.
-- |
-- | abs (fromInt 2) == (fromInt 2)
-- | abs (fromInt (-2)) == (fromInt 2)
-- | abs (fromInt 0) == (fromInt 0)
abs :: Int53 -> Int53
abs (Int53 i) = Int53 $ Math.abs i


-- | A class which allows a function to accept eitner an `Int` or an `Int53`,
-- | work with `Int53` internally, and then return whatever type was provided.
-- |
Expand Down
5 changes: 5 additions & 0 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ main = runTest do
pow (fromInt 0) (fromInt 0) ==> (fromInt 1)
pow (fromInt 2) (fromInt (-2)) ==> (fromInt 0)

test "abs" do
abs (fromInt 2) ==> (fromInt 2)
abs (fromInt (-2)) ==> (fromInt 2)
abs (fromInt 0) ==> (fromInt 0)

test "top" do
((topInt53 - one) + one) ==> topInt53

Expand Down

0 comments on commit 612b5bb

Please sign in to comment.