Commits

arkdro committed bcaab14

add bias numbers, that is necessary for ocaml Int32.to_int
on 32-bit platform

Comments (0)

Files changed (1)

erlang/src/c_server.erl

     Cmd = term_to_binary({get, none}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
-handle_call({multiply_list, Term}, From,
+handle_call({multiply_list, List}, From,
             #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({mult_list, Term}),
+    Blist = bias_list(List),
+    Cmd = term_to_binary({mult_list, Blist}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
 handle_call({multiply, N1, N2}, From,
             #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({multiply, N1, N2}),
+    B1 = bias_number(N1),
+    B2 = bias_number(N2),
+    Cmd = term_to_binary({multiply, B1, B2}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
-handle_call({sum, Term}, From, #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({sum_list, Term}),
+handle_call({sum, List}, From, #state{status=running, port=Port} = State) ->
+    Blist = bias_list(List),
+    Cmd = term_to_binary({sum_list, Blist}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
 handle_call({add, N1, N2}, From,
             #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({add, N1, N2}),
+    B1 = bias_number(N1),
+    B2 = bias_number(N2),
+    Cmd = term_to_binary({add, B1, B2}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
 handle_call({subtract, N1, N2}, From,
             #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({subtract, N1, N2}),
+    B1 = bias_number(N1),
+    B2 = bias_number(N2),
+    Cmd = term_to_binary({subtract, B1, B2}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
 handle_call({divide, N1, N2}, From,
             #state{status=running, port=Port} = State) ->
-    Cmd = term_to_binary({divide, N1, N2}),
+    B1 = bias_number(N1),
+    B2 = bias_number(N2),
+    Cmd = term_to_binary({divide, B1, B2}),
     port_command(Port, Cmd),
     {noreply, State#state{from=From}};
 handle_call(stop, _From, St) ->
     {ok, State}.
 
 %-------------------------------------------------------------------
+bias_number({Sign, Mant, Exp}) when Mant >= (2 bsl 30) and Mant < (2 bsl 31) ->
+    %% this is necessary as ocaml Int32.to_int on 32-bit platform
+    %% behaves as Int31, e.g. truncates highest bit
+    {Sign, Mant * 10000000000, Exp - 10};
+bias_number(N) ->
+    N.
+
+%-------------------------------------------------------------------
+bias_list(L) ->
+    [bias_number(X) || X <- L].
+
+%-------------------------------------------------------------------
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.