Exponentiation operator: Difference between revisions
Content added Content deleted
No edit summary |
(Realize in F#) |
||
Line 861: | Line 861: | ||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
<lang fsharp> |
|||
//Integer Exponentiation, more interesting anyway than repeated multiplication. Nigel Galloway, October 12th., 2018 |
|||
let rec myExp n g=match g with |
|||
|0 ->1 |
|||
|g when g%2=1 ->n*(myExp n (g-1)) |
|||
|_ ->let p=myExp n (g/2) in p*p |
|||
printfn "%d" (myExp 3 15) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
14348907 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Simple, unoptimized implementation which accepts a positive or negative exponent: |
Simple, unoptimized implementation which accepts a positive or negative exponent: |
||
Line 897: | Line 911: | ||
] until |
] until |
||
drop * ;</lang> |
drop * ;</lang> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
<lang forth>: ** ( n m -- n^m ) |
<lang forth>: ** ( n m -- n^m ) |