http://qs321.pair.com?node_id=781353


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

Seems like the conversion glitch could be happening at several places.

Maybe the initial assignment of float foo needs a cast. MSVC warns about loss of precision in such cases -- maybe it's serious. :)

float foo = (float)nv;

As a workaround, perhaps you could truncate the initial assignment of the double:

double nv = (float)(2.0 / 3);

Lastly, maybe something is awry in the conversions that are being done during the comparison -- like it's ignoring your cast. It's a stab in the dark, but maybe a hack like this would get it to pay attention:

static __inline int compare_truncated_double_to_float(double d, float f) { float truncted_double = (float)d; if (f == truncated_double) { return 1; } else { return 0; } }

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

--
Marvin Humphrey