"""Proof: the 16-bit fork, from finfo, nothing typed from memory.
float16 spent its bits on precision and dies at 65504; bfloat16 kept
float32's exponent and survives, with two decimal digits left."""
import torch

for dt in (torch.float32, torch.float16, torch.bfloat16):
    fi = torch.finfo(dt)
    print(f"{str(dt):16s} max {fi.max:>12.4g}   tiny {fi.tiny:.3g}   "
          f"eps {fi.eps:.3g}")
x = torch.tensor(60000.0)
print(f"\n60000 * 1.2 in float16 : {(x.half() * 1.2).item()}")
print(f"60000 * 1.2 in bfloat16: {(x.bfloat16() * torch.tensor(1.2, dtype=torch.bfloat16)).item()}")
print(f"1.001 in float16       : {torch.tensor(1.001, dtype=torch.float16).item():.6f}")
print(f"1.001 in bfloat16      : {torch.tensor(1.001, dtype=torch.bfloat16).item():.6f}")
