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

increment of "2\n" did not change it to a number.

Why do you say that?

13:45 >perl -Mbigint -wE "my ($m, $k) = split / /, qq[10 2\n]; say qq[ +>$k<]; ++$k; say qq[>>$k<<];" >2 < >>3<< 13:49 >

Update (31 Aug 14): Fixed typo: changed ++k to ++$k.

Auto-increment has here converted $k from a string to a number, as can be seen from the loss of the trailing newline. The same effect is produced by $k++ or $k += 1.

Hope that helps,

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

Replies are listed 'Best First'.
Re^4: is it a BigInt bug?
by rsFalse (Chaplain) on Aug 30, 2014 at 22:17 UTC
    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

      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,