Created
September 30, 2012 10:44
-
-
Save agushuley/3806437 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 2, 10th assignment
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
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