Skip to content

Instantly share code, notes, and snippets.

@InvisibleTech
Created September 6, 2015 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InvisibleTech/bc5af79928145d783435 to your computer and use it in GitHub Desktop.
Save InvisibleTech/bc5af79928145d783435 to your computer and use it in GitHub Desktop.
Just a simple power function for an integer exponent. Just for fun.
def pow(x: Double, n: Int) : Double = {
n match {
case 0 => 1.0
case n if n < 0 => 1.0 / pow(x, Math.abs(n))
case n if (n & 0x1) == 0 => pow(x, n >> 1) * pow(x, n >> 1)
case _ => x * pow(x, n - 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment