From: Larry Wall Date: Wed, 15 Mar 1995 16:34:28 +0000 (-0800) Subject: [fix bug in print] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8bb9dbe4584e4740e744f2e392c02dc263a7baee;p=p5sagit%2Fp5-mst-13.2.git [fix bug in print] : In perl 5.001 the print function now only outputs one significant digit for the : the results of some mathematical functions. : : $ cat mine : #!/usr/bin/perl : print sqrt(2), "\n"; : print 4 * atan2(1,1), "\n"; : print log(2), "\n"; : $ ./mine : 1 : 3 : 0 Okay, I understand how this one happened. This is a case where a beneficial fix uncovered a bug elsewhere. I changed the constant folder to prefer integer results over double if the numbers are the same. In this case, they aren't, but it leaves the integer value there anyway because the storage is already allocated for it, and it *might* be used in an integer context. And since it's producing a constant, it sets READONLY. Unfortunately, sv_2pv() bogusly preferred the integer value to the double when READONLY was set. This never showed up if you just said print 1.4142135623731; because in that case, there was already a string value. Larry --- diff --git a/sv.c b/sv.c index 350356a..d2fecd0 100644 --- a/sv.c +++ b/sv.c @@ -1246,14 +1246,14 @@ STRLEN *lp; return s; } if (SvREADONLY(sv)) { - if (SvIOKp(sv)) { - (void)sprintf(tokenbuf,"%ld",(long)SvIVX(sv)); - goto tokensave; - } if (SvNOKp(sv)) { Gconvert(SvNVX(sv), DBL_DIG, 0, tokenbuf); goto tokensave; } + if (SvIOKp(sv)) { + (void)sprintf(tokenbuf,"%ld",(long)SvIVX(sv)); + goto tokensave; + } if (dowarn) warn(warn_uninit); *lp = 0;