develooper Front page | perl.perl5.porters | Postings from February 2015

Re: [perl #123851] "use integer" behaving oddly for large unsigned values

Thread Previous | Thread Next
February 17, 2015 09:35
Re: [perl #123851] "use integer" behaving oddly for large unsigned values
Message ID:

-----Original Message----- 
From: Tony Cook via RT
Sent: Tuesday, February 17, 2015 4:35 PM

>> $ perl -Minteger -le '$x = 10_000_000_000_000_000_011; print $x; print $x 
>> /
>> 10;'
>> 10000000000000000011
>> -844674407370955160
>> $ perl -MMath::BigInt -le '$x =
>> Math::BigInt->new("10_000_000_000_000_000_011"); print $x; print $x /
>> Math::BigInt->new("10");'
>> 10000000000000000011
>> 1000000000000000001
> There are examples in perldoc integer documenting the wrapping behaviour.
> What behaviour do you expect given the documentation?

I think I expected such a significant and crippling limitation to be spelled 
out in a more glaringly obvious way.
But you're right - if you read the documentation properly it's all there.

So ... if you're wanting to do integer arithmetic on perl UV's that might be 
large enough to break the fragility of the integer pragma, then Math::BigInt 
is the only readily available option without venturing outside core perl. Is 
that right ?

Anyway - feel free to close this report. (I won't be using the integer 
pragma while it's in this state.)
Sorry for the noise.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About