[PATCH] make printf output for Infinity and NaN match C99 standard
Jeff Johnston
jjohnstn@redhat.com
Tue Oct 11 23:11:00 GMT 2005
Patch checked in.
-- Jeff J.
Bob Wilson wrote:
> As you can probably tell, I'm working on contributing a bunch of changes
> from Tensilica's copy of newlib. Here's another one, done by David
> Weatherford. I've also got a bunch of documentation fixes that I'll try
> to sort through next week.
>
> Anyway, this patch makes the output of Infinity and NaN floating-point
> values match the C99 specification: "inf" and "nan" for e/f/g formats
> and uppercase versions of those for E/F/G formats. The 'F' format
> wasn't even recognized, so the patch fixes that, too.
>
> 2005-10-06 David Weatherford <weath@tensilica.com>
>
> * libc/stdio/vfprintf.c (_VFPRINTF_R): Recognize 'F' format.
> Print "inf" and "nan" in lowercase for e/f/g formats and in uppercase
> for E/F/G formats.
>
>
> ------------------------------------------------------------------------
>
> Index: libc/stdio/vfprintf.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
> retrieving revision 1.40
> diff -u -r1.40 vfprintf.c
> --- libc/stdio/vfprintf.c 16 Jun 2005 19:14:01 -0000 1.40
> +++ libc/stdio/vfprintf.c 6 Oct 2005 21:23:21 -0000
> @@ -800,6 +800,7 @@
> case 'e':
> case 'E':
> case 'f':
> + case 'F':
> case 'g':
> case 'G':
> if (prec == -1) {
> @@ -819,12 +820,18 @@
> if (isinf (_fpvalue)) {
> if (_fpvalue < 0)
> sign = '-';
> - cp = "Inf";
> + if (ch == 'E' || ch == 'F' || ch == 'G')
> + cp = "INF";
> + else
> + cp = "inf";
> size = 3;
> break;
> }
> if (isnan (_fpvalue)) {
> - cp = "NaN";
> + if (ch == 'E' || ch == 'F' || ch == 'G')
> + cp = "NAN";
> + else
> + cp = "nan";
> size = 3;
> break;
> }
More information about the Newlib
mailing list