[A complimentary Cc of this posting was sent to
Brian Blackmore
#!/usr/bin/perl
$a=42.1; for (1..30) { $a+=0.1 }
$b="$a"; print "a=",$a," b=",$b,"\n";
$a==$b ? print "Equal\n" : print "Not equal\n" ;
I would like to know for future reference if this is in the manuals
or if I misinterpreted what's in perlnumber.
I think we discussed this already. I might have oversimplified things
when I wrote perlnumber (or [hopefully ;-] it might have been a later edit).
Also, are these instructions discussed anywhere, or just in the
source?
Might be in the autogenerated POD for Configure variables:
perl -V:d_Gconvert
There is also perlvar for $#, but I suspect it is erroneous.
Is it a choice of what parameters to pass to CRTL that is causing
the fault, or is it the choice to use the CRTL period? If it's a
parameter issue, why haven't the parameters been changed?
There are two conflicting targets:
a) One does not want a silly semantic of number conversion (like
information loss);
b) One does not want to see silly bug reports like
why
perl -wle "$#='%.17g'; print 17.1"
prints garbage digits?
(I assume that this value of $# is the default, so setting it
would not appear in the bug report.)
c) The conversion should not be too slow.
With the current choice of $#, one STILL gets stuff as in "b". And
the precision is always always lost. But with finer $#, the bug
reports would be more frequent.
About mid-90s, there was a discussion about adding custom
stringification function, which does not has semantic of %.NNg, but
does better: it emits the minimal number of digits such that the
following conversion to a number would result in the initial number.
Somebody did a test, and found that using this custom function would
significantly slow down number-to-string conversion. So "c" was violate.
["a" would be fixed; it is not clear how this would change "b",
since fixing "a" increases number of cases where people would see
mismatch with "school arithmetic" (after performing arithmetic
operations on numbers with a few significant digits).]
However, a couple of years after this, I did some research, and found
out that perl was not caching results of number-to-string conversion.
After fixing it, the number of times perl calls number-to-string
conversion routines should have changed dramatically.
So it MIGHT be that using such a custom conversion function would not
violate "c". It also MIGHT be that it would not significantly
increase the flow of "b".
Choices, choices, choices - and shortage of time.
Hope this helps,
Ilya