diff options
Diffstat (limited to 'tests/run/inlinePower/power_1.scala')
-rw-r--r-- | tests/run/inlinePower/power_1.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/run/inlinePower/power_1.scala b/tests/run/inlinePower/power_1.scala new file mode 100644 index 000000000..1faa10516 --- /dev/null +++ b/tests/run/inlinePower/power_1.scala @@ -0,0 +1,13 @@ +package p + +object pow { + + @dotty.annotation.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 + } +} |