Last active
June 3, 2017 08:36
-
-
Save rlbaker/c6f46cf33afa6326f9d4 to your computer and use it in GitHub Desktop.
Floor/Ceil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MathOps do | |
def floor(x) when x < 0 do | |
t = trunc x | |
case x-t == 0 do | |
true -> t | |
false -> t - 1 | |
end | |
end | |
def floor(x) do | |
trunc x | |
end | |
def ceiling(x) when x < 0 do | |
trunc x | |
end | |
def ceiling(x) do | |
t = trunc x | |
case x-t == 0 do | |
true -> t | |
false -> t + 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment