Just trying out scala, trying to implement the following
An efficient way of computing a power x^n (where n is a nonnegative integer) is given by the recursion
x^n = y^2 if n is even and positive, where y = x^(n / 2)
x^n = x· x^(n - 1) if n is odd
x^0 = 1
Write a Scala function pow(x : Double, n : Int) : Int that implements this algorithm. What is the code of your function?
Here's my code:
but this seems to go into an infinite loop when I try for example pow2(2,2). What's wrong with it?
Also, is there a keyboard or something you can use to break out of a scala command? I'm using Windows PowerShell and the only key combo that seems to do anything is Ctrl+Break which gives me a
thread dump from Hotspot and doesn't let me continue with my session.