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

Thank you, graff, it was what I mean. I thought it must DWIM, and "use bigint" must not work in different way from "use bigint". I found real number instead of integer in this case at the bottom, later wrote here.
use bigint; ($m,$k)=split/ /,<>; print $k<$m? $m / ++$k : -1
stdin="10 2\n" stdout=3.33... One more strange is that increment of "2\n" did not change it to a number.

Replies are listed 'Best First'.
Re^3: is it a BigInt bug?
by Athanasius (Archbishop) on Jul 21, 2014 at 03:51 UTC
    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,

      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,