Last active
August 29, 2015 14:11
-
-
Save swanhtet1992/f4af9cb4dca704945e3d to your computer and use it in GitHub Desktop.
Solution for λ Talks in Yangon registration quiz
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 multiply(x: Double, n: Double): Double = { | |
if (n == 0) 0 else x + multiply(x, n - 1) | |
} | |
def power(b: Int, e: Int): Double = { | |
if (e > 0) multiply(b.toDouble, power(b, e - 1)) | |
else if (e < 0) 1/power(b, -e) // let me use / for negative e :P | |
else 1.0 | |
} | |
power(2, 8) // 256.0 | |
power(2, -8) //0.00390625 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kyite tal kwar