In [1]:
f = 256.0

In [2]:
print(f.hex())


0x1.0000000000000p+8

In [3]:
print(type(f.hex()))


<class 'str'>

In [4]:
print(256.0.hex())


0x1.0000000000000p+8

In [5]:
print(0.5.hex())


0x1.0000000000000p-1

In [6]:
print(42.195.hex())


0x1.518f5c28f5c29p+5

In [7]:
i = 256

In [8]:
# print(i.hex())
# AttributeError: 'int' object has no attribute 'hex'

In [9]:
s = '0x1.0000000000000p+8'

In [10]:
print(float.fromhex(s))


256.0

In [11]:
print(type(float.fromhex(s)))


<class 'float'>

In [12]:
print(float.fromhex('0x1p+8'))


256.0

In [13]:
print(float.fromhex('1p+8'))


256.0

In [14]:
print(float.fromhex('0x100'))


256.0

In [15]:
print(float.fromhex('100'))


256.0

In [16]:
print(float.fromhex('0xf2.f8p-10'))


0.237274169921875

In [17]:
print((15 * 16**1 + 2 * 16**0 + 15 * 16**-1 + 8 * 16**-2) * 2**-10)


0.237274169921875

In [18]:
import sys

In [19]:
f_max = sys.float_info.max

In [20]:
print(f_max)


1.7976931348623157e+308

In [21]:
print(f_max.hex())


0x1.fffffffffffffp+1023

In [22]:
print(float.fromhex('0x1.fffffffffffffp+1023'))


1.7976931348623157e+308

In [23]:
# print(float.fromhex('0x1.0000000000000p+1024'))
# OverflowError: hexadecimal value too large to represent as a float

In [24]:
# print(float.fromhex('0x2.0000000000000p+1023'))
# OverflowError: hexadecimal value too large to represent as a float

In [25]:
f_min = sys.float_info.min

In [26]:
print(f_min)


2.2250738585072014e-308

In [27]:
print(f_min.hex())


0x1.0000000000000p-1022

In [28]:
print(float.fromhex('0x1.0000000000000p-1022'))


2.2250738585072014e-308

In [29]:
print(float.fromhex('0x0.0000000000001p-1022'))


5e-324

In [30]:
print(format(float.fromhex('0x0.0000000000001p-1022'), '.17'))


4.9406564584124654e-324

In [31]:
print(float.fromhex('0x0.0000000000001p-1023'))


0.0