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: ZeroDivisionError when inf is expected
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Behzad Seyfi, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2019-10-10 16:01 by Behzad Seyfi, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg354391 - (view) Author: Behzad Seyfi (Behzad Seyfi) Date: 2019-10-10 16:01
>>> 1/1e-323
inf

>>> 1/1e-324
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero

in a 1/x fraction, up to x = 1e-324 it is inf but when x = 1e-325 or little it throws ZeroDivisionError. It is not acceptable and accountable behaviour for inf definition.
msg354395 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-10 16:19
That's not a bug: 64-bit float of IEEE 754 rounds 1e-324 to 0.0.

vstinner@apu$ python3
Python 3.7.4 (default, Jul  9 2019, 16:32:37) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1e-324
0.0
>>> import sys
>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
>>> sys.float_info.min
2.2250738585072014e-308
>>> sys.float_info.min.hex()
'0x1.0000000000000p-1022'

>>> 1/0.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero
>>> 1/1e-324
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero
msg354477 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-11 17:57
See https://en.wikipedia.org/wiki/Denormal_number.
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82613
2019-10-11 17:57:16serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg354477
2019-10-10 16:19:04vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg354395

resolution: not a bug
stage: resolved
2019-10-10 16:01:41Behzad Seyficreate