Discussion:
from c.l.py, this should be biting us as well
Laura Creighton
2002-12-22 13:31:12 UTC
Permalink
------- Forwarded Message

Return-Path: python-list-***@python.org
Delivery-Date: Sun Dec 22 13:36:40 2002
From: "lemonite" <***@t-online.de>
Newsgroups: comp.lang.python
Subject: Re: Strange Errors with Python-2.2.2

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

- --
http://mail.python.org/mailman/listinfo/python-list

------- End of Forwarded Message
Tim Peters
2002-12-22 17:33:18 UTC
Permalink
[Laura Creighton, forwarding a msg from <***@t-online.de>]

There's a vigorous thread about this on c.l.py. It's unclear what's wrong--
or indeed whether anything is wrong --since the test program's meaning isn't
Post by Laura Creighton
printf("fractional part = %f\ninteger part = %f\n",
modf(x, &y), y);
The value of y isn't defined there (order of side effects isn't defined in
C).

Loading...