Strange Errors with Python-2.2.2

lemonite lemonite at t-online.de
Sun Dec 22 07:32:32 EST 2002


After searching through Python's source code, I recognized, that the
funtion float_int() in floatobject.c is causing my trouble and its
implementation has changed compared with Python-2.1.3. It seems, as if the
call to modf() returns wrong results and to be sure I've tested modf()
with the following C testfile:

#include <stdio.h>
#include <math.h>

int main()
{
	double x = 1.1;
	double y;
	
	printf("Calling modf() for %f\n", x);
	printf("fractional part = %f\ninteger part = %f\n",
					modf(x, &y), y);
	
	return 0;
}

The expected output should look like this:

Calling modf() for 1.100000
fractional part = 0.100000
integer part = 1.000000

but GCC actually gave me:

$ gcc test.c -o test
$ ./test
Calling modf() for 1.100000
fractional part = 1.100000
integer part = -0.000000

To double-check I switched to Win2k and compiled with MinGW, but it did
not much better (at least the signs are correct):

C:\Temp>C:\mingw\bin\gcc test.c -o test.mingw.exe C:\Temp>test.mingw
Calling modf() for 1.100000
fractional part = 0.100000
integer part = 0.000000

Only lcc on Win2k performed as expected:

C:\Temp>C:\lcc\bin\lc test.c
C:\Temp>test
Calling modf() for 1.100000
fractional part = 0.100000
integer part = 1.000000


In summary it looks like the trouble is GCC related. Replacing float_int()
in Python-2.2.2 with float_int() from Python-2.1.3 fixes the problem,
because there is no modf() call in the 2.1.3--version. However I will try
to locate the error in GCC. At least the Python implementation does not 
seem to be responsible for all this.

Kind regards,
lemonite




More information about the Python-list mailing list