Recently, one of my co-workers noticed some problems hashing on references in our 64-bit HPUX-11 environment with perl 5.6.1. A bit of probing left me, the resident perl gnome, quite concerned. I see the problem also on an IA64/Linux build of perl 5.6.1, but not on a 64-bit Solaris build. This may be an instance of RTFM, but I have not seen it addressed in any FAQs, so I may be readingthe wrong FAQs. Or my eyes may have crossed and missed it.

The problem occurs in large integers, where the lower 8 bits get rounded if the upper 8 are in use. Here's a simple test script that illustrates the problem.

#!/path/to/perl my $X = \$X; printf STDOUT "Starting with VAR %lx and REF %lx \n", $X, \$X; if ($X == \$X) { printf STDOUT "uh oh, they are deemed equal\n"; } else { printf STDOUT "ah, good, they are observed to differ\n"; } # end

Here's a slightly more informative version of the same:

#!/path/to/perl my $X = \$X; my $Y = \$Y; if ( \$X == \$Y ) { printf STDOUT "disturbing declaration of equality! \n"; printf STDOUT "Refs: %s \t %s \n", \$X, \$Y; printf STDOUT "Vals: %lx \t %lx \n", $X, $Y; printf STDOUT "SOps: sum %lx \t dif %lx \n", $X + $Y, $X - $Y; printf STDOUT "incs: %lx \t +512=%lx \t +1024=%lx \n", $X, $X ++ 512, $X + 1024; } else { printf STDOUT "all is quiet and peaceful, \n"; printf STDOUT "%lx and %lx are recognized to differ by %lx \n" +, \$X, \$Y, \$X - \$Y; } # end

Results on the Solaris 5.8 machine:

all is quiet and peaceful, 100231cc0 and 100231ce0 are recognized to differ by ffffffffffffffe0

Results on the HPUX 11 machine:

disturbing declaration of equality! Refs: SCALAR(0x800000010002a9b0) SCALAR(0x800000010002a9d0) Vals: 800000010002a9f0 800000010002aa30 SOps: sum 200055000 dif 0 incs: 800000010002a9f0 +512=800000010002a800 +1024=800000010002b00 +0

What seems to be happening in the second case is values like
800000010002a9f0 and 800000010002aa30
are getting rounded to
800000010002a800 and 800000010002a800
and treated as equal, among other unsettling traits.

So, has anyone else encountered this? Is there a quick and happy fix? Is libc.sl hopelessly mangled? Can't we all just...get along?


In reply to 64-to-56-bit truncation? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.