Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004740OCamlOCaml generalpublic2009-03-08 09:172012-02-23 15:58
Reporterdelorimier 
Assigned Toxleroy 
PrioritynormalSeveritycrashReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.10.2 
Target VersionFixed in Version3.11.1+dev 
Summary0004740: 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:
% 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.
TagsNo tags attached.
Attached Files

- Relationships
related to 0005513closedxleroy Int64.div causes floating point exception 

-  Notes
(0004850)
delorimier (reporter)
2009-03-08 21:52

I also get the same error with Int32.div
(0004887)
xleroy (administrator)
2009-03-28 19:44

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.

- Issue History
Date Modified Username Field Change
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
Powered by Mantis Bugtracker