Hi,

On a perl 5.18.0 built with nvtype of "long double" I would expect that the value returned by the XSub:
SV * get_problem_val(void) { return newSVnv(1e-298L); }
would be exactly equal to the perl value 1e-298.
But that's not the case.

Here's the demo script:
#!perl -l use warnings; use strict; use Config; use Inline C => Config => USING => 'ParseRegExp', BUILD_NOISY => 1; use Inline C => <<'EOC'; SV * get_problem_val(void) { return newSVnv(1e-298L); } EOC print "\n\$Config{nvtype}: $Config{nvtype}"; print "Different values" if 1e-298 != get_problem_val(); print scalar reverse unpack "b64", pack "D", 1e-298; print scalar reverse unpack "b64", pack "D", get_problem_val();
As well as confirming that nvtype is long double and that the values differ, it also reveals that the last 5 (least significant) bits of the 64-bit perl mantissa are 10000 whereas the 64-bit C mantissa terminates with 01110
Other than that, they agree.

Is there a sound reason for this variation in value ?
If not, is there anyone here with a "long double" build of perl that experiences *expected* behaviour from the above demo ?

(BTW, it looks to me that the perl value is correct but the C value is not. At least, perl agrees with the 64-bit mantissa that the mpfr library assigns.)

Cheers,
Rob

In reply to When 1e-298L != 1e-298L by syphilis

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.