[comp.sys.next] printf bug?!

eric@bode.ee.ualberta.ca (Eric Norum,EB 547,4626) (07/01/90)

I've been getting gnuplot working on my machine (since Mathematica seems to
have no good way of getting semi-log plots....) and have found a bug in the
printing of floating point numbers.  At least I *think* it's a bug.

Look at the second, third, fourth and fifth rows of the fourth column, the
second, third and fourth rows of the fifth column, the second and third
rows of the sixth column, and the second row of the seventh (last) column.

%e		 %f		 %g	 %.g	 %.1g	 %.2g	 %.3g

1.000000e-05	 0.000010	 1e-05	 1e-05	 1e-05	 1e-05	 1e-05
1.000000e-04	 0.000100	 0.0001	 0	 0	 0	 0
1.000000e-03	 0.001000	 0.001	 0	 0	 0	 0.001
1.000000e-02	 0.010000	 0.01	 0	 0	 0.01	 0.01
1.000000e-01	 0.100000	 0.1	 0	 0.1	 0.1	 0.1
1.000000e+00	 1.000000	 1	 1e+00	 1	 1	 1
1.000000e+01	 10.000000	 10	 1e+01	 1e+01	 10	 10

K+R II says that `%g' format should use `%f' format when the exponent is
greater than or equal to -4 and less than the precision.  This is what
is happening above.
IMHO, it seems that when the exponent is between -1 and -4 the absolute
value of the exponent should be added to the precision before the `%f'
conversion is performed.

	eric

p.s. A good way of getting semi-log plots (for frequency responses, etc.)
     from Mathematica would be great!
Eric Norum
Dept. of Electrical Engineering      eric@bode.ee.ualberta.ca
University of Alberta
Edmonton, Canada.                   phone: (403) 492-4626