Subject: | bcmp() fails for very large numbers |
bcmp() fails for very large numbers. In the case below, $x and $y are
different, yet bcmp() returns 1, as if they were equal. The bug was
introduced in version 1.76.
perl -MMath::BigFloat -wle '
$x = Math::BigFloat -> new("1e1234567890987654321");
$y = Math::BigFloat -> new("1e1234567890987654300");
print $x -> bcmp($y)'
The bug is caused by a short-cut in bcmp() where the exponent is
converted to a Perl scalar (with the _num() library function). This
causes a loss of precision.
It seems that this is done deliberately, since a comment in the code
says "the numify somewhat limits our length, but makes it much faster".
I vote for following the good rules in the "GOALS" file in the
distribution, one of which says "Favour correctness over speed".