You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Float patch for inf and nan on Windows (and other platforms) #45976
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/tiran'closed_at=<Date2007-12-18.23:26:07.917>created_at=<Date2007-12-15.10:23:24.457>labels= []
title='Float patch for inf and nan on Windows (and other platforms)'updated_at=<Date2008-01-06.22:29:44.389>user='https://github.com/tiran'
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.
(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?
...
(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 "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 1.#INF
>>> repr(nan)
'-1.#IND'
>>> float(_)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): -1.#IND
This has nothing to do with Python -- same thing from C, etc.
(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?
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.
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.
Activity
tiran commentedon Dec 15, 2007
The patch unifies the creation and representation of "inf", "-inf" and
"nan" on all platforms.
tiran commentedon Dec 15, 2007
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.
Rhamphoryncus commentedon Dec 17, 2007
For instance, in code that may do "a / Py_NAN".
Those manual string copies (*cp++ = 'n';) are ugly. Can't you use
strcpy() instead?
tiran commentedon Dec 17, 2007
Adam Olsen wrote:
You are right! Fixed
Done
Christian
tiran commentedon Dec 17, 2007
I'm posting a combined patch for all features at bpo-1640.
gvanrossum commentedon Dec 18, 2007
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?
tim-one commentedon Dec 18, 2007
[Guido]
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:
This has nothing to do with Python -- same thing from C, etc.
tiran commentedon Dec 18, 2007
Guido van Rossum wrote:
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.
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.
I missed the spot, thanks.
Christian
tim-one commentedon Dec 18, 2007
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.
gvanrossum commentedon Dec 18, 2007
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.
gvanrossum commentedon Dec 18, 2007
I suggest you check this in (with the Py_HUGE_VAL fix) and then see how
much of bpo-1640 we still need.
tiran commentedon Dec 18, 2007
Applied in r59558 to the trunk