Making value tables

In this notebook, we generate value tables akin to those at P3109.

Thes tables comprise one-line summaries of each float value in the form

Code Binary     = Exact binary E =  Float16 equivalent Float16 binary E    = Float Value
0x21 0_0100_001 = +0b1.001*2^-4  = 0_01011_0010000000 +0b1.0010000000*2^-4 = ~0.0703
from gfloat import *
from gfloat.formats import *
import numpy as np
from IPython.display import HTML
import airium
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 5
      3 import numpy as np
      4 from IPython.display import HTML
----> 5 import airium

ModuleNotFoundError: No module named 'airium'

Define some helpers.

Render with underscores separating s_e_m

E.g 0_1011_110. For formats with zero significand bits or zero exponent bits, we use 0_1011110_ or 0__10111110.

def str_bits_with_underscores(fi, fv):
    # 0_1011110_
    if fi.tSignificandBits == 0:
        return f"{fv.signbit}_{fv.exp:0{fi.expBits}b}_"

    # 0__1011110
    if fi.expBits == 0:
        return f"{fv.signbit}__{fv.significand:0{fi.tSignificandBits}b}"

    # 0_101_1110
    return (
        f"{fv.signbit}_{fv.exp:0{fi.expBits}b}_{fv.significand:0{fi.tSignificandBits}b}"
    )


fi = format_info_p3109(3)
assert str_bits_with_underscores(fi, decode_float(fi, 0x41)) == "0_10000_01"

fi = format_info_p3109(1)
assert str_bits_with_underscores(fi, decode_float(fi, 0x41)) == "0_1000001_"

fi = format_info_p3109(7)
assert str_bits_with_underscores(fi, decode_float(fi, 0x41)) == "0_1_000001"

Render a binary16 value

Returns two strings, like this:

'0_00010_1010000000', '+0b1.1010000000*2^-13'
import struct


def b16_str(val) -> tuple[str, str]:
    """
    Represent VAL in binary16.

    If val does not convert exactly to binary16,
    returns "<Not16:{val}>"
    """
    with np.errstate(over="ignore"):
        b16 = np.float16(val)

    if float(b16) != val and np.isfinite(b16):
        # Finite, but not representable in float16
        return f"<Not16:{val}>", ""
    b16_int = struct.unpack("!H", struct.pack("!e", b16))[0]

    # bitstr is of the form 0_00000_1100000000
    s = f"{b16_int:016b}"
    e_str = s[1:6]
    m_str = s[6:]
    bitstr = f"{s[0]}_{e_str}_{m_str}"

    # pow2str is of the form '+0b0.1100000000*2^-15', or '' for nonfinite values
    e = int(e_str, 2) - 15
    m = int(m_str, 2)
    leading_bit = 0 if e == -15 else 1
    signstr = "-" if s[0] == "1" else "+"
    if np.isfinite(b16):
        pow2str = f"{signstr}0b{leading_bit}.{m:010b}*2^{e}"
    else:
        pow2str = ""
    return bitstr, pow2str


assert b16_str(13 * 2**-16) == ("0_00010_1010000000", "+0b1.1010000000*2^-13")

Make HTML table

def mktbl(fi: FormatInfo, cols=4, skip_rows=None, **kw):
    # Make tables
    nvals = 2**fi.bits
    rows = nvals // cols

    style = f"""
  body {{
  }}
  table {{
    width:100%;
    margin: 0pt;
    font-family: monospace;
    font-size: x-small;
    font-weight: bold;
    border-collapse: collapse;
  }}

  tr.blankrow {{
    height: 4ex;
    vertical-align: top;
  }}
  
  td {{
    text-align: left;
    border: solid 2px #ccc;
    width: {98/cols}%;
  }}
  
  .special {{
    color: #874723;
  }}
  
  .subnormal {{
    color: #0121a7;
  }}
  
  .normal {{
  }}
  
  @media (prefers-color-scheme: dark) {{
    .special {{
      color: orange;
    }}

    .subnormal {{
      color: cyan;
    }}
    
    .normal {{
    }}
  }}

  pre {{
    margin: 1pt 1pt 1pt 13pt;
    display: inline;
  }}
"""

    def table_style(fv):
        """
        Select from the table entry styles defined in CSS above.
        """
        if fv.fclass == FloatClass.SUBNORMAL:
            return "subnormal"

        if fv.fclass == FloatClass.NORMAL:
            return "normal"

        if fv.fclass == FloatClass.ZERO and not fv.signbit:
            return "normal"

        # Everyting else is special
        return "special"

    title = f"FP8 Value Table, {fi.name}"
    a = airium.Airium()
    a("<!DOCTYPE html>")
    with a.html():
        with a.head():
            # a.meta('http-equiv="refresh" content="1"') # for rapid testing
            a.meta(charset="utf-8")
            a.title(_t=title)
            a.style(_t=style)

        with a.body():
            a.h3(_t=title)

            with a.table():
                for i in range(0, rows):
                    if skip_rows and (skip_rows[0] <= i < skip_rows[1]):
                        if i == skip_rows[0]:
                            a.tr(klass="blankrow").td("...")
                        continue
                    trklass = "blankrow" if i > 0 and i % 16 == 0 else ""
                    with a.tr(klass=trklass):
                        for n in range(i, nvals, rows):
                            fv = decode_float(fi, n)
                            text = str_tablerow(fi, fv, show_b16_info=False, **kw)
                            a.td(klass=table_style(fv)).pre(_t=text)

    return str(a)


HTML(mktbl(format_info_ocp_e2m1, cols=2, vs_width=8, vs_d=3))
FP8 Value Table, ocp_e2m1

FP8 Value Table, ocp_e2m1

0x00 0_00_0 = 0.0
0x08 1_00_0 = -0.0
0x01 0_00_1 = +0b0.1*2^0   = 0.5
0x09 1_00_1 = -0b0.1*2^0   = -0.5
0x02 0_01_0 = +0b1.0*2^0   = 1.0
0x0a 1_01_0 = -0b1.0*2^0   = -1.0
0x03 0_01_1 = +0b1.1*2^0   = 1.5
0x0b 1_01_1 = -0b1.1*2^0   = -1.5
0x04 0_10_0 = +0b1.0*2^1   = 2.0
0x0c 1_10_0 = -0b1.0*2^1   = -2.0
0x05 0_10_1 = +0b1.1*2^1   = 3.0
0x0d 1_10_1 = -0b1.1*2^1   = -3.0
0x06 0_11_0 = +0b1.0*2^2   = 4.0
0x0e 1_11_0 = -0b1.0*2^2   = -4.0
0x07 0_11_1 = +0b1.1*2^2   = 6.0
0x0f 1_11_1 = -0b1.1*2^2   = -6.0

OCP E2M3

This 6-bit format has 32 values, with no NaN or Inf, but does have -0. The positive subnormals are the linear ramp of eighths: [n/8 for n in 1:7].

One might describe the format in text as:

zero to one by eighths, two to four by quarters, four to eight by halves

where “to” is open-ended, or “to” is not “thru”.

HTML(mktbl(format_info_ocp_e2m3, cols=2, vs_width=8, vs_d=3))
FP8 Value Table, ocp_e2m3

FP8 Value Table, ocp_e2m3

0x00 0_00_000 = 0.0
0x20 1_00_000 = -0.0
0x01 0_00_001 = +0b0.001*2^0   = 0.125
0x21 1_00_001 = -0b0.001*2^0   = -0.125
0x02 0_00_010 = +0b0.010*2^0   = 0.25
0x22 1_00_010 = -0b0.010*2^0   = -0.25
0x03 0_00_011 = +0b0.011*2^0   = 0.375
0x23 1_00_011 = -0b0.011*2^0   = -0.375
0x04 0_00_100 = +0b0.100*2^0   = 0.5
0x24 1_00_100 = -0b0.100*2^0   = -0.5
0x05 0_00_101 = +0b0.101*2^0   = 0.625
0x25 1_00_101 = -0b0.101*2^0   = -0.625
0x06 0_00_110 = +0b0.110*2^0   = 0.75
0x26 1_00_110 = -0b0.110*2^0   = -0.75
0x07 0_00_111 = +0b0.111*2^0   = 0.875
0x27 1_00_111 = -0b0.111*2^0   = -0.875
0x08 0_01_000 = +0b1.000*2^0   = 1.0
0x28 1_01_000 = -0b1.000*2^0   = -1.0
0x09 0_01_001 = +0b1.001*2^0   = 1.125
0x29 1_01_001 = -0b1.001*2^0   = -1.125
0x0a 0_01_010 = +0b1.010*2^0   = 1.25
0x2a 1_01_010 = -0b1.010*2^0   = -1.25
0x0b 0_01_011 = +0b1.011*2^0   = 1.375
0x2b 1_01_011 = -0b1.011*2^0   = -1.375
0x0c 0_01_100 = +0b1.100*2^0   = 1.5
0x2c 1_01_100 = -0b1.100*2^0   = -1.5
0x0d 0_01_101 = +0b1.101*2^0   = 1.625
0x2d 1_01_101 = -0b1.101*2^0   = -1.625
0x0e 0_01_110 = +0b1.110*2^0   = 1.75
0x2e 1_01_110 = -0b1.110*2^0   = -1.75
0x0f 0_01_111 = +0b1.111*2^0   = 1.875
0x2f 1_01_111 = -0b1.111*2^0   = -1.875
0x10 0_10_000 = +0b1.000*2^1   = 2.0
0x30 1_10_000 = -0b1.000*2^1   = -2.0
0x11 0_10_001 = +0b1.001*2^1   = 2.25
0x31 1_10_001 = -0b1.001*2^1   = -2.25
0x12 0_10_010 = +0b1.010*2^1   = 2.5
0x32 1_10_010 = -0b1.010*2^1   = -2.5
0x13 0_10_011 = +0b1.011*2^1   = 2.75
0x33 1_10_011 = -0b1.011*2^1   = -2.75
0x14 0_10_100 = +0b1.100*2^1   = 3.0
0x34 1_10_100 = -0b1.100*2^1   = -3.0
0x15 0_10_101 = +0b1.101*2^1   = 3.25
0x35 1_10_101 = -0b1.101*2^1   = -3.25
0x16 0_10_110 = +0b1.110*2^1   = 3.5
0x36 1_10_110 = -0b1.110*2^1   = -3.5
0x17 0_10_111 = +0b1.111*2^1   = 3.75
0x37 1_10_111 = -0b1.111*2^1   = -3.75
0x18 0_11_000 = +0b1.000*2^2   = 4.0
0x38 1_11_000 = -0b1.000*2^2   = -4.0
0x19 0_11_001 = +0b1.001*2^2   = 4.5
0x39 1_11_001 = -0b1.001*2^2   = -4.5
0x1a 0_11_010 = +0b1.010*2^2   = 5.0
0x3a 1_11_010 = -0b1.010*2^2   = -5.0
0x1b 0_11_011 = +0b1.011*2^2   = 5.5
0x3b 1_11_011 = -0b1.011*2^2   = -5.5
0x1c 0_11_100 = +0b1.100*2^2   = 6.0
0x3c 1_11_100 = -0b1.100*2^2   = -6.0
0x1d 0_11_101 = +0b1.101*2^2   = 6.5
0x3d 1_11_101 = -0b1.101*2^2   = -6.5
0x1e 0_11_110 = +0b1.110*2^2   = 7.0
0x3e 1_11_110 = -0b1.110*2^2   = -7.0
0x1f 0_11_111 = +0b1.111*2^2   = 7.5
0x3f 1_11_111 = -0b1.111*2^2   = -7.5

OCP Formats: E5M2, E4M3

HTML(mktbl(format_info_ocp_e5m2, cols=4, skip_rows=(0x10, 0x30), vs_width=8, vs_d=5))
FP8 Value Table, ocp_e5m2

FP8 Value Table, ocp_e5m2

0x00 0_00000_00 = 0.0
0x40 0_10000_00 = +0b1.00*2^1   = 2.0
0x80 1_00000_00 = -0.0
0xc0 1_10000_00 = -0b1.00*2^1   = -2.0
0x01 0_00000_01 = +0b0.01*2^-14 = ~1.5259e-05
0x41 0_10000_01 = +0b1.01*2^1   = 2.5
0x81 1_00000_01 = -0b0.01*2^-14 = ~-1.5259e-05
0xc1 1_10000_01 = -0b1.01*2^1   = -2.5
0x02 0_00000_10 = +0b0.10*2^-14 = ~3.0518e-05
0x42 0_10000_10 = +0b1.10*2^1   = 3.0
0x82 1_00000_10 = -0b0.10*2^-14 = ~-3.0518e-05
0xc2 1_10000_10 = -0b1.10*2^1   = -3.0
0x03 0_00000_11 = +0b0.11*2^-14 = ~4.5776e-05
0x43 0_10000_11 = +0b1.11*2^1   = 3.5
0x83 1_00000_11 = -0b0.11*2^-14 = ~-4.5776e-05
0xc3 1_10000_11 = -0b1.11*2^1   = -3.5
0x04 0_00001_00 = +0b1.00*2^-14 = ~6.1035e-05
0x44 0_10001_00 = +0b1.00*2^2   = 4.0
0x84 1_00001_00 = -0b1.00*2^-14 = ~-6.1035e-05
0xc4 1_10001_00 = -0b1.00*2^2   = -4.0
0x05 0_00001_01 = +0b1.01*2^-14 = ~7.6294e-05
0x45 0_10001_01 = +0b1.01*2^2   = 5.0
0x85 1_00001_01 = -0b1.01*2^-14 = ~-7.6294e-05
0xc5 1_10001_01 = -0b1.01*2^2   = -5.0
0x06 0_00001_10 = +0b1.10*2^-14 = ~9.1553e-05
0x46 0_10001_10 = +0b1.10*2^2   = 6.0
0x86 1_00001_10 = -0b1.10*2^-14 = ~-9.1553e-05
0xc6 1_10001_10 = -0b1.10*2^2   = -6.0
0x07 0_00001_11 = +0b1.11*2^-14 = ~0.00011
0x47 0_10001_11 = +0b1.11*2^2   = 7.0
0x87 1_00001_11 = -0b1.11*2^-14 = ~-0.00011
0xc7 1_10001_11 = -0b1.11*2^2   = -7.0
0x08 0_00010_00 = +0b1.00*2^-13 = ~0.00012
0x48 0_10010_00 = +0b1.00*2^3   = 8.0
0x88 1_00010_00 = -0b1.00*2^-13 = ~-0.00012
0xc8 1_10010_00 = -0b1.00*2^3   = -8.0
0x09 0_00010_01 = +0b1.01*2^-13 = ~0.00015
0x49 0_10010_01 = +0b1.01*2^3   = 10.0
0x89 1_00010_01 = -0b1.01*2^-13 = ~-0.00015
0xc9 1_10010_01 = -0b1.01*2^3   = -10.0
0x0a 0_00010_10 = +0b1.10*2^-13 = ~0.00018
0x4a 0_10010_10 = +0b1.10*2^3   = 12.0
0x8a 1_00010_10 = -0b1.10*2^-13 = ~-0.00018
0xca 1_10010_10 = -0b1.10*2^3   = -12.0
0x0b 0_00010_11 = +0b1.11*2^-13 = ~0.00021
0x4b 0_10010_11 = +0b1.11*2^3   = 14.0
0x8b 1_00010_11 = -0b1.11*2^-13 = ~-0.00021
0xcb 1_10010_11 = -0b1.11*2^3   = -14.0
0x0c 0_00011_00 = +0b1.00*2^-12 = ~0.00024
0x4c 0_10011_00 = +0b1.00*2^4   = 16.0
0x8c 1_00011_00 = -0b1.00*2^-12 = ~-0.00024
0xcc 1_10011_00 = -0b1.00*2^4   = -16.0
0x0d 0_00011_01 = +0b1.01*2^-12 = ~0.00031
0x4d 0_10011_01 = +0b1.01*2^4   = 20.0
0x8d 1_00011_01 = -0b1.01*2^-12 = ~-0.00031
0xcd 1_10011_01 = -0b1.01*2^4   = -20.0
0x0e 0_00011_10 = +0b1.10*2^-12 = ~0.00037
0x4e 0_10011_10 = +0b1.10*2^4   = 24.0
0x8e 1_00011_10 = -0b1.10*2^-12 = ~-0.00037
0xce 1_10011_10 = -0b1.10*2^4   = -24.0
0x0f 0_00011_11 = +0b1.11*2^-12 = ~0.00043
0x4f 0_10011_11 = +0b1.11*2^4   = 28.0
0x8f 1_00011_11 = -0b1.11*2^-12 = ~-0.00043
0xcf 1_10011_11 = -0b1.11*2^4   = -28.0
0x30 0_01100_00 = +0b1.00*2^-3  = 0.125
0x70 0_11100_00 = +0b1.00*2^13  = 8192.0
0xb0 1_01100_00 = -0b1.00*2^-3  = -0.125
0xf0 1_11100_00 = -0b1.00*2^13  = -8192.0
0x31 0_01100_01 = +0b1.01*2^-3  = 0.15625
0x71 0_11100_01 = +0b1.01*2^13  = 10240.0
0xb1 1_01100_01 = -0b1.01*2^-3  = -0.15625
0xf1 1_11100_01 = -0b1.01*2^13  = -10240.0
0x32 0_01100_10 = +0b1.10*2^-3  = 0.1875
0x72 0_11100_10 = +0b1.10*2^13  = 12288.0
0xb2 1_01100_10 = -0b1.10*2^-3  = -0.1875
0xf2 1_11100_10 = -0b1.10*2^13  = -12288.0
0x33 0_01100_11 = +0b1.11*2^-3  = 0.21875
0x73 0_11100_11 = +0b1.11*2^13  = 14336.0
0xb3 1_01100_11 = -0b1.11*2^-3  = -0.21875
0xf3 1_11100_11 = -0b1.11*2^13  = -14336.0
0x34 0_01101_00 = +0b1.00*2^-2  = 0.25
0x74 0_11101_00 = +0b1.00*2^14  = 16384.0
0xb4 1_01101_00 = -0b1.00*2^-2  = -0.25
0xf4 1_11101_00 = -0b1.00*2^14  = -16384.0
0x35 0_01101_01 = +0b1.01*2^-2  = 0.3125
0x75 0_11101_01 = +0b1.01*2^14  = 20480.0
0xb5 1_01101_01 = -0b1.01*2^-2  = -0.3125
0xf5 1_11101_01 = -0b1.01*2^14  = -20480.0
0x36 0_01101_10 = +0b1.10*2^-2  = 0.375
0x76 0_11101_10 = +0b1.10*2^14  = 24576.0
0xb6 1_01101_10 = -0b1.10*2^-2  = -0.375
0xf6 1_11101_10 = -0b1.10*2^14  = -24576.0
0x37 0_01101_11 = +0b1.11*2^-2  = 0.4375
0x77 0_11101_11 = +0b1.11*2^14  = 28672.0
0xb7 1_01101_11 = -0b1.11*2^-2  = -0.4375
0xf7 1_11101_11 = -0b1.11*2^14  = -28672.0
0x38 0_01110_00 = +0b1.00*2^-1  = 0.5
0x78 0_11110_00 = +0b1.00*2^15  = 32768.0
0xb8 1_01110_00 = -0b1.00*2^-1  = -0.5
0xf8 1_11110_00 = -0b1.00*2^15  = -32768.0
0x39 0_01110_01 = +0b1.01*2^-1  = 0.625
0x79 0_11110_01 = +0b1.01*2^15  = 40960.0
0xb9 1_01110_01 = -0b1.01*2^-1  = -0.625
0xf9 1_11110_01 = -0b1.01*2^15  = -40960.0
0x3a 0_01110_10 = +0b1.10*2^-1  = 0.75
0x7a 0_11110_10 = +0b1.10*2^15  = 49152.0
0xba 1_01110_10 = -0b1.10*2^-1  = -0.75
0xfa 1_11110_10 = -0b1.10*2^15  = -49152.0
0x3b 0_01110_11 = +0b1.11*2^-1  = 0.875
0x7b 0_11110_11 = +0b1.11*2^15  = 57344.0
0xbb 1_01110_11 = -0b1.11*2^-1  = -0.875
0xfb 1_11110_11 = -0b1.11*2^15  = -57344.0
0x3c 0_01111_00 = +0b1.00*2^0   = 1.0
0x7c 0_11111_00 = inf
0xbc 1_01111_00 = -0b1.00*2^0   = -1.0
0xfc 1_11111_00 = -inf
0x3d 0_01111_01 = +0b1.01*2^0   = 1.25
0x7d 0_11111_01 = nan
0xbd 1_01111_01 = -0b1.01*2^0   = -1.25
0xfd 1_11111_01 = nan
0x3e 0_01111_10 = +0b1.10*2^0   = 1.5
0x7e 0_11111_10 = nan
0xbe 1_01111_10 = -0b1.10*2^0   = -1.5
0xfe 1_11111_10 = nan
0x3f 0_01111_11 = +0b1.11*2^0   = 1.75
0x7f 0_11111_11 = nan
0xbf 1_01111_11 = -0b1.11*2^0   = -1.75
0xff 1_11111_11 = nan
HTML(mktbl(format_info_ocp_e4m3, cols=4, skip_rows=(0x10, 0x30), vs_width=8, vs_d=5))
FP8 Value Table, ocp_e4m3

FP8 Value Table, ocp_e4m3

0x00 0_0000_000 = 0.0
0x40 0_1000_000 = +0b1.000*2^1   = 2.0
0x80 1_0000_000 = -0.0
0xc0 1_1000_000 = -0b1.000*2^1   = -2.0
0x01 0_0000_001 = +0b0.001*2^-6  = ~0.00195
0x41 0_1000_001 = +0b1.001*2^1   = 2.25
0x81 1_0000_001 = -0b0.001*2^-6  = ~-0.00195
0xc1 1_1000_001 = -0b1.001*2^1   = -2.25
0x02 0_0000_010 = +0b0.010*2^-6  = ~0.00391
0x42 0_1000_010 = +0b1.010*2^1   = 2.5
0x82 1_0000_010 = -0b0.010*2^-6  = ~-0.00391
0xc2 1_1000_010 = -0b1.010*2^1   = -2.5
0x03 0_0000_011 = +0b0.011*2^-6  = ~0.00586
0x43 0_1000_011 = +0b1.011*2^1   = 2.75
0x83 1_0000_011 = -0b0.011*2^-6  = ~-0.00586
0xc3 1_1000_011 = -0b1.011*2^1   = -2.75
0x04 0_0000_100 = +0b0.100*2^-6  = ~0.00781
0x44 0_1000_100 = +0b1.100*2^1   = 3.0
0x84 1_0000_100 = -0b0.100*2^-6  = ~-0.00781
0xc4 1_1000_100 = -0b1.100*2^1   = -3.0
0x05 0_0000_101 = +0b0.101*2^-6  = ~0.00977
0x45 0_1000_101 = +0b1.101*2^1   = 3.25
0x85 1_0000_101 = -0b0.101*2^-6  = ~-0.00977
0xc5 1_1000_101 = -0b1.101*2^1   = -3.25
0x06 0_0000_110 = +0b0.110*2^-6  = ~0.01172
0x46 0_1000_110 = +0b1.110*2^1   = 3.5
0x86 1_0000_110 = -0b0.110*2^-6  = ~-0.01172
0xc6 1_1000_110 = -0b1.110*2^1   = -3.5
0x07 0_0000_111 = +0b0.111*2^-6  = ~0.01367
0x47 0_1000_111 = +0b1.111*2^1   = 3.75
0x87 1_0000_111 = -0b0.111*2^-6  = ~-0.01367
0xc7 1_1000_111 = -0b1.111*2^1   = -3.75
0x08 0_0001_000 = +0b1.000*2^-6  = 0.015625
0x48 0_1001_000 = +0b1.000*2^2   = 4.0
0x88 1_0001_000 = -0b1.000*2^-6  = ~-0.01562
0xc8 1_1001_000 = -0b1.000*2^2   = -4.0
0x09 0_0001_001 = +0b1.001*2^-6  = ~0.01758
0x49 0_1001_001 = +0b1.001*2^2   = 4.5
0x89 1_0001_001 = -0b1.001*2^-6  = ~-0.01758
0xc9 1_1001_001 = -0b1.001*2^2   = -4.5
0x0a 0_0001_010 = +0b1.010*2^-6  = ~0.01953
0x4a 0_1001_010 = +0b1.010*2^2   = 5.0
0x8a 1_0001_010 = -0b1.010*2^-6  = ~-0.01953
0xca 1_1001_010 = -0b1.010*2^2   = -5.0
0x0b 0_0001_011 = +0b1.011*2^-6  = ~0.02148
0x4b 0_1001_011 = +0b1.011*2^2   = 5.5
0x8b 1_0001_011 = -0b1.011*2^-6  = ~-0.02148
0xcb 1_1001_011 = -0b1.011*2^2   = -5.5
0x0c 0_0001_100 = +0b1.100*2^-6  = ~0.02344
0x4c 0_1001_100 = +0b1.100*2^2   = 6.0
0x8c 1_0001_100 = -0b1.100*2^-6  = ~-0.02344
0xcc 1_1001_100 = -0b1.100*2^2   = -6.0
0x0d 0_0001_101 = +0b1.101*2^-6  = ~0.02539
0x4d 0_1001_101 = +0b1.101*2^2   = 6.5
0x8d 1_0001_101 = -0b1.101*2^-6  = ~-0.02539
0xcd 1_1001_101 = -0b1.101*2^2   = -6.5
0x0e 0_0001_110 = +0b1.110*2^-6  = ~0.02734
0x4e 0_1001_110 = +0b1.110*2^2   = 7.0
0x8e 1_0001_110 = -0b1.110*2^-6  = ~-0.02734
0xce 1_1001_110 = -0b1.110*2^2   = -7.0
0x0f 0_0001_111 = +0b1.111*2^-6  = ~0.02930
0x4f 0_1001_111 = +0b1.111*2^2   = 7.5
0x8f 1_0001_111 = -0b1.111*2^-6  = ~-0.02930
0xcf 1_1001_111 = -0b1.111*2^2   = -7.5
0x30 0_0110_000 = +0b1.000*2^-1  = 0.5
0x70 0_1110_000 = +0b1.000*2^7   = 128.0
0xb0 1_0110_000 = -0b1.000*2^-1  = -0.5
0xf0 1_1110_000 = -0b1.000*2^7   = -128.0
0x31 0_0110_001 = +0b1.001*2^-1  = 0.5625
0x71 0_1110_001 = +0b1.001*2^7   = 144.0
0xb1 1_0110_001 = -0b1.001*2^-1  = -0.5625
0xf1 1_1110_001 = -0b1.001*2^7   = -144.0
0x32 0_0110_010 = +0b1.010*2^-1  = 0.625
0x72 0_1110_010 = +0b1.010*2^7   = 160.0
0xb2 1_0110_010 = -0b1.010*2^-1  = -0.625
0xf2 1_1110_010 = -0b1.010*2^7   = -160.0
0x33 0_0110_011 = +0b1.011*2^-1  = 0.6875
0x73 0_1110_011 = +0b1.011*2^7   = 176.0
0xb3 1_0110_011 = -0b1.011*2^-1  = -0.6875
0xf3 1_1110_011 = -0b1.011*2^7   = -176.0
0x34 0_0110_100 = +0b1.100*2^-1  = 0.75
0x74 0_1110_100 = +0b1.100*2^7   = 192.0
0xb4 1_0110_100 = -0b1.100*2^-1  = -0.75
0xf4 1_1110_100 = -0b1.100*2^7   = -192.0
0x35 0_0110_101 = +0b1.101*2^-1  = 0.8125
0x75 0_1110_101 = +0b1.101*2^7   = 208.0
0xb5 1_0110_101 = -0b1.101*2^-1  = -0.8125
0xf5 1_1110_101 = -0b1.101*2^7   = -208.0
0x36 0_0110_110 = +0b1.110*2^-1  = 0.875
0x76 0_1110_110 = +0b1.110*2^7   = 224.0
0xb6 1_0110_110 = -0b1.110*2^-1  = -0.875
0xf6 1_1110_110 = -0b1.110*2^7   = -224.0
0x37 0_0110_111 = +0b1.111*2^-1  = 0.9375
0x77 0_1110_111 = +0b1.111*2^7   = 240.0
0xb7 1_0110_111 = -0b1.111*2^-1  = -0.9375
0xf7 1_1110_111 = -0b1.111*2^7   = -240.0
0x38 0_0111_000 = +0b1.000*2^0   = 1.0
0x78 0_1111_000 = +0b1.000*2^8   = 256.0
0xb8 1_0111_000 = -0b1.000*2^0   = -1.0
0xf8 1_1111_000 = -0b1.000*2^8   = -256.0
0x39 0_0111_001 = +0b1.001*2^0   = 1.125
0x79 0_1111_001 = +0b1.001*2^8   = 288.0
0xb9 1_0111_001 = -0b1.001*2^0   = -1.125
0xf9 1_1111_001 = -0b1.001*2^8   = -288.0
0x3a 0_0111_010 = +0b1.010*2^0   = 1.25
0x7a 0_1111_010 = +0b1.010*2^8   = 320.0
0xba 1_0111_010 = -0b1.010*2^0   = -1.25
0xfa 1_1111_010 = -0b1.010*2^8   = -320.0
0x3b 0_0111_011 = +0b1.011*2^0   = 1.375
0x7b 0_1111_011 = +0b1.011*2^8   = 352.0
0xbb 1_0111_011 = -0b1.011*2^0   = -1.375
0xfb 1_1111_011 = -0b1.011*2^8   = -352.0
0x3c 0_0111_100 = +0b1.100*2^0   = 1.5
0x7c 0_1111_100 = +0b1.100*2^8   = 384.0
0xbc 1_0111_100 = -0b1.100*2^0   = -1.5
0xfc 1_1111_100 = -0b1.100*2^8   = -384.0
0x3d 0_0111_101 = +0b1.101*2^0   = 1.625
0x7d 0_1111_101 = +0b1.101*2^8   = 416.0
0xbd 1_0111_101 = -0b1.101*2^0   = -1.625
0xfd 1_1111_101 = -0b1.101*2^8   = -416.0
0x3e 0_0111_110 = +0b1.110*2^0   = 1.75
0x7e 0_1111_110 = +0b1.110*2^8   = 448.0
0xbe 1_0111_110 = -0b1.110*2^0   = -1.75
0xfe 1_1111_110 = -0b1.110*2^8   = -448.0
0x3f 0_0111_111 = +0b1.111*2^0   = 1.875
0x7f 0_1111_111 = nan
0xbf 1_0111_111 = -0b1.111*2^0   = -1.875
0xff 1_1111_111 = nan

IEEE WG P3109 {P} formats

We choose just one example: p3109(p=3), which has the same number of exponent bits as OCP E5

HTML(mktbl(format_info_p3109(3), cols=4, skip_rows=(0x10, 0x30), vs_width=8, vs_d=5))
FP8 Value Table, p3109_p3

FP8 Value Table, p3109_p3

0x00 0_00000_00 = 0.0
0x40 0_10000_00 = +0b1.00*2^0   = 1.0
0x80 1_00000_00 = nan
0xc0 1_10000_00 = -0b1.00*2^0   = -1.0
0x01 0_00000_01 = +0b0.01*2^-15 = ~7.6294e-06
0x41 0_10000_01 = +0b1.01*2^0   = 1.25
0x81 1_00000_01 = -0b0.01*2^-15 = ~-7.6294e-06
0xc1 1_10000_01 = -0b1.01*2^0   = -1.25
0x02 0_00000_10 = +0b0.10*2^-15 = ~1.5259e-05
0x42 0_10000_10 = +0b1.10*2^0   = 1.5
0x82 1_00000_10 = -0b0.10*2^-15 = ~-1.5259e-05
0xc2 1_10000_10 = -0b1.10*2^0   = -1.5
0x03 0_00000_11 = +0b0.11*2^-15 = ~2.2888e-05
0x43 0_10000_11 = +0b1.11*2^0   = 1.75
0x83 1_00000_11 = -0b0.11*2^-15 = ~-2.2888e-05
0xc3 1_10000_11 = -0b1.11*2^0   = -1.75
0x04 0_00001_00 = +0b1.00*2^-15 = ~3.0518e-05
0x44 0_10001_00 = +0b1.00*2^1   = 2.0
0x84 1_00001_00 = -0b1.00*2^-15 = ~-3.0518e-05
0xc4 1_10001_00 = -0b1.00*2^1   = -2.0
0x05 0_00001_01 = +0b1.01*2^-15 = ~3.8147e-05
0x45 0_10001_01 = +0b1.01*2^1   = 2.5
0x85 1_00001_01 = -0b1.01*2^-15 = ~-3.8147e-05
0xc5 1_10001_01 = -0b1.01*2^1   = -2.5
0x06 0_00001_10 = +0b1.10*2^-15 = ~4.5776e-05
0x46 0_10001_10 = +0b1.10*2^1   = 3.0
0x86 1_00001_10 = -0b1.10*2^-15 = ~-4.5776e-05
0xc6 1_10001_10 = -0b1.10*2^1   = -3.0
0x07 0_00001_11 = +0b1.11*2^-15 = ~5.3406e-05
0x47 0_10001_11 = +0b1.11*2^1   = 3.5
0x87 1_00001_11 = -0b1.11*2^-15 = ~-5.3406e-05
0xc7 1_10001_11 = -0b1.11*2^1   = -3.5
0x08 0_00010_00 = +0b1.00*2^-14 = ~6.1035e-05
0x48 0_10010_00 = +0b1.00*2^2   = 4.0
0x88 1_00010_00 = -0b1.00*2^-14 = ~-6.1035e-05
0xc8 1_10010_00 = -0b1.00*2^2   = -4.0
0x09 0_00010_01 = +0b1.01*2^-14 = ~7.6294e-05
0x49 0_10010_01 = +0b1.01*2^2   = 5.0
0x89 1_00010_01 = -0b1.01*2^-14 = ~-7.6294e-05
0xc9 1_10010_01 = -0b1.01*2^2   = -5.0
0x0a 0_00010_10 = +0b1.10*2^-14 = ~9.1553e-05
0x4a 0_10010_10 = +0b1.10*2^2   = 6.0
0x8a 1_00010_10 = -0b1.10*2^-14 = ~-9.1553e-05
0xca 1_10010_10 = -0b1.10*2^2   = -6.0
0x0b 0_00010_11 = +0b1.11*2^-14 = ~0.00011
0x4b 0_10010_11 = +0b1.11*2^2   = 7.0
0x8b 1_00010_11 = -0b1.11*2^-14 = ~-0.00011
0xcb 1_10010_11 = -0b1.11*2^2   = -7.0
0x0c 0_00011_00 = +0b1.00*2^-13 = ~0.00012
0x4c 0_10011_00 = +0b1.00*2^3   = 8.0
0x8c 1_00011_00 = -0b1.00*2^-13 = ~-0.00012
0xcc 1_10011_00 = -0b1.00*2^3   = -8.0
0x0d 0_00011_01 = +0b1.01*2^-13 = ~0.00015
0x4d 0_10011_01 = +0b1.01*2^3   = 10.0
0x8d 1_00011_01 = -0b1.01*2^-13 = ~-0.00015
0xcd 1_10011_01 = -0b1.01*2^3   = -10.0
0x0e 0_00011_10 = +0b1.10*2^-13 = ~0.00018
0x4e 0_10011_10 = +0b1.10*2^3   = 12.0
0x8e 1_00011_10 = -0b1.10*2^-13 = ~-0.00018
0xce 1_10011_10 = -0b1.10*2^3   = -12.0
0x0f 0_00011_11 = +0b1.11*2^-13 = ~0.00021
0x4f 0_10011_11 = +0b1.11*2^3   = 14.0
0x8f 1_00011_11 = -0b1.11*2^-13 = ~-0.00021
0xcf 1_10011_11 = -0b1.11*2^3   = -14.0
0x30 0_01100_00 = +0b1.00*2^-4  = 0.0625
0x70 0_11100_00 = +0b1.00*2^12  = 4096.0
0xb0 1_01100_00 = -0b1.00*2^-4  = -0.0625
0xf0 1_11100_00 = -0b1.00*2^12  = -4096.0
0x31 0_01100_01 = +0b1.01*2^-4  = 0.078125
0x71 0_11100_01 = +0b1.01*2^12  = 5120.0
0xb1 1_01100_01 = -0b1.01*2^-4  = ~-0.07812
0xf1 1_11100_01 = -0b1.01*2^12  = -5120.0
0x32 0_01100_10 = +0b1.10*2^-4  = 0.09375
0x72 0_11100_10 = +0b1.10*2^12  = 6144.0
0xb2 1_01100_10 = -0b1.10*2^-4  = -0.09375
0xf2 1_11100_10 = -0b1.10*2^12  = -6144.0
0x33 0_01100_11 = +0b1.11*2^-4  = 0.109375
0x73 0_11100_11 = +0b1.11*2^12  = 7168.0
0xb3 1_01100_11 = -0b1.11*2^-4  = ~-0.10938
0xf3 1_11100_11 = -0b1.11*2^12  = -7168.0
0x34 0_01101_00 = +0b1.00*2^-3  = 0.125
0x74 0_11101_00 = +0b1.00*2^13  = 8192.0
0xb4 1_01101_00 = -0b1.00*2^-3  = -0.125
0xf4 1_11101_00 = -0b1.00*2^13  = -8192.0
0x35 0_01101_01 = +0b1.01*2^-3  = 0.15625
0x75 0_11101_01 = +0b1.01*2^13  = 10240.0
0xb5 1_01101_01 = -0b1.01*2^-3  = -0.15625
0xf5 1_11101_01 = -0b1.01*2^13  = -10240.0
0x36 0_01101_10 = +0b1.10*2^-3  = 0.1875
0x76 0_11101_10 = +0b1.10*2^13  = 12288.0
0xb6 1_01101_10 = -0b1.10*2^-3  = -0.1875
0xf6 1_11101_10 = -0b1.10*2^13  = -12288.0
0x37 0_01101_11 = +0b1.11*2^-3  = 0.21875
0x77 0_11101_11 = +0b1.11*2^13  = 14336.0
0xb7 1_01101_11 = -0b1.11*2^-3  = -0.21875
0xf7 1_11101_11 = -0b1.11*2^13  = -14336.0
0x38 0_01110_00 = +0b1.00*2^-2  = 0.25
0x78 0_11110_00 = +0b1.00*2^14  = 16384.0
0xb8 1_01110_00 = -0b1.00*2^-2  = -0.25
0xf8 1_11110_00 = -0b1.00*2^14  = -16384.0
0x39 0_01110_01 = +0b1.01*2^-2  = 0.3125
0x79 0_11110_01 = +0b1.01*2^14  = 20480.0
0xb9 1_01110_01 = -0b1.01*2^-2  = -0.3125
0xf9 1_11110_01 = -0b1.01*2^14  = -20480.0
0x3a 0_01110_10 = +0b1.10*2^-2  = 0.375
0x7a 0_11110_10 = +0b1.10*2^14  = 24576.0
0xba 1_01110_10 = -0b1.10*2^-2  = -0.375
0xfa 1_11110_10 = -0b1.10*2^14  = -24576.0
0x3b 0_01110_11 = +0b1.11*2^-2  = 0.4375
0x7b 0_11110_11 = +0b1.11*2^14  = 28672.0
0xbb 1_01110_11 = -0b1.11*2^-2  = -0.4375
0xfb 1_11110_11 = -0b1.11*2^14  = -28672.0
0x3c 0_01111_00 = +0b1.00*2^-1  = 0.5
0x7c 0_11111_00 = +0b1.00*2^15  = 32768.0
0xbc 1_01111_00 = -0b1.00*2^-1  = -0.5
0xfc 1_11111_00 = -0b1.00*2^15  = -32768.0
0x3d 0_01111_01 = +0b1.01*2^-1  = 0.625
0x7d 0_11111_01 = +0b1.01*2^15  = 40960.0
0xbd 1_01111_01 = -0b1.01*2^-1  = -0.625
0xfd 1_11111_01 = -0b1.01*2^15  = -40960.0
0x3e 0_01111_10 = +0b1.10*2^-1  = 0.75
0x7e 0_11111_10 = +0b1.10*2^15  = 49152.0
0xbe 1_01111_10 = -0b1.10*2^-1  = -0.75
0xfe 1_11111_10 = -0b1.10*2^15  = -49152.0
0x3f 0_01111_11 = +0b1.11*2^-1  = 0.875
0x7f 0_11111_11 = inf
0xbf 1_01111_11 = -0b1.11*2^-1  = -0.875
0xff 1_11111_11 = -inf