printf %05f on infinity
Jeff Johnston
jjohnstn@redhat.com
Tue Apr 24 19:27:00 GMT 2007
Ok, but leave out the URL reference in the comment.
-- Jeff J.
Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> C99 basically requires the intuitive relation that if printf can generate
> something using a single % specifier, scanf can restore the same value
> (well, with the caveat that scanf can use a canonical NaN instead of
> supporting all 2^53 of them, and within the limits of rounding if the
> printf precision was too small). Or, more directly,
>
> "C99+TC1+TC2: 7.19.6.1 The fprintf function
> Paragraph 6, discussion on the '0' flag: ... leading zeros ...
> are used to pad to the field width rather than performing space
> padding, except when converting an infinity or NaN."
> http://www.opengroup.org/austin/mailarchives/ag/msg10445.html
>
> So printf("%05f",1./0) should result in " inf", not "00inf". OK to apply?
>
> 2007-04-12 Eric Blake <ebb9@byu.net>
>
> * libc/stdio/vfprintf.c (_VFPRINTF_F): Don't zero pad on infinity
> or NaN with %05f.
>
> - --
> Don't work too hard, make some time for fun as well!
>
> Eric Blake ebb9@byu.net
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (Cygwin)
> Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGHuo884KuGfSFAYARAtrHAJ43u0Y8SgDDwHdFOB467P917IxhyACeLKIJ
> X7qzFt/M6GRhy9XA4WwMo9c=
> =f8q4
> -----END PGP SIGNATURE-----
>
> ------------------------------------------------------------------------
>
> Index: libc/stdio/vfprintf.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 vfprintf.c
> --- libc/stdio/vfprintf.c 13 Apr 2007 01:57:33 -0000 1.49
> +++ libc/stdio/vfprintf.c 13 Apr 2007 02:18:02 -0000
> @@ -872,7 +872,14 @@ reswitch: switch (ch) {
> _fpvalue = GET_ARG (N, ap, double);
> }
>
> - /* do this before tricky precision changes */
> + /* do this before tricky precision changes
> +
> + If the output is infinite or NaN, leading
> + zeros are not permitted. Otherwise, scanf
> + could not read what print wrote.
> +
> + http://www.opengroup.org/austin/mailarchives/ag/msg10445.html
> + */
> if (isinf (_fpvalue)) {
> if (_fpvalue < 0)
> sign = '-';
> @@ -881,6 +888,7 @@ reswitch: switch (ch) {
> else
> cp = "inf";
> size = 3;
> + flags &= ~ZEROPAD;
> break;
> }
> if (isnan (_fpvalue)) {
> @@ -889,11 +897,12 @@ reswitch: switch (ch) {
> else
> cp = "nan";
> size = 3;
> + flags &= ~ZEROPAD;
> break;
> }
>
> #else /* !_NO_LONGDBL */
> -
> +
> if (flags & LONGDBL) {
> _fpvalue = GET_ARG (N, ap, _LONG_DOUBLE);
> } else {
> @@ -910,6 +919,7 @@ reswitch: switch (ch) {
> else
> cp = "inf";
> size = 3;
> + flags &= ~ZEROPAD;
> break;
> }
> if (tmp == 1) {
> @@ -918,6 +928,7 @@ reswitch: switch (ch) {
> else
> cp = "nan";
> size = 3;
> + flags &= ~ZEROPAD;
> break;
> }
> #endif /* !_NO_LONGDBL */
>
More information about the Newlib
mailing list