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

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

Thread Next
From:
Hugo van der Sanden via RT
Date:
February 17, 2015 04:18
Subject:
[perl #123851] "use integer" behaving oddly for large unsigned values
Message ID:
rt-4.0.18-25764-1424146679-745.123851-15-0@perl.org
On Mon Feb 16 19:11:30 2015, sisyphus wrote:
> I can't see anything in the integer documentation that explains this.
> The only reference I see there in relation to signed/unsigned issues 
> pertains to the bitwise operators.

I think the relevant bit is this part in the second para of the description:

       [...] In addition, the range of operands and results is
       restricted to that of familiar two's complement integers, i.e.,
       -(2**31) .. (2**31-1) on 32-bit architectures, and -(2**63) ..
       (2**63-1) on 64-bit architectures. [...]

I believe an initially assigned constant is treated as a float (by parts of perl that the integer module can't reach) until you use it numerically. So here's where it first wraps to negative for 64-bit ints:

% perl -wle 'for (9223372036854775807, 9223372036854775808) { my $x = $_; printf "%s = %#x\n", $x, $x; use integer; print $x; $x += 0; print $x }'
9223372036854775807 = 0x7fffffffffffffff
9223372036854775807
9223372036854775807
9223372036854775808 = 0x8000000000000000
9223372036854775808
-9223372036854775808
% 

Hugo

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=123851

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About