Exponentiation operator: Difference between revisions
Content added Content deleted
m (→{{header|OCaml}}: indentation) |
|||
Line 652: | Line 652: | ||
It is possible to create a generic exponential. For this, one must know the |
It is possible to create a generic exponential. For this, one must know the |
||
multiplication function, and the unit value. Here, the usual fast algorithm is |
multiplication function, and the unit value. Here, the usual fast algorithm is |
||
used |
used: |
||
<lang ocaml>let pow one mul a n = |
<lang ocaml>let pow one mul a n = |
||
let rec g p x = function |
|||
⚫ | |||
| 0 -> x |
|||
| i -> |
|||
⚫ | |||
in |
|||
g a one n |
|||
;; |
|||
pow 1 ( * ) 2 16;; (* 65536 *) |
pow 1 ( * ) 2 16;; (* 65536 *) |
||
Line 674: | Line 680: | ||
*)</lang> |
*)</lang> |
||
See also [[Matrix- |
See also [[Matrix-exponentiation operator#OCaml]] for a matrix usage. |
||
=={{header|Perl}}== |
=={{header|Perl}}== |