eshafto has asked for the wisdom of the Perl Monks concerning the following question:

I've built 5.10 on Solaris 10, and make test fails on t/base/num.t thusly:
1..50 ok 1 ok 2 ok 3 ok 4 not ok 5 # 0.100000000000000005551115123125783 not ok 6 # -0.100000000000000005551115123125783 not ok 7 # 0.100000000000000005551115123125783 not ok 8 # -0.100000000000000005551115123125783 not ok 9 # 10.0099999999999997868371792719699 ok 10 ok 11
The tests look like this:
$a = 0.1; "$a"; print $a eq "0.1" ? "ok 5\n" : "not ok 5 # $a\n";
I configured this with -Duse64bitall and added the -m64 and -mcpu=v9 flags to the compile and link commands. For chuckles I installed anyway and tried to update CPAN and all the version checking failed with things like:
# Failed test ' <SOFTPKG>' # at t/basic.t line 83. # '<SOFTPKG NAME="Big-Dummy" VERSION="0.010000000000 +0000002081668171172169"> [...] # doesn't match '(?m-xis:^<SOFTPKG NAME="Big-Dummy" VERSION="0.01" +>)'
If I build it as a 32-bit app, I get:
./perl -e "$a=> perl -e '$a = 0.1; print "$a\n";' 0.1
But as a 64-bit app, I get:
> ./perl -e '$a = 0.1; print "$a\n";' 0.100000000000000005551115123125783
I've done a lot of trial-and-error with the config flags and settings, but no luck so far. I've googled and googled till my googler was sore. Can you think of something I haven't before? Anything remotely helpful will be appreciated, lauded, and extolled beyond reasonable measure.

Replies are listed 'Best First'.
Re: 64-bit build fails numeric tests
by kennethk (Abbot) on Feb 01, 2010 at 17:03 UTC
    Don't have a machine to play with here, but 64 bit perl on Solaris in perlsolaris says:

    Long Doubles.

    As of 5.8.1, long doubles are working if you use the Sun compilers (needed for additional math routines not included in libm).

    Given that your issue appears to be a single/double precision float mismatch, have you tried building with the Sun compilers? When you modified the compile and link commands, could you have missed a line, s.t. some libraries were built without the -m64 flag?

      Thank you for finding that. I really did try.

      From this line it appears that one cannot build 64-bit Perl on Solaris using gnu tools. Am I reading that correctly?

        I read it as saying there are known issues associated with Solaris builds with gcc. Past that is outside my experience.

        Note that the error you are reporting is that when numifying strings, they are being returned as floats instead of doubles. The specific error referenced above, however, pertains to long doubles. To me, this sounds more like an inconsistent build - 32 bit numification routines interacting with a 64 bit perl - thus my question about missing a line in your modification.

Re: 64-bit build fails numeric tests
by ikegami (Patriarch) on Feb 01, 2010 at 17:09 UTC

    1/10 is a periodic numbers in binary (like 1/3 is in decimal). It can't be represented exactly as a float. Normally, the least significant bits are rounded off to give the appearance of being able to store those numbers. You're not getting that rounding for some reason.

    I find it odd that a 64-bit build uses double-precision numbers, but I don't know if that's unusual or wrong. I'm not experienced with those.

    If you don't get a solution here, I suggest that you file a bug report. It'll put you in touch with people better equipped to solve this problem.

      I find it odd that a 64-bit build uses double-precision numbers, but I don't know if that's unusual or wrong

      Looking at the INSTALL file that ships with the perl source, it appears that -Duse64bitall switches on 64 bit ints and longs, and the use of 64bit pointers ... but doesn't switch on -Duselongdouble. If you want the extra precision that -Duselongdouble provides it seems that you have to specify either -Duselongdouble or -Dusemorebits.

      It could be interesting to know if there were any compiler flags (other than the ones already stated) specified by the OP.

      Cheers,
      Rob

        Rob,

        Adding -Duselongdouble seems to have fixed the problem. I suspect I shall have to spend more time trying to figure out exactly what 64-bit features I need and exactly how to get those and no others. But at least now I have a consistent, working build.

        Thanks to you and everyone who contributed to the thread.