Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Perldoc: integers *stored* as... ???
August 20, 2010, 4:07 pm
rate this thread
In the online Perl 5 version 12.1 documentation at:
Under the heading of Storing Numbers it reads "In fact numbers stored
in the native integer format may be stored either in the signed native
form, or in the unsigned native form."
Integers are *stored* as bits in a word, dword, or qword, it's how
they're interpreted that matters.
my $x = 0xffff_ffff;
print $x, "\n";
On a 32-bit machine outputs:
Re: Perldoc: integers *stored* as... ???
Well, yes. Since 5.6.0, perl scalars have a flag bit in them that
indicates whether the stored number should be treated as signed or
%d on a 32bit machine is inadequate for displaying Perl integers, since
it casts them to signed. This is perhaps a bug.
Note that on a perl with 32bit integers (that is, on a 32bit machine and
not built with use64bitint)
my ($x, $y) = (0xffff_ffff, -1);
print "$_\n" for $x, $y;
despite the fact that the 32bit word actually storing the number has the
same value in both cases.