This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Return 0 (with a warning) for sprintf("%.0g") and sprintf("%.0f")
authorNicholas Clark <nick@ccl4.org>
Thu, 13 May 2010 11:04:55 +0000 (12:04 +0100)
committerNicholas Clark <nick@ccl4.org>
Thu, 13 May 2010 11:04:55 +0000 (12:04 +0100)
commit95ea86d57f54b7436354f58e8ed9989a65c974a8
treea535437458b99c431787f1fac9caa36be4d94de8
parentbc643a33723eaabcc2e2444f4a9034de283df5c0
Return 0 (with a warning) for sprintf("%.0g") and sprintf("%.0f")

There is special case code in the sprintf implementation, for simple %f and %g
formats, conditionally compiled in only when NVs are doubles. Under long
doubles, these are handled by the general purpose code, which always returns
0 if the argument is missing. Note that sprintf(" %.0g"), ie a leading space,
sufficient to bypass the special case code, would return the string " 0".

The special case code used to return an empty string, meaning that the
behaviour of sprintf("%.0g") and sprintf("%.0f") was inconsistent between a
perl built with doubles, and a perl with long doubles, and the behaviour of
sprintf("%.0g") and sprintf(" %.0g") was inconsistent.

5b98cd54dff3b163 fixed #62874 - the special case code did not warn, but
changed behaviour to return 0. d347ad18ecf3da70 undid the behaviour change,
viewing it as a regression. However, the tests added in 5b98cd54dff3b163
expose the inconsistency in behaviour between doubles and long doubles.

There should be no inconsistency, hence the only logically consistent
conclusion is that the special case implementation was wrong - it cannot
give results inconsistent with the general code. Hence this commit changes
it to return 0 (with a warning). This is achieved by simply skipping the
special case code, if there are insufficient arguments.
sv.c
t/op/sprintf.t