Commits

arkdro committed 668a358

use decimal tuple for add

Comments (0)

Files changed (1)

   | _, _ ->
     Eterm.ET_tuple [|(Eterm.ET_atom "error"); (Eterm.ET_atom "wrong_arguments");|]
 
+let op_add x1 x2 =
+  let t1 = make_tuple x1 in
+  let t2 = make_tuple x2 in
+  match t1, t2 with
+  | Some _, Some _ ->
+    let (Some n1) = make_num t1 in
+    let (Some n2) = make_num t2 in
+    let res = Num.add_num n1 n2 in
+    Eterm.ET_tuple [|(Eterm.ET_atom "ok"); make_decimal_tuple res;|]
+  | _, _ ->
+    Eterm.ET_tuple [|(Eterm.ET_atom "error"); (Eterm.ET_atom "wrong_arguments");|]
+
 let handle_payload = function
     | Eterm.ET_tuple [|(Eterm.ET_atom "divide"); x1; x2;|] ->
       Trace.dbg "handle_payload" "divide\n%!";
     | Eterm.ET_tuple [|(Eterm.ET_atom "subtract"); x1; x2;|] ->
       Trace.dbg "handle_payload" "subtract\n%!";
       op_subtract x1 x2
-    | Eterm.ET_tuple [|(Eterm.ET_atom "add"); Eterm.ET_bignum n1; Eterm.ET_bignum n2;|] ->
-      Trace.dbg "handle_payload" "add bignums\n%s\n%s\n%!"
-        (Num.string_of_num n1) (Num.string_of_num n2);
-      let res = Num.add_num n1 n2 in
-      Eterm.ET_bignum res
+    | Eterm.ET_tuple [|(Eterm.ET_atom "add"); x1; x2;|] ->
+      Trace.dbg "handle_payload" "add\n%!";
+      op_add x1 x2
     | Eterm.ET_tuple [|(Eterm.ET_atom "multiply"); Eterm.ET_bignum n1; Eterm.ET_bignum n2;|] ->
       Trace.dbg "handle_payload" "mult bignums\n%s\n%s\n%!"
         (Num.string_of_num n1) (Num.string_of_num n2);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.