a33e7228d654b74c2807120bae212334fcdf5374
[Faustine.git] / interpretor / aux.ml
1 (**
2 Module: Aux
3 Description: all auxiliary functions
4 @author WANG Haisheng
5 Created: 12/08/2013 Modified: 13/08/2013
6 *)
7
8 let array_map2 = fun f -> fun a -> fun b ->
9 let n1 = Array.length a in
10 let n2 = Array.length b in
11 if n1 = n2 then Array.init n1 (fun i -> f a.(i) b.(i))
12 else raise (Invalid_argument "Array.map2 size not matched.");;
13
14 let array_map3 = fun f -> fun a -> fun b -> fun c ->
15 let n1 = Array.length a in
16 let n2 = Array.length b in
17 let n3 = Array.length c in
18 if n1 = n2 && n1 = n3 then Array.init n1 (fun i -> f a.(i) b.(i) c.(i))
19 else raise (Invalid_argument "Array.map3 size not matched.");;
20
21 let decorate = fun s -> " Faustine -> " ^ s;;
22
23 let xor : bool -> bool -> bool =
24 fun a -> fun b -> (a || b) && (not (a && b));;
25
26 let rint : float -> float =
27 fun f ->
28 if (f -. (floor f)) >= 0.5 then ceil f
29 else floor f;;