Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005739OCamlOCaml standard librarypublic2012-08-25 15:482013-07-19 11:10
Reportersmimram 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version3.12.1 
Target Version4.01.0+devFixed in Version4.01.0+dev 
Summary0005739: Printf.printf "%F" (-.nan) returns -nan
DescriptionWhen trying to generate code for OCaml (in OCaml) I expected Printf.printf "%F" to generate a float which is a valid expression in OCaml syntax: according to the documentation "%F converts a floating-point argument to Caml syntax". However,

# -nan;;
Error: This expression has type float but an expression was expected of type
         int
# Printf.printf "%F\n" (-.nan);;
-nan
- : unit = ()

Maybe should the last expression return "-.nan" (or the syntax could be modified to allow -nan).
Steps To ReproducePrintf.printf "%F\n" (-.nan);;
TagsNo tags attached.
Attached Files

- Relationships
related to 0004688resolvedfrisch Special floating-point values aren't converted to strings correctly under Windows 

-  Notes
(0007985)
gasche (developer)
2012-08-25 18:53
edited on: 2012-08-25 19:04

Confirmed under 3.12.1 and 4.00.

printf "%F" neg_infinity also prints "-inf" which suffers from the same problem. I think this was already discussed in 0004688.

If I understand correctly the patch of "dra" in 0004688, the effect of (printf "%F" (-.nan)) on the Windows platform (mingw or MSVC) could be to return "nan" instead of the negative nan on 4.00 -- I can't test myself, though.

(0009754)
doligez (administrator)
2013-07-11 16:32

What the hell is the meaning of the sign bit on nan??? Does -.nan mean "not a negative number"?

This prints "nan" on Mac OS X, but the problem with -inf remains.

Seriously, this needs to be fixed.
(0009807)
xleroy (administrator)
2013-07-19 11:10

The payload of NaNs include the sign bit. So, a sloppy float->string conversion could test the sign bit, emit a "-" sign, then notice the float is a NaN.

Fixed in 4.01 branch (commit 13910) and in trunk (commit 13911) by special-casing NaN and positive/negative infinity for "%F" conversions.

- Issue History
Date Modified Username Field Change
2012-08-25 15:48 smimram New Issue
2012-08-25 18:50 gasche Relationship added related to 0004688
2012-08-25 18:53 gasche Note Added: 0007985
2012-08-25 18:53 gasche Status new => confirmed
2012-08-25 19:04 gasche Note Edited: 0007985 View Revisions
2012-09-06 16:43 doligez Target Version => 4.00.1+dev
2012-09-27 14:53 doligez Target Version 4.00.1+dev => 4.00.2+dev
2013-07-11 16:32 doligez Note Added: 0009754
2013-07-11 16:32 doligez Target Version 4.00.2+dev => 4.01.0+dev
2013-07-19 11:10 xleroy Note Added: 0009807
2013-07-19 11:10 xleroy Status confirmed => resolved
2013-07-19 11:10 xleroy Resolution open => fixed
2013-07-19 11:10 xleroy Fixed in Version => 4.01.0+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker