On Sun Jan 28 07:47:37 2007, TELS wrote:
Show quoted text>
> Thanx for your report! However, when I make the proposed change, some
> testcases fail, so I have to investigate what the real fix should be.
In the line in Math::BigInt::objectify() saying
$k->can('as_number') ? $k = $k->as_number() : $k = $a[0]->new($k);
the "$k = $a[0]->new($k)" is always executed. If the test
"$k->can('as_number')" is true, the "$k->as_number()" is also executed,
but has no effect, since $k has already been through "$k = $a[0]->new($k)".
When the above line is changed to
$k = $k->can('as_number') ? $k->as_number() : $a[0]->new($k);
the "$k->as_number()" is executed without $k having been through "$k =
$a[0]->new($k)". The tests fail, as mentioned by TELS, because
"$k->as_number()" and "$a[0]->new($k)" doesn't always give the same results.
So Math::Big* has inconsistent behaviour with respect to how a
Math::BigSomething is converted to a Math::BigInt. For example, try to
convert a Math::BigFloat to a Math::BigInt:
$ perl -MMath::BigFloat -wle '$x = Math::BigFloat -> new("3.14"); print
Math::BigInt -> new($x)'
NaN
$ perl -MMath::BigFloat -wle '$x = Math::BigFloat -> new("3.14"); print
$x -> as_number()'
3
(Even Math::BigInt->new() itself isn't consistent; see
http://rt.cpan.org/Public/Bug/Display.html?id=61887)
I suggest that "Math::BigInt -> new()" is fixed so that it always
returns the same as Math::BigSomething -> as_number(), or CORE::int().
This might cause some backwards incompatibility if people have written
code depending on "Math::BigInt -> new()" returning a NaN if the input
has a non-zero decimal part (which it not always does; see RT 61887),
but I think it is worth it. And since we are on the doorstep of
Math::BigInt version 2.00, this is a good time to make the change.