Hi,
It doesn't get much more OT than this.
The demo C program:
#include <stdio.h> int main(void) { double nv = 2.0 / 3; float foo = 2.0 / 3; /* Need to do stuff here that ensures that what follows below outputs "False True" */ if(foo == nv) printf("True "); else printf("False "); if(foo == (float)nv) printf("True\n"); else printf("False\n"); return 0; }
Afaict, with any sane C compiler (including MSVC++ 8.0, MSVC++ 9.0, MinGW port of gcc-3.4.5, and gcc-3.2.2 on linux) that program will output "False True".
But with versions of MSVC++ prior to version 8.0, it outputs "False False".

I'm wondering if anyone knows of a workaround that will enable the correct output of "False True" with those earlier versions of MSVC++.

I posted this to comp.os.ms-windows.programmer.misc, and then realized that most posts there now go unanswered and that mine was the first post there in over 5 weeks ... I'm not at all hopeful of a useful response on that forum. Alternatively, if someone knows of a site where this subject is *not* OT, and where there's a good chance of an informed response, then that might also be helpful to me.

Cheers,
Rob

PS For anyone interested, it's not hard to create a script that is essentially the same yet produces the reverse output of "True False". (Again, this applies only to MSVC++ prior to version 8.0.) :
#include <stdio.h> int main(void) { double nv = 2.0 / 3; float foo = nv; /*The only change*/ if(foo == nv) printf("True "); else printf("False "); if(foo == (float)nv) printf("True\n"); else printf("False\n"); return 0; }
But that doesn't help me to solve my problem at all.
My problem is that this bug (as presented in the first script) is stuffing up one particular aspect of PDL when PDL is built using MSVC++ versions that pre-date version 8.0 - and that's what I'm trying to fix.

In reply to [Win32, C, and way OT] C floats, doubles, and their equivalence 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.