Skip to content

Commit

Permalink
Exponentiating by squaring
Browse files Browse the repository at this point in the history
  • Loading branch information
skyz1 committed Jul 16, 2023
1 parent 67e4d30 commit 050d047
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/Core/int.candy
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ pow base exponent :=
needs (is base)
needs (is exponent)
needs (isNonNegative exponent)
recursive exponent { recurse exponent ->
recursive [base, exponent] { recurse params ->
[base, exponent] = params
ifElse
(exponent | isPositive)
{ base | multiply (recurse (exponent | subtract 1)) }
(exponent | equals 0)
{ 1 }
{
ifElse
(exponent | isEven)
{ recurse [Base: base | multiply base, Exponent: exponent | shiftRight 1] }
{ base | multiply (recurse [Base: base | multiply base, Exponent: exponent | subtract 1 | shiftRight 1]) }
}
}

1 comment on commit 050d047

@jwbot
Copy link
Collaborator

@jwbot jwbot commented on 050d047 Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler

Benchmark suite Current: 050d047 Previous: 4ee0a88 Ratio
Time: Compiler/hello_world 18001269 ns/iter (± 340306) 20119411 ns/iter (± 384982) 0.89
Time: Compiler/fibonacci 165849699 ns/iter (± 687634) 164114398 ns/iter (± 1004162) 1.01
Time: VM Runtime/hello_world 63952 ns/iter (± 4195) 65651 ns/iter (± 2529) 0.97
Time: VM Runtime/fibonacci/15 494817104 ns/iter (± 1879130) 530565124 ns/iter (± 1725636) 0.93
Time: VM Runtime/PLB/binarytrees/6 2231622405 ns/iter (± 19538076) 2424239930 ns/iter (± 8095602) 0.92

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.