import numpy as np
2.**1023
8.98846567431158e+307
2.**1024
--------------------------------------------------------------------------- OverflowError Traceback (most recent call last) Cell In[4], line 1 ----> 1 2.**1024 OverflowError: (34, 'Result too large')
-np.float64(2.)**1024
/var/folders/97/ppgk101x3214hn7bzlb85jk00000gn/T/ipykernel_41109/3987387186.py:1: RuntimeWarning: overflow encountered in scalar power -np.float64(2.)**1024
np.float64(-inf)
2.**(-1022)
2.2250738585072014e-308
2.**(-1022) * 2.**(-1)
1.1125369292536007e-308
2.**(-1022) * 2.**(-52)
5e-324
np.double(1.)/(-0.)
/var/folders/97/ppgk101x3214hn7bzlb85jk00000gn/T/ipykernel_41109/2823736679.py:1: RuntimeWarning: divide by zero encountered in scalar divide np.double(1.)/(-0.)
np.float64(-inf)
-2. / np.inf
-0.0
(np.inf - 2.) - 8
inf
np.double(0.) / 0.
/var/folders/97/ppgk101x3214hn7bzlb85jk00000gn/T/ipykernel_41109/2462110309.py:1: RuntimeWarning: invalid value encountered in scalar divide np.double(0.) / 0.
np.float64(nan)
# too small
eps = 2**(-53)
print(f'ε = 1.0 * 2**(-53)')
print( (1.+eps) - 1. )
ε = 1.0 * 2**(-53) 0.0
# Let's try this larger one
eps = 2**(-52)
print(f'ε = 1.0 * 2**(-52)')
print( (1.+eps) - 1. )
ε = 1.0 * 2**(-52) 2.220446049250313e-16
# OK, something between those two
bs = '11'
print(f'ε = {bs[0]}.{bs[1:]} * 2^(-53)')
eps = int(bs, 2) * 2**(-1) * 2**(-53)
print(eps)
print( (1.+eps) - 1. )
ε = 1.1 * 2^(-53) 1.6653345369377348e-16 2.220446049250313e-16
# Same idea, but smaller
bs = '1'
for k in range(50):
bs += '0'
bs += '1'
print(f'eps = {bs[0]}.{bs[1:]} * 2^(-53)')
eps = int(bs, 2) * 2**(-len(bs)) * 2**(-52)
print(eps)
print( (1.+eps) - 1. )
eps = 1.000000000000000000000000000000000000000000000000001 * 2^(-53) 1.110223024625157e-16 2.220446049250313e-16
np.finfo(np.double).eps
np.float64(2.220446049250313e-16)
np.finfo(np.single).eps
np.float32(1.1920929e-07)
np.pi
3.141592653589793
np.single(np.pi)
np.float32(3.1415927)
# How many base-10 digits cover the range of 52 base-2 digits?
np.log10(2**52)
np.float64(15.653559774527022)
# How many base-10 digits cover the range of 52 base-2 digits?
np.log10(2**23)
np.float64(6.923689900271567)
np.double(0.)**0.
np.float64(1.0)
np.log(0. * np.inf)
np.float64(nan)