Hi,
If the argument is outside the range of a Python float, an OverflowError will be raised.
but when I try to produce an OverflowError, instead the float is rounded to inf. I'm not clear if this is a doc bug, an error with the implementation of Ubuntu python 3.11.6, or an error with my test.
Overflow: a finite result is too large to be represented accurately (i.e., its exponent with an unbounded exponent range would be larger than emax). By default, returns ±infinity for the round-to-nearest modes (and follows the rounding rules for the directed rounding modes).
To reproduce:
andrew@andrew-gs:~/Documents/100daysPython/misc$ cat o2.py
import sys
s="10e310"
try:
v=float( s )
except ValueError as e:
print( f"Caught ValueError \"{e}\"" )
sys.exit(1)
except:
print( f"Caught unknown exception. Exiting." )
sys.exit(2)
print( f"\nstring \"{s}\" becomes {v}\n" )
print( sys.float_info )
andrew@andrew-gs:~/Documents/100daysPython/misc$ python3 ./o2.py
string "10e310" becomes inf
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)
andrew@andrew-gs:~/Documents/100daysPython/misc$
Does this look like a doc bug, an implementation bug, or something else?
Thanks for any information,
Andrew