converting float to int issue

Bengt Richter bokr at oz.net
Tue May 6 09:44:21 EDT 2003


On Mon, 05 May 2003 21:25:21 +0200, Irmen de Jong <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote:

>[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...
>
+2¢: I notice that in the (2.2.2 windows) object.c source a modf call is bracketed thus:
___________________________

#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
{
	extended e;
	fractpart = modf(v, &e);
	intpart = e;
}
#else
	fractpart = modf(v, &intpart);
#endif
___________________________

but not so in floatobject.c where modf is used for the int(floatnum) operation.
I'm not familiar with MPW, but could that be a problem for somebody on a Mac?

Regards,
Bengt Richter




More information about the Python-list mailing list