Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Perl can't make some easy arithmetics :(

by rsFalse (Chaplain)
on Oct 24, 2014 at 21:05 UTC ( #1104920=note: print w/replies, xml ) Need Help??


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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2023-12-04 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (25 votes). Check out past polls.

    Notices?