Skip to content

Instantly share code, notes, and snippets.

@agushuley
Created September 30, 2012 10:44
Show Gist options
  • Save agushuley/3806437 to your computer and use it in GitHub Desktop.
Save agushuley/3806437 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 2, 10th assignment
def pow( x: Double, p: Int ): Double = {
if ( p == 1 ) x
else if ( p == 0 ) 1
else if ( p < 0 ) 1 / pow( x, -p )
else if ( p % 2 == 0 ) {
val y = pow( x, p / 2)
y * y
}
else pow( x, p - 1) * x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment