7c21a61c0b2f19f1fc64628c723d6bc8d00c04f7
[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;;
30
31 let remainder_float : float -> float -> float =
32 fun f1 -> fun f2 ->
33 let r = mod_float f1 f2 in
34 if (abs_float r) > ((abs_float f2) /. 2.) then
35 (if r *. f2 > 0. then (r -. f2) else (r +. f2))
36 else r;;