You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4740 Reporter: delorimier Assigned to:@xavierleroy Status: closed (set by @xavierleroy on 2011-05-29T10:14:18Z) Resolution: fixed Priority: normal Severity: crash Version: 3.10.2 Fixed in version: 3.11.1+dev Category: ~DO NOT USE (was: OCaml general) Related to:#5513 Monitored by: delorimier
Bug description
(Int32.rem Int32.min_int Int32.minus_one) gives a machine generated floating point exception, and exits the toplevel interpretor.
The expression should return Int32.zero.
My machine is a 32 bit x86.
This bug occurs in version 3.10.2 bytecode and native.
It also occurs in version 3.10.0 bytecode, and I did not try native.
Here's an example:
% ocaml
Objective Caml version 3.10.2
open Int32;;
rem min_int minus_one;;
zsh: floating point exception ocaml
%
I couldn't find any other bad Int32.rem cases.
The text was updated successfully, but these errors were encountered:
Let's start with division first, since this is where the real problem lies. Dividing min_int by (-1) gives a result (- min_int) which is not representable in two's complement. Some processors (x86) raise a hardware exception in this case, other return min_int, yet others produce unspecified results.
Concerning remainder, min_int rem (-1) is perfectly representable since it is 0, but processors like x86 have only one instruction that computes the quotient and the remainder, so the same problems as with division occur.
I agree this undefined behavior in OCaml is not nice, therefore I implemented a fix whereas Int32.div Int32.min_int Int32.minus_one = Int32.min_int and Int32.rem Int32.min_int Int32.minus_one = Int32.zero. (Likewise for Int64 and Nativeint.) This behavior is consistent with that of "/" and "mod" at type int.
The fix is in the 3.11 bugfix branch and will be in release 3.11.1.
Original bug ID: 4740
Reporter: delorimier
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2011-05-29T10:14:18Z)
Resolution: fixed
Priority: normal
Severity: crash
Version: 3.10.2
Fixed in version: 3.11.1+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #5513
Monitored by: delorimier
Bug description
(Int32.rem Int32.min_int Int32.minus_one) gives a machine generated floating point exception, and exits the toplevel interpretor.
The expression should return Int32.zero.
My machine is a 32 bit x86.
This bug occurs in version 3.10.2 bytecode and native.
It also occurs in version 3.10.0 bytecode, and I did not try native.
Here's an example:
% ocaml
Objective Caml version 3.10.2
open Int32;;
rem min_int minus_one;;
zsh: floating point exception ocaml
%
I couldn't find any other bad Int32.rem cases.
The text was updated successfully, but these errors were encountered: