Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007507OCamldocumentationpublic2017-03-22 14:362017-05-08 23:18
ReporterArmael 
Assigned Tooctachron 
PrioritynormalSeverityminorReproducibilityN/A
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.06.0+dev 
Summary0007507: Documentation for Printf's format "%g" looks imprecise or incorrect
DescriptionIn stdlib/printf.mli, the documentation for the %g format states:

   - [g] or [G]: convert a floating-point argument to decimal notation, in style [f] or [e], [E] (whichever is more compact).

However:

- [Printf.printf "%f" 1.] prints "1.000000"
- [Printf.printf "%e" 1.] prints "1.000000e+00"
- [Printf.printf "%g" 1.] prints "1", which corresponds to neither "%f" or "%e".

This seems to indicate that the documentation for %g is quite vague, at best.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0017691)
gasche (developer)
2017-03-22 15:02

I have bad news for you: OCaml does not implement %g itself, it delegates to the libc's %g format semantics (see: "man 3 printf"). This means that you will get inconsistent results across platforms and that giving a precise and correct specification is unlikely to succeed.
(0017692)
Armael (reporter)
2017-03-22 15:07

Could the documentation refer to the libc's semantics, then?
(0017699)
xleroy (administrator)
2017-03-24 18:56

Quoting from the glibc man pages:

              The double argument is converted in style f or e (or F or E for
              G conversions). The precision specifies the number of signifi?
              cant digits. If the precision is missing, 6 digits are given;
              if the precision is zero, it is treated as 1. Style e is used
              if the exponent from its conversion is less than -4 or greater
              than or equal to the precision. Trailing zeros are removed from
              the fractional part of the result; a decimal point appears only
              if it is followed by at least one digit.

So, the summary in the OCaml documentation is not too bad. If we really want, we could add a sentence about trailing zeros possibly removed.
(0017700)
octachron (developer)
2017-03-24 19:29

Reading the OCaml documentation, I would think that the most surprising part is the elision of the decimal point which does happen for neither %f, %e or %E. Should I document this point?
(0017701)
gasche (developer)
2017-03-24 19:35

Follow your heart.
(0017780)
octachron (developer)
2017-05-08 14:47

The corresponding github PR, directly inspired from the C90 standard description, is here https://github.com/ocaml/ocaml/pull/1163 [^] .

Armael, do you wish to be cited in the changelog?
(0017781)
Armael (reporter)
2017-05-08 15:40

No, don't bother. Thanks for taking care of this!

- Issue History
Date Modified Username Field Change
2017-03-22 14:36 Armael New Issue
2017-03-22 15:02 gasche Note Added: 0017691
2017-03-22 15:07 Armael Note Added: 0017692
2017-03-24 18:56 xleroy Note Added: 0017699
2017-03-24 18:56 xleroy Status new => acknowledged
2017-03-24 19:29 octachron Note Added: 0017700
2017-03-24 19:35 gasche Note Added: 0017701
2017-05-08 14:47 octachron Note Added: 0017780
2017-05-08 15:40 Armael Note Added: 0017781
2017-05-08 23:18 octachron Status acknowledged => resolved
2017-05-08 23:18 octachron Fixed in Version => 4.06.0+dev
2017-05-08 23:18 octachron Resolution open => fixed
2017-05-08 23:18 octachron Assigned To => octachron


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker