|Anonymous | Login | Signup for a new account||2017-01-22 13:17 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0004740||OCaml||OCaml general||public||2009-03-08 09:17||2012-02-23 15:58|
|Target Version||Fixed in Version||3.11.1+dev|
|Summary||0004740: Int32.rem floating point exception|
|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:
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.
|Tags||No tags attached.|
|I also get the same error with Int32.div|
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.
|2009-03-08 09:17||delorimier||New Issue|
|2009-03-08 21:52||delorimier||Note Added: 0004850|
|2009-03-28 16:57||xleroy||Status||new => assigned|
|2009-03-28 16:57||xleroy||Assigned To||=> xleroy|
|2009-03-28 19:44||xleroy||Note Added: 0004887|
|2009-03-28 19:44||xleroy||Status||assigned => resolved|
|2009-03-28 19:44||xleroy||Resolution||open => fixed|
|2009-04-02 11:55||xleroy||Fixed in Version||=> 3.11.1+dev|
|2011-05-29 12:14||xleroy||Status||resolved => closed|
|2012-02-23 15:58||xleroy||Relationship added||related to 0005513|
|Copyright © 2000 - 2011 MantisBT Group|