msg58661 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-15 10:23 |
The patch unifies the creation and representation of "inf", "-inf" and "nan" on all platforms. >>> float("inf") inf >>> float("-inf") -inf >>> float("nan") nan >>> repr(1e300 * 1e300) 'inf' >>> repr(1e300 * 1e300 * 0) 'nan' >>> repr(1e300 * 1e300 * -1) '-inf' |
|
|
msg58664 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-15 20:54 |
Update: I've added a platform independent implementation of stricmp and strnicmp (case insensitive compare). It could be useful for other parts of the code as well. |
|
|
msg58697 - (view) |
Author: Adam Olsen (Rhamphoryncus) |
Date: 2007-12-17 17:37 |
You have: #define Py_NAN Py_HUGE_VAL * 0 I think this would be safer as: #define Py_NAN (Py_HUGE_VAL * 0) For instance, in code that may do "a / Py_NAN". Those manual string copies (*cp++ = 'n';) are ugly. Can't you use strcpy() instead? |
|
|
msg58703 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-17 19:53 |
Adam Olsen wrote: > You have: > #define Py_NAN Py_HUGE_VAL * 0 > I think this would be safer as: > #define Py_NAN (Py_HUGE_VAL * 0) > > For instance, in code that may do "a / Py_NAN". You are right! Fixed > Those manual string copies (*cp++ = 'n';) are ugly. Can't you use > strcpy() instead? Done Christian |
|
|
msg58704 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-17 19:54 |
I'm posting a combined patch for all features at #1640. |
|
|
msg58759 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-12-18 19:48 |
Mostly looks good. Here are some nits. (1) You shouldn't have to add pystrcmp.c to the VC project files since on Windows it isn't used, right? (2) Will the Windows input routine still accept the *old* representations for INF and NAN? IMO that's important (a) so as to be able to read old pickles or marshalled data, (b) so as to be able to read data files written by C programs. (3) Shouldn't you be using Py_HUGE_VAL instead of HUGE_VAL in the chunk starting at line 187 in floatobject.c? |
|
|
msg58768 - (view) |
Author: Tim Peters (tim.peters) *  |
Date: 2007-12-18 20:26 |
[Guido] > ... > (2) Will the Windows input routine still accept the *old* > representations for INF and NAN? IMO that's important (a) so as to be > able to read old pickles or marshalled data, (b) so as to be able to > read data files written by C programs. Ha! You're such an optimist ;-) The remarkable truth is that Windows has never been able to read its own representations for INF and NAN: '1.#INF' >>> float(_) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for float(): 1.#INF >>> repr(nan) '-1.#IND' >>> float(_) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for float(): -1.#IND This has nothing to do with Python -- same thing from C, etc. |
|
|
msg58771 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-18 21:12 |
Guido van Rossum wrote: > (1) You shouldn't have to add pystrcmp.c to the VC project files since > on Windows it isn't used, right? It was the easiest way to test the functions in pystrcmp. Linux doesn't have stricmp but it also doesn't require the additional code to mangle 1.#INF into inf. > (2) Will the Windows input routine still accept the *old* > representations for INF and NAN? IMO that's important (a) so as to be > able to read old pickles or marshalled data, (b) so as to be able to > read data files written by C programs. See Tim's answer. Pickles and other C programs aren't an issue. Internally NaNs and INFs are represented with a special bit pattern (all bits of the exponent are set). As long as users don't use str() or repr() on floats it still works. The pickle module uses struct. > (3) Shouldn't you be using Py_HUGE_VAL instead of HUGE_VAL in the chunk > starting at line 187 in floatobject.c? I missed the spot, thanks. Christian |
|
|
msg58776 - (view) |
Author: Tim Peters (tim.peters) *  |
Date: 2007-12-18 21:56 |
Historical note: Guido is probably thinking of "the old" pickle and marshal here, which did have problems with inf and NaN on Windows (as in they didn't work at all). Michael Hudson changed them to use special bit patterns instead, IIRC for Python 2.5. |
|
|
msg58780 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-12-18 22:19 |
> Historical note: Guido is probably thinking of "the old" pickle and > marshal here, which did have problems with inf and NaN on Windows (as in > they didn't work at all). Michael Hudson changed them to use special > bit patterns instead, IIRC for Python 2.5. In pickle.py, protocol 0 (still the default in 2.6) uses repr(x) to write a float and float(s) to convert that back to input. Maybe you're thinking of marshal, which is more sophisticated. |
|
|
msg58781 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-12-18 22:21 |
I suggest you check this in (with the Py_HUGE_VAL fix) and then see how much of #1640 we still need. |
|
|
msg58785 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-12-18 23:26 |
Applied in r59558 to the trunk |
|
|