Overfloat is a .NET 8 Native AOT floating-point library with a native C ABI and a Python binding layer. It is an IEEE 754-oriented arbitrary-precision floating-point library.
The implementation currently supports:
- custom exponent and mantissa widths
- decimal parsing into quantized binary floating-point values
- zero, subnormal, normal, infinity, and NaN classification
- addition, subtraction, multiplication, and division
- exact decimal formatting of quantized results
- native C ABI exports
- Python bindings that load the native library through
ctypes
src/Overfloat- core .NET implementation and native export layerinclude- public C header for native consumerspython- Python package and packaging metadatatests- .NET test projectdocs- architecture and design notes.github/workflows- CI and release automationVERSION- single source of truth for the project version
- .NET 8 SDK
- a platform toolchain supported by .NET Native AOT
Build a native shared library with dotnet publish and an appropriate runtime identifier, for example:
dotnet publish .\Overfloat.csproj -c Release -r win-x64Representative output paths are:
- Windows:
bin/Release/net8.0/win-x64/publish/Overfloat.dll - Linux:
bin/Release/net8.0/linux-x64/publish/libOverfloat.so - macOS:
bin/Release/net8.0/osx-x64/publish/libOverfloat.dylib
To use the Python package without an explicit library path, place the published native library in python/overfloat/ under one of the supported filenames:
overfloat.dllliboverfloat.soliboverfloat.dylib
using Overfloat;
var spec = new OverfloatSpecification(8, 23, OverfloatRoundingMode.ToNearestEven);
var a = OverfloatNumber.Parse(spec, "1.5");
var b = OverfloatNumber.Parse(spec, "2.25");
Console.WriteLine(OverfloatMath.Add(a, b));
Console.WriteLine(OverfloatMath.Multiply(a, b));
Console.WriteLine(OverfloatMath.Divide(a, b));Install from PyPI:
pip install overfloatIf pip is not on PATH, use python -m pip install overfloat instead.
The PyPI wheels bundle the native Overfloat shared library for the target platform.
Use the wheel files attached to GitHub Releases only when you need manual downloads, offline installation, or release troubleshooting.
Each release can contain:
- platform-specific wheels
- platform-specific native library artifacts
Download the wheel that matches the current platform and Python version, then install it with pip.
The current release workflow builds wheels for Python 3.9, 3.10, 3.11, 3.12, and 3.13.
Typical wheel names:
- Windows:
overfloat-<version>-cp<python>-cp<python>-win_amd64.whl - Linux:
overfloat-<version>-cp<python>-cp<python>-manylinux_..._x86_64.whl - macOS:
overfloat-<version>-cp<python>-cp<python>-macosx_11_0_arm64.whl
For example, Python 3.9 uses cp39, Python 3.10 uses cp310, Python 3.11 uses cp311, Python 3.12 uses cp312, and Python 3.13 uses cp313.
Manual wheel install example:
pip install .\overfloat-<version>-cp312-cp312-win_amd64.whlAfter installation, import the package and call OverfloatLibrary() directly.
from overfloat import OverfloatLibrary
lib = OverfloatLibrary()
spec = lib.create_spec_from_total_bits(32) # 32-bit floating-point format, FP32
a = spec("1.5")
b = spec("2.25")
print(a + b)
print(a * b)
print(spec("1") / spec("10"))If no path is passed, OverfloatLibrary() looks for the native library file that is installed alongside the Python package. When the package is installed from a wheel, that library file is already bundled inside the package. It checks these filenames in order:
liboverfloat.sooverfloat.dllliboverfloat.dylib
Example:
from overfloat import OverfloatLibrary
lib = OverfloatLibrary()
spec = lib.create_spec_from_total_bits(4096)
manual_spec = lib.create_spec(43, 4048)
a = spec("1.5")
b = spec("2.25")
manual_value = manual_spec("1.5")
print(lib.version)
print(spec.exponent_bits)
print(spec.mantissa_bits)
print(a + b)
print(a * b)
print(spec("1") / spec("10"))
print(manual_spec.exponent_bits)
print(manual_spec.mantissa_bits)
print(manual_value)
print(a.to_bits_hex())
print(spec.from_bits_hex(a.to_bits_hex()))
print(a.compare(b))
print(a.compare_total(b))
print(lib.exception_flags)create_spec_from_total_bits(total_bits) is the convenient preset form.
create_spec(exponent_bits, mantissa_bits) is the manual form when the exponent width and mantissa width need to be set directly.
Built-in preset formats:
16-> exponent5, mantissa1032-> exponent8, mantissa2364-> exponent11, mantissa52128-> exponent15, mantissa112
These preset values also match the IEEE 754 standard formats. The implementation handles them as direct built-in mappings instead of recomputing them from the formula.
For IEEE 754-2008 interchange-style formats with k >= 128 and k a multiple of 32, create_spec_from_total_bits(k) follows the standard width derivation:
k = total bit width, including the sign bit
w = round(4 × log2(k)) - 13 exponent width
t = k - w - 1 mantissa storage width, excluding the hidden bit
p = t + 1 = k - w precision, including the hidden bit
For explicit lifetime management:
from overfloat import OverfloatLibrary
lib = OverfloatLibrary()
with lib.create_spec_from_total_bits(4096) as spec:
with spec("1.5") as value:
print(value)spec.parse("1.5") remains available for code that prefers the explicit parsing form.
look! that's so easy!
This path is useful for checking a freshly published native build before packaging it into a wheel.
- Build or download a published native library.
- Change into the repository
python/directory. - Load the library with an explicit path.
Example:
from overfloat import OverfloatLibrary
lib = OverfloatLibrary("../bin/Release/net8.0/win-x64/publish/Overfloat.dll")- Build the native library for the target platform.
- Copy the published native library into
python/overfloat/. - Change into the
python/directory. - Run
python -m build --wheel --outdir dist .. - Install the generated wheel from
python/dist/.
Windows example:
dotnet publish .\Overfloat.csproj -c Release -r win-x64
Copy-Item .\bin\Release\net8.0\win-x64\publish\Overfloat.dll .\python\overfloat\overfloat.dll -Force
Set-Location .\python
python -m build --wheel --outdir dist .
pip install .\dist\overfloat-<version>-cp312-cp312-win_amd64.whlAfter installing from PyPI, installing a release wheel manually, or loading a published native library explicitly, run a few quick checks.
Basic arithmetic check:
python -c "from overfloat import OverfloatLibrary; lib = OverfloatLibrary(); spec = lib.create_spec_from_total_bits(32); print(spec('1.5') + spec('2.25'))"Expected output:
3.75
Bit-pattern round-trip check:
python -c "from overfloat import OverfloatLibrary; lib = OverfloatLibrary(); spec = lib.create_spec_from_total_bits(32); a = spec('1.5'); bits = a.to_bits_hex(); print(bits); print(spec.from_bits_hex(bits))"Negative-zero check:
python -c "from overfloat import OverfloatLibrary; lib = OverfloatLibrary(); spec = lib.create_spec_from_total_bits(32); n = spec.from_bits_hex('80000000'); print(str(n)); print(n.to_bits_hex())"The C interface uses opaque handles. Functions that create a specification or number transfer ownership to the caller, and the matching *_free function must be called when the value is no longer needed.
The public header is include/overfloat.h.
OverfloatRoundingMode values:
0-ToNearestEven1-TowardZero2-TowardPositiveInfinity3-TowardNegativeInfinity4-AwayFromZero
dotnet test .\tests\Overfloat.Tests\Overfloat.Tests.csproj -c ReleaseRun Python examples and ad hoc Python checks from the repository python/ directory.
Apache License 2.0