Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004207OCaml~DO NOT USE (was: OCaml general)public2007-02-14 22:482007-02-21 15:14
Assigned To 
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product Version3.09.3 
Target VersionFixed in Version 
Summary0004207: int_of_float nan = 0, int_of_float infinity = 0
DescriptionIt seems that the only sane thing for int_of_float to do when presented with NaN is to raise an exception, the same goes for infinity.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
xleroy (administrator)
2007-02-21 15:14

The documentation for int_of_float does warn that the result is unspecified if the float argument falls outside the range of representable integers. I will add "or if the argument is NaN".

But, more generally, int_of_float inherits its semantics from that of the double -> long conversion of C or that of the corresponding machine instruction, just like other integer and float arithmetic operations in Caml. I don't think it would make sense to raise an exception in case of overflow for int_of_float but not for other arithmetic operations.

Note that if this is a serious problem in your application, it is possible to define a safer version of int_of_float, for instance:

let min_float_int = (* appropriate float constant close to min_int *)
let max_float_int = (* appropriate float constant close to max_int *)
let safe_int_of_float f =
  if f >= min_float_int && f <= max_float_int
  then int_of_float f
  else invalid_argument "safe_int_of_float"

- Issue History
Date Modified Username Field Change
2007-02-14 22:48 letaris New Issue
2007-02-21 15:14 xleroy Note Added: 0003923
2007-02-21 15:14 xleroy Status new => closed
2007-02-21 15:14 xleroy Resolution open => won't fix
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker