Jump to content

Exponentiation operator: Difference between revisions

m (→‎{{header|OCaml}}: generic pow)
Line 656:
<lang ocaml>let pow one mul a n = let rec g p x = function 0 -> x | i ->
g (mul p p) (if i mod 2 = 1 then mul p x else x) (i/2) in g a one n;;
 
 
pow 1 ( * ) 2 16;; (* 65536 *)
Line 664 ⟶ 663:
pow 0 ( + ) 2 16;; (* 32 *)
pow "" ( ^ ) "abc " 10;; (* "abc abc abc abc abc abc abc abc abc abc " *)
pow [ ] ( @ ) [ 1; 2 ] 10;; (* [1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2] *)</lang>
</lang>
 
See also [[Matrix-exponentiation_operator#OCaml]] for a matrix usage.
 
=={{header|Perl}}==
506

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.