converting float to int issue
Irmen de Jong
irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Mon May 5 15:25:21 EDT 2003
[OFFTOPIC]
Alex wrote:
> Found the problem and resolution:
> http://forums.gentoo.org/viewtopic.php?t=27211
Sorry for this second follow up but I just noticed that
the little C test code they give on that forum is NOT CORRECT.
It does:
printf("fractional part = %f\ninteger part = %f\n", modf(x, &y), y);
And as we all know, the order in which the modf and the y argument are
evaluated is uncertain. That's why they got 0.0000 for the integer part
in the result (and sometimes 1.000) . They should have done this:
double result = modf(x,&y);
printf("fractional part = %f\ninteger part = %f\n", result, y);
At first, the code produced the "wrong" results on my system, too.
After the fix, it produces the correct results.
Alex, are you on that forum? You might want to point this out over there...
--Irmen de Jong
More information about the Python-list
mailing list