aboutsummaryrefslogblamecommitdiff
path: root/tests/run/inlinePower/power_1.scala
blob: 4e96d7caa264e5ac7274d998f31f3e5ec65d9b11 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12



            
                                               






                                          
package p

object pow {

  inline def power(x: Double, n: Int): Double =
    if (n == 0) 1.0
    else if (n == 1) x
    else {
      val y = power(x, n / 2)
      if (n % 2 == 0) y * y else y * y * x
    }
}