in reply to Re: Perl can't make some easy arithmetics :(
in thread Perl can't make some easy arithmetics :(

I used ideone.com for calculating. It says version is 5.16.2
  • Comment on Re^2: Perl can't make some easy arithmetics :(

Replies are listed 'Best First'.
Re^3: Perl can't make some easy arithmetics :(
by Loops (Curate) on Oct 24, 2014 at 21:19 UTC

    Okay, ideone.com is running on 32bit, and that is what you're running into. On my 64bit system with this input:

    9 7
    900000000000000009 900000000000000007
    99223372036854775810 99223372036854775808
    
    The output is:
    2 2 2 2
    2 2 2 2
    0 0 0 2
    
      Seems that there is a problem with magic: if use bigint and take some string, Perl doesn't convert correctly string to bigint?

        Yes, unless one of the variables has already been coerced to be a bigint, so even this is enough:

        use bigint; while(<>) { my ($a, $b)= split/ /; $a += 0; print $a - $b, "\n"; }

        However you can just coerce everything when you first read them in as strings:

        use bigint; while(<>) { my ($a, $b)= map { 0+$_ } split/ /; print $a - $b, "\n"; }