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

Maths #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add absolute value
tredontho committed Oct 3, 2021
commit 0140f8fdbacada9a7a9a6c6a3f023a4b8e84a5e4
9 changes: 9 additions & 0 deletions src/Maths/Abs.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Maths.Abs where

import Prelude hiding (abs)

-- The absolute value of a number greater than or equal to 0 is simply that number.
-- The absolute value of a number less than 0 is the negation of that number
abs :: (Num a, Ord a) => a -> a
abs n | n < 0 = negate n
| otherwise = n