I think your detailed investigation demonstrates why the code I posted in repsonse to
creamygoodness's post behaves the way it does.
After much poking and scratching and re-reading of suggestions that have been kindly and thoughtfully presented here, I've eventually come up with using this approach in the PDL code:
#include <stdio.h>
#if defined _MSC_VER && _MSC_VER < 1400
#pragma optimize("", off)
#endif
int main(void) {
#if defined _MSC_VER && _MSC_VER < 1400
double nv = 2.0 / 3;
float foo = 2.0 / 3;
float dummy = (float)nv;
if(foo == dummy) printf("True ");
else printf("False ");
#else
double nv = 2.0 / 3;
float foo = 2.0 / 3;
if(foo == (float)nv) printf("True ");
else printf("False ");
#endif
return 0;
}
It seems to be doing the right thing with all of my compilers.
I don't think that C script needs to have the optimization turned off - the creation of the dummy variable is alone sufficient to get the behaviour I'm after. But for some reason, in the PDL code, creation of the dummy variable is *not*, by itself, sufficient - optimization also needs to be disabled. (I turn it off for the setvaltobad functions, then turn it back on again.)
Thanks to *all* who replied.
Cheers,
Rob
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.