-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Float patch for inf and nan on Windows (and other platforms) #45976
Comments
The patch unifies the creation and representation of "inf", "-inf" and >>> float("inf")
inf
>>> float("-inf")
-inf
>>> float("nan")
nan
>>> repr(1e300 * 1e300)
'inf'
>>> repr(1e300 * 1e300 * 0)
'nan'
>>> repr(1e300 * 1e300 * -1)
'-inf' |
Update: I've added a platform independent implementation of stricmp and strnicmp |
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 |
Adam Olsen wrote:
You are right! Fixed
Done Christian |
I'm posting a combined patch for all features at bpo-1640. |
Mostly looks good. Here are some nits. (1) You shouldn't have to add pystrcmp.c to the VC project files since (2) Will the Windows input routine still accept the *old* (3) Shouldn't you be using Py_HUGE_VAL instead of HUGE_VAL in the chunk |
[Guido]
Ha! You're such an optimist ;-) The remarkable truth is that Windows '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. |
Guido van Rossum wrote:
It was the easiest way to test the functions in pystrcmp. Linux doesn't
See Tim's answer.
I missed the spot, thanks. Christian |
Historical note: Guido is probably thinking of "the old" pickle and |
In pickle.py, protocol 0 (still the default in 2.6) uses repr(x) to |
I suggest you check this in (with the Py_HUGE_VAL fix) and then see how |
Applied in r59558 to the trunk |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: