From: grundy@rtf.bt.co.uk (Martin Grundy) Subject: Problem with %g in printf()? Date: 14 Jan 1993 11:59:53 GMT
Hi all...
I am having a slight problem with the "%g" format specifier in printf.
A program I wrote several years ago uses the following printf statement
to output the results of a calculation:-
double f, o1.o2;
printf("%-16g%-16.4g%-16.4g\n", f, o1, o2);
An example of the output is (from bsd unix and MSC v5.1 under ms-dog):-
300 -13.05 -91.28
3794.04 -3.077 94.03
4000 -3.755 93.72
There are 16 character spaces between each column as one would expect.
However, compiling under gcc v2.2.2d on linux 0.99.2 (with libc 4.2 and
kernel maths emulation) the output is:-
300 -13.05 -91.28
3794.04 -3.077 94.03
4000 -3.755 93.72
The output is correct for the second line where there the first value
contains a decimal, but for the first and third lines where the 1st value
has no decimal point, the 2nd and 3rd values are displaced right by the
number of trailing zeros of the 1st value!
Has anybody seen this before, and is it a bug or feature?