Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007690OCamlstandard librarypublic2017-12-13 15:462017-12-19 15:24
Reporteroandrieu 
Assigned Tonojebar 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.03.0 
Target VersionFixed in Version 
Summary0007690: issues with caml_float_of_hex
DescriptionThere are some overflow issues with the exponent computations in caml_float_of_hex, which results in some invalid conversions. The integer exp variable overflows, which results in the call to ldexp to overflow when it should underflow (and vice versa).

The test "if (e < INT_MIN || e > INT_MAX) return -1;" is ineffective on Win64 since int and long have the same size there: this results in some difference in behavior between win64 and linux.

And (minor point), the function accept spaces between the 'p' and the exponent digits, whereas strtod and the C99 syntax do not allow spaces there.
Steps To Reproduce$ cat f.ml
let hexstring_of_float x =
  Printf.sprintf "%h" x

let () =
  let s =
    try hexstring_of_float (float_of_string Sys.argv.(1))
    with _ -> "invalid" in
  print_endline s

$ ocamlopt.opt f.ml

$ ./a.out 0x1.0p-2147483648
infinity

$ ./a.out 0x123456789ABCDEF0p2147483647
0x0p+0

$ ./a.out 0x1p2147483648
-> invalid on linux64
-> infinity on win64

$ ./a.out '0x1p 1'
0x1p+1
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0018743)
oandrieu (reporter)
2017-12-13 17:12

I can provide a GPR if you think these corner cases are worth fixing.
(0018744)
nojebar (developer)
2017-12-13 17:14

Definitely the overflow one needs fixing; a GPR would be much appreciated!
Regarding the second one, I am not sure if it is a bug or not at the moment.
(0018745)
oandrieu (reporter)
2017-12-13 20:09

there, GPR#1528 : https://github.com/ocaml/ocaml/pull/1528 [^]
(0018752)
nojebar (developer)
2017-12-19 15:24

This PR has now been merged, so marking this resolved.

- Issue History
Date Modified Username Field Change
2017-12-13 15:46 oandrieu New Issue
2017-12-13 17:12 oandrieu Note Added: 0018743
2017-12-13 17:14 nojebar Note Added: 0018744
2017-12-13 20:09 oandrieu Note Added: 0018745
2017-12-19 15:24 nojebar Note Added: 0018752
2017-12-19 15:24 nojebar Status new => resolved
2017-12-19 15:24 nojebar Resolution open => fixed
2017-12-19 15:24 nojebar Assigned To => nojebar


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker