Commits

arkdro committed cdfd061

add functions for decimals

Comments (0)

Files changed (1)

 let precision = 100
 
+let make_tuple = function
+  | Eterm.ET_tuple [|Eterm.ET_int n1; Eterm.ET_int n2; Eterm.ET_int n3;|] ->
+    Some (Int32.to_int n1,
+          Num.num_of_int (Int32.to_int n2),
+          Int32.to_int n3)
+  | Eterm.ET_tuple [|Eterm.ET_int n1; Eterm.ET_bignum n2; Eterm.ET_int n3;|] ->
+    Some (Int32.to_int n1, n2, Int32.to_int n3)
+  | _x ->
+    None
+
+let compose_num mant = function
+  | pow when pow >= 0 ->
+    let ipow = Big_int.power_int_positive_int 10 pow in
+    let bpow = Num.Big_int ipow in
+    Num.mult_num mant bpow
+  | pow ->
+    let ipow = Big_int.power_int_positive_int 10 (-pow) in
+    let bpow = Num.Big_int ipow in
+    Num.div_num mant bpow
+
+let make_num = function
+  | Some (0, mant, pow) ->
+    Some (compose_num mant pow)
+  | Some (1, mant, pow) ->
+    Some (Num.minus_num (compose_num mant pow))
+  | None ->
+    None
+
 let conv_sign = function
   | -1 -> 1
   | 0 -> 0