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

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

Thread Next
Hugo van der Sanden via RT
February 17, 2015 04:18
[perl #123851] "use integer" behaving oddly for large unsigned values
Message ID:
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
9223372036854775808 = 0x8000000000000000


via perlbug:  queue: perl5 status: new

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