in reply to Re^3: is it a BigInt bug?
in thread is it a BigInt bug?

But if ++$k becomes the number 3, why it gives different answer?
print $k<$m? $m / ++$k : -1 # gives 3.(3) print $k<$m? $m / 3 : -1 # gives 3

Replies are listed 'Best First'.
Re^5: is it a BigInt bug?
by Athanasius (Archbishop) on Aug 31, 2014 at 03:49 UTC

    Yes, I think this is a bigint bug:

    #! perl use strict; use warnings; use bigint; my $m = '10'; my $k = '2'; ++$k; print $m / $k, "\n"; print $k->sign(), "\n";

    Output:

    13:45 >perl 992_SoPW.pl 3.33333333333333 Can't locate object method "sign" via package "3" (perhaps you forgot +to load "3"?) at 992_SoPW.pl line 10. 13:45 >

    This shows that ++ is failing to convert $k into a BigInt object. But change the line ++$k; to $k += 1; and the output is now as expected:

    13:45 >perl 992_SoPW.pl 3 + 13:46 >

    The documentation for bigint claims:

    All operators (including basic math operations) except the range operator .. are overloaded.

    But this doesn’t appear to be true for autoincrement.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,