Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: [Win32, C, and way OT] C floats, doubles, and their equivalence

by syphilis (Canon)
on Jul 19, 2009 at 00:12 UTC ( #781386=note: print w/ replies, xml ) Need Help??


in reply to Re: [Win32, C, and way OT] C floats, doubles, and their equivalence
in thread [Win32, C, and way OT] C floats, doubles, and their equivalence

It's a stab in the dark ...

Good stab - I can make use of that. The following outputs "True False" on the buggy compilers (and "True True" on sane compilers):

#include <stdio.h> int main(void) { double nv = 2.0 / 3; float foo = 2.0 / 3; float truncated = (float)nv; if(foo == truncated) printf("True "); else printf("False "); if(foo == (float)nv) printf("True\n"); else printf("False\n"); return 0; }
I can apply that method (used to obtain that "True") to PDL, which solves the problem I have asked about. Unfortunately, while it enables me to get the behaviour I want with my C demo scripts, it's still not producing the correct result with PDL - but this is such a fickle bug. I'll have to play around with it some more.

PS: This is relevant to the work I do ensuring Windows compatibility for my XS distros

#if defined _MSC_VER && _MSC_VER < 1400 then expect weirdness if you start comparing floats with doubles.

Thanks Marvin.

Cheers,
Rob


Comment on Re^2: [Win32, C, and way OT] C floats, doubles, and their equivalence
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2015-07-29 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls