classification
Title: float.fromhex bugs
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: mark.dickinson
Priority: normal Keywords: patch

Created on 2009-05-09 19:50 by mark.dickinson, last changed 2009-05-11 17:33 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
issue5981.patch mark.dickinson, 2009-05-09 20:43
Messages (3)
msg87509 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-09 19:50
Two problems with float.fromhex:

(1) it incorrectly rejects trailing whitespace on infs and nans:

>>> float.fromhex('a.0 ')
10.0
>>> float.fromhex('nan ')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid hexadecimal floating-point string

(2) The implementation uses PyOS_strnicmp for detecting nans and infs,
which is locale-aware.  A locale-unaware case-insensitive comparison 
should be used instead.  I don't know of any locale where this actually 
makes a difference, but I think it should be fixed anyway.
msg87510 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-09 20:43
Here's a patch.
msg87581 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-11 17:33
Fixed in r72564 (trunk), r72565 (py3k).  The trailing whitespace bugfix 
was backported in r72566 (2.6) and r72567 (3.0), but those versions still 
use locale-aware isspace and islower.

As a semi-accidental by-product, the fix also changes the behaviour of 
float.fromhex('-nan'): previously, float.fromhex('-nan') and 
float.fromhex('nan') had the same sign;  now they have opposite signs. Sane code that's affected by the sign bit of a nan should be extremely 
rare, so I don't think this change is going to bother anyone.
History
Date User Action Args
2009-05-11 17:33:35mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg87581
2009-05-09 20:43:21mark.dickinsonsetfiles: + issue5981.patch
keywords: + patch
messages: + msg87510

stage: needs patch -> patch review
2009-05-09 19:50:15mark.dickinsoncreate