[Tutor] Meaning of %g ?
Alan Gauld
alan.gauld at freenet.co.uk
Fri Apr 14 21:03:24 CEST 2006
>>> Hopefully those examples show whats happening.
>>> I have no idea why %g is dropping a digit, it may even be a bug!
>>
>> It looks to me like either a documentation error or a bug. It might be
>> worth asking on c.l.py.
>
> Which I did; see here for Fredrik Lundh's answer:
> http://groups.google.com/group/comp.lang.python/msg/f8dca0d28c426d48?hl=en&
Hmm, that says there is allowed to be a difference but not why there is a
difference.
The quote from the C standard would allow both e,f and g to have the same
precision.
In the original K&R(pre ANSI) it simply says %g is the shorter of %f and %e
with
no hint of any other modification. Given that the logical implementation for
%g
would be to use %e/%f format as required but for some odd reason its been
implemented differently.
So its not really a bug, since the spac allows for it, but is still strange
behaviour
Thanks for asking the question Kent, I was going to get around to it
sometime! :-)
IMHO.
Alan G.
More information about the Tutor
mailing list