%g format in printf
Mark Brader
msb at sq.sq.com
Sat Sep 9 11:32:33 AEST 1989
[Quoting style in quoted messages changed for consistency.]
Bradford R. Daniels (daniels at grue.dec.com) writes:
> > I learned in my high school ... that if I am asked to print out "1024"
> > with 1 significant digit, I should get "1000" printed out.
Chris Torek (chris at mimsy.UUCP) writes:
> No: "1000" has four significant digits (as does "1.000"); you need "1e3".
> I have seen arguments on both sides of this, but only believe the one
> that says `the number of digits written is the number of significant
> digits'.
Well, my high school agreed with Bradford's; I learned that either "1e3"
or "1000" had *one* significant digit, and that to write a value of
1000 with four significant digits you had to say "1000." or "1.000e3".
(Where "e" is taken as an ASCIIfication of "times sign, 10, superscript:")
But such an interpretation of "significant digit" would make section
4.9.6.1 impossible to satisfy for a conversion specification of "%4g"
and a value of 1000 -- the wording requires %f style and no trailing period
-- so it's clear that the authors of the pANS must have had in mind the
interpretation that Chris gives. Given that there seem to be two conflicting
interpretations it is a pity that they used the words "significant digits".
As for a value of 1024, of course "%.1g" of that should produce "1e3",
or rather, "1e+03".
--
Mark Brader Summary of issue: Fix FORTRAN-8x.
SoftQuad Inc., Toronto Committee Response: This proposal contains
utzoo!sq!msb insurmountable technical errors.
msb at sq.com -- X3J11 responses to 2nd public review
This article is in the public domain.
More information about the Comp.std.c
mailing list