Anonymous user
Exponentiation operator: Difference between revisions
m
→{{header|OCaml}}: indentation
m (→{{header|OCaml}}: indentation) |
|||
Line 652:
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
used
<lang ocaml>let pow one mul a n =
let rec g p x = function
g (mul p p) (if i mod 2 = 1 then mul p x else x) (i/2) in g a one n;;▼
| 0 -> x
| i ->
in
g a one n
;;
pow 1 ( * ) 2 16;; (* 65536 *)
Line 674 ⟶ 680:
*)</lang>
See also [[Matrix-
=={{header|Perl}}==
|