Skip to content

Instantly share code, notes, and snippets.

@styx
Forked from alco/ipow.ex
Created October 12, 2013 08:40
Show Gist options
  • Save styx/6947513 to your computer and use it in GitHub Desktop.
Save styx/6947513 to your computer and use it in GitHub Desktop.
defmodule IntMath do
use Bitwise
def pow(_, 0), do: 1
def pow(a, 1), do: a
def pow(a, n) when band(n, 1) === 0 do
tmp = pow(a, n >>> 1)
tmp * tmp
end
def pow(a, n) do
a * pow(a, n-1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment