: 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
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;