[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: May be proposed tests (except for the overflow) would be helpful? Right now 'f' and 'd' parsing code is not covered by tests. -- ___ Python tracker

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-07 Thread Stefan Krah
Stefan Krah added the comment: I agree. Fixing all this would probably require a PEP. It looks like the original plan was to provide a facility to turn off the Overflow exception: http://mail.python.org/pipermail/python-dev/2000-May/003990.html -- _

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-07 Thread Mark Dickinson
Mark Dickinson added the comment: Closing as "won't fix"; Python is sadly far from consistent about returning infinity versus raising OverflowError, in a wide variety of situations. For example, compare: * float(Decimal('1e310')) with float(Fraction('1e310')), or * struct.pack('f', 1e100)

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-05 Thread Stefan Krah
Stefan Krah added the comment: The proposal makes sense at first glance, but I agree with Mark that it is not clear what should be done. For example, all arrays in Python silently convert to inf: >>> from numpy import array >>> x = array([1,2,3], 'f') >>> x array([ 1., 2., 3.], dtype=float32)

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-05 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: No one integer produces infinity in 'double' parameter parsing. But the 'float' parameter parsing can produce infinity, and it can raise an exception. To be consistent, we need or produce infinity on double overflow (in this case, we must explicitly produce i

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: > But values that rounded to DBL_MAX can raise > OverflowError. In any case it's too difficult to achieve strict behavior > in this corner case. Well, PyLong_AsDouble *does* achieve strict behaviour in this corner case :-). Integers less than 0.5 * (sys.float

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- type: -> enhancement versions: -Python 2.7, Python 3.2 ___ Python tracker ___ ___ Python-bugs-list

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is a patch with tests. > Nope. Values just larger than DBL_MAX won't raise OverflowError here. Isn't that a little bit. But values that rounded to DBL_MAX can raise OverflowError. In any case it's too difficult to achieve strict behavior in this corner

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: > And it checks strictly out of ±DBL_MAX. Nope. Values just larger than DBL_MAX won't raise OverflowError here. > Because float(10**1000) returns no float('inf'), but raises an > exception, I think that returning ±∞ will be wrong. Possibly. But there's also

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I also thought about ±∞. But PyLong_AsDouble() raises OverflowError for out-of-range value. And it checks strictly out of ±DBL_MAX. Because float(10**1000) returns no float('inf'), but raises an exception, I think that returning ±∞ will be wrong. --

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Changes by Mark Dickinson : -- assignee: -> mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: I was just remembering that I was *sure* I'd seen the double->float avoiding undefined behaviour issue mentioned on a C mailing list not so long ago. Turns out that there was a good reason for me remembering that... https://groups.google.com/group/comp.lang

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Changes by Mark Dickinson : -- nosy: +skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: I don't think this change should be made for 2.7 or 3.2, since it has potential to break existing code. Though technically, conversion of an out-of-range double to a float gives undefined behaviour (C99 6.3.1.5p2), I'm willing to bet that most current compil

[issue14722] Overflow in parsing 'float' parameters in PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : In function convertsimple() in Python/getargs.c possible converting out of float range value from double to float. Fortunately, 'f' format character is not used in CPython source code. But it can be used in the extensions. Tests will be later. -