Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-24 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found