My only suggestion is that you dump the values as bits and see where they differ

Definitely worth a try, but it appears not to have helped much.
So .... I changed the original Inline::C script to:
use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, USING => 'ParseRegExp', #CLEAN_AFTER_BUILD => 0, ; use Inline C => <<'EOC'; #include <stdio.h> int foo(void) { _Decimal64 d64 = 0.DD, neg_zero, pos_zero = 0.DD; void *pd64 = &d64, *pneg_zero = &neg_zero, *ppos_zero = &pos_zero; int i; neg_zero = pos_zero * -1.DD; d64 *= -1.DD; if(d64 != pos_zero) printf("!= 0\n"); else printf("== 0\n"); if(d64 != neg_zero) printf("!= -0\n"); else printf("== -0\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)pd64)[i]); printf("\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)pneg_zero)[i]); printf("\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)ppos_zero)[i]); printf("\n"); return 0; } EOC foo();
It now outputs:
!= 0 == -0 B1C0000000000000 B1C0000000000000 31C0000000000000
"B1C000..." is a _Decimal64 -0, and "31C000..." a _Decimal64 0.
The first bit is the sign bit, the next 10 bits encode the exponent, and the 54-bit significand is an implicit 0 bit followed by the remaining 53 bits (all 0).
When I run that revised C code as a C program it outputs (correctly):
== 0 == -0 B1C0000000000000 B1C0000000000000 31C0000000000000
I also modified the Inline::C rendition that was getting it right to:
use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, USING => 'ParseRegExp', #CLEAN_AFTER_BUILD => 0, ; use Inline C => <<'EOC'; #include <stdio.h> void _is_zero(_Decimal64 d64) { _Decimal64 neg_zero, pos_zero = 0.DD; void *pd64 = &d64, *pneg_zero = &neg_zero, *ppos_zero = &pos_zero; int i; neg_zero = pos_zero * -1.DD; if(d64 != pos_zero) printf("!= 0\n"); else printf("== 0\n"); if(d64 != neg_zero) printf("!= -0\n"); else printf("== -0\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)pd64)[i]); printf("\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)pneg_zero)[i]); printf("\n"); for(i = 7; i >= 0; i--) printf("%02X", ((unsigned char*)ppos_zero)[i]); printf("\n"); } int foo(void) { _Decimal64 d64 = 0.DD; d64 *= -1.DD; _is_zero(d64); return 0; } EOC foo();
It still outputs (correctly):
== 0 == -0 B1C0000000000000 B1C0000000000000 31C0000000000000
It's as though the != operation (in the problem script) believes that the values it's comparing are unsigned.

Cheers,
Rob

In reply to Re^2: Inline::C producing an absurd result by syphilis
in thread Inline::C producing an absurd result 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.