Python package for working with arbitrary* precision floating point numbers and their bit-level representations following IEEE-754 rules.
*: currently limited by machine precision, usually 64 bit
pip install anyfloat
>>> from anyfloat import FP8_E4M3
>>> FP8_E4M3.float_from_bitstring('01001000')
3.0
>>> from anyfloat import FloatingPointSpec
>>> FP4 = FloatingPointSpec(num_mantissa_bits=1, num_exponent_bits=2)
>>> FP4.float_from_bitstring('0110')
3.0
>>> FP4.bitstring_from_float(3.0)
0110
For more examples, see examples/
.
Using a Python virtual environment is recommended
Install requirements:
pip install -r requirements.txt
pip install -r requirements-dev.txt
Install this package in editable mode:
pip install -e .
Install pre-commit hooks:
pre-commit install
This repository follows Google's Python Style Guide.