floating-point formatting issue

Allin Cottrell cottrell@wfu.edu
Sun Jul 29 09:04:00 GMT 2007


I'm running this by the list in case it's already handled in CVS.
There's an issue with the handling of the "%g" format specifier
in the glibc 2.6 release.  Consider this program:

#include <stdio.h>

int main (void)
{
    printf("x = %#.5g\n", 51.0);
    printf("y = %#.5g\n", 50.999999);

    return 0;
}

As I understand the C standard, this should print

x = 51.000
y = 51.000

but on my system with glibc 2.6 it prints

x = 51.000
y = 51.00

(This seems to be the converse of a bug in glibc <= 2.5, whereby 
it would append an extra zero when printing certain numbers with 
the "%#.<digits>g" specifier.)

-- 
Allin Cottrell
Department of Economics
Wake Forest University, NC



More information about the Libc-alpha mailing list