printf
printf copied to clipboard
possible `%g` minor non-compliance
There is minor problem with %g
specifier:
from https://www.gnu.org/software/libc/manual/html_node/Floating_002dPoint-Conversions.html#Floating_002dPoint-Conversions
The ‘%g’ and ‘%G’ conversions print the argument in the style of ‘%e’ or ‘%E’ (respectively) if the exponent would be less than -4 or greater than or equal to the precision; otherwise they use the ‘%f’ style. A precision of 0, is taken as 1. Trailing zeros are removed from the fractional portion of the result and a decimal-point character appears only if it is followed by a digit.
printf("%0-15.3g", -42.);
:
"-42.0 "glibc printf:
"-42 "
It seems to me that %g
should use shortest representation, precision is only upper limit, #
modifier may be used if decimal point is requested (unimplemented now)
(https://stackoverflow.com/questions/30658919/the-precision-of-printf-with-specifier-g)
See also issue #75.
Seems to be resolved by commit 84e66ae32e6225e1d9510f3b130337bd7607ea5b on my fork.