This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ** operator does not overflow to inf
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: inf*inf gives inf, but inf**2 gives overflow error
View: 3222
Assigned To: Nosy List: Keith.Randall, iritkatriel, mark.dickinson
Priority: normal Keywords:

Created on 2014-02-07 18:44 by Keith.Randall, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg210517 - (view) Author: Keith Randall (Keith.Randall) Date: 2014-02-07 18:44
>>> 1e200*1e200
inf
>>> 1e200**2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: (34, 'Numerical result out of range')

Shouldn't floating-point operations overflow to inf, not generate exceptions?
msg210523 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-02-07 18:54
> Shouldn't floating-point operations overflow to inf, not generate exceptions?

This has been discussed a few times before (I'll try to find the references).

But to answer you question: actually, no.  I think they *should* generate exceptions.  That is, if I were to change anything here, it would be the result of the multiplication, not the result of the ** operation.  IMO, numerically naive users shouldn't be exposed to infinities and NaNs; they should get exceptions for invalid inputs instead.  The math and cmath modules fairly rigorously follow this idea, but as you've discovered the built-in operators aren't so consistent.

Fixing it without breaking existing code and without annoying existing users is tricky, though.
msg210525 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-02-07 18:57
Issue #3222 is related.
msg210526 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-02-07 19:03
And here's a link to the middle of a related discussion under the heading "Turn off ZeroDivisionError?" on python-list, Feb 2008.

https://mail.python.org/pipermail/python-list/2008-February/473302.html

You'd have to read up- and down-thread to get the entire discussion.
msg210527 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-02-07 19:05
See also #18570.
msg380490 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-07 02:41
If there are no objections, I will close this as a duplicate of issue3222.
msg380497 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-11-07 09:55
Thanks, @iritkatriel. Sounds good to me.
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64742
2020-11-07 09:55:52mark.dickinsonsetstatus: pending -> closed

messages: + msg380497
stage: resolved
2020-11-07 02:41:55iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg380490

superseder: inf*inf gives inf, but inf**2 gives overflow error
resolution: duplicate
2015-07-21 08:06:56ethan.furmansetnosy: - ethan.furman
2014-02-07 21:41:26ethan.furmansetnosy: + ethan.furman
2014-02-07 19:05:17mark.dickinsonsetmessages: + msg210527
2014-02-07 19:03:33mark.dickinsonsetmessages: + msg210526
2014-02-07 18:57:43mark.dickinsonsetmessages: + msg210525
2014-02-07 18:54:29mark.dickinsonsetnosy: + mark.dickinson
messages: + msg210523
2014-02-07 18:44:35Keith.Randallcreate