Skip to content

Instantly share code, notes, and snippets.

@rlbaker
Last active June 3, 2017 08:36
Show Gist options
  • Save rlbaker/c6f46cf33afa6326f9d4 to your computer and use it in GitHub Desktop.
Save rlbaker/c6f46cf33afa6326f9d4 to your computer and use it in GitHub Desktop.
Floor/Ceil
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