Perldoc: integers *stored* as... ???

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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.

use strict;
use warnings;
my $x = 0xffff_ffff;
print $x, "\n";
printf("%d\n", $x);

On a 32-bit machine outputs:

Re: Perldoc: integers *stored* as... ???

Quoted text here. Click to load it

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

Quoted text here. Click to load it

%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.


Re: Perldoc: integers *stored* as... ???

Quoted text here. Click to load it

Wrong.  Integers are not stored as bits.  They are stored as parts of
SVIV, SVUV, SVNVIV, SVPVIV, SVwhatever else structures.

So your remark makes yet less sense than the sentence in the docs
(which indeed, would benefit from some edits).


Site Timeline