Skip to main content

crfix: correctly rounded fixed-point functions for Python

crfix.sigmoid(x, fin, fout, bits): for every integer x, the exact sigmoid of x·2^−fin rounded once to an integer with fout fractional bits, in the rounding mode you ask for, then saturated to bits. The same goes for exp, exp2, log, log2, tanh, sqrt, rsqrt, the reciprocal and division. Every result is the one an exact computation followed by one rounding would give, so a lookup table or a fixed-point kernel built from it has no error beyond its format.

import numpy as np, crfix
x = np.arange(-128, 128, dtype=np.int8)
y = crfix.sigmoid(x, fin=4, fout=7, bits=8)              # sigmoid(x / 16) as round(sigmoid * 128), int8
t = crfix.table("tanh", fin=5, fout=7, bits=8)            # an int8 kernel's lookup table: t[x + 128]
q = crfix.div(a, 8, b, 8, fout=12, bits=16, mode="down")  # (a / 256) / (b / 256), rounded down

TFLite's affine formats, where a value is scale·(q − zero_point), for any scales:

inp, out = crfix.Affine(0.0478, 3), crfix.Affine(1 / 256, -128)
t = crfix.table_affine("sigmoid", inp, out)               # a LOGISTIC kernel's table, every entry correctly rounded
p = crfix.softmax(logits, c=beta * 0.0478, out=out)       # the exact softmax of c·logits, rounded into out

A lookup table as C source, CSV or a list, from the command line (--f32 rounds decimal scales to float32 first, as a TFLite model stores them; hex floats such as 0x1p-8 are taken exactly):

python -m crfix table tanh --fin 5 --fout 7 --bits 8 --format c
python -m crfix table-affine sigmoid --in 0.0478,3 --out 0x1p-8,-128 --f32 --format c --name logistic
  • Modes: "nearest" (ties to even), "up", "down" and "zero". In an affine format, "zero" rounds the value itself toward 0, before the zero point is added.
  • Domain edges: log of a value ≤ 0 gives the most negative result. sqrt of a negative value gives 0. rsqrt of a value ≤ 0, and the reciprocal of 0, give the largest. a/0 goes by a's sign, and 0/0 gives 0.
  • Integer arithmetic only: the library has no floating point, and gives the same bits on x86-64, ARM64, 32-bit ARM and a Cortex-M0.
  • How it is proven: every 16-bit input, in every format, mode and container, is checked against MPFR. Results that the fast 64-bit enclosures cannot decide go to interval arithmetic that is correct by construction. This package's own tests use a second, independent reference: Python's decimal and exact fractions.

pip install crfix brings a wheel with the library, libcrfix.so.0 (or libcrfix.0.dylib on macOS); CRFIX_LIBRARY names another. The methods and their checks are in crnumerics' fix/README.md.

Metadata

Release files for crfix 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crfix 0.8.0
File Size Uploaded
crfix-0.8.0.tar.gz 12.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for crfix 0.8.0
File Interpreter ABI Platform
crfix-0.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details
crfix-0.8.0-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl Python 3 none Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details
crfix-0.8.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 104.8 kB

Release files / crfix-0.8.0.tar.gz

Download URL crfix-0.8.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
983a2d542dd4ccb075954081f507e28cb406432f39407da912c82c2943227d95
BLAKE2b-256 checksum
How to use checksums
0135db09101448ed78b1169c904fec3fdee2bdfe3c301300d0ebda75b6ef8f66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / crfix-0.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL crfix-0.8.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 32.3 kB
Tags Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
59c2b15634cd0030cd7851e71217f0e7dcba5a3fc9039a9e7e1fb11f5c68cdda
BLAKE2b-256 checksum
How to use checksums
352c940905e9934fc2af321ef6373cf9c7de9f456bd01138d01ad6f48516bbf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / crfix-0.8.0-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL crfix-0.8.0-py3-none-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 31.4 kB
Tags Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
5940595bf306b92b2d07b26b1b18cd952587ca2ad62936ad6a9c770c8eb9a581
BLAKE2b-256 checksum
How to use checksums
682472bb2d1809d3d0aa130de9ea14745ad62a70c497946c0f9a225e34b24dae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / crfix-0.8.0-py3-none-macosx_11_0_arm64.whl

Download URL crfix-0.8.0-py3-none-macosx_11_0_arm64.whl
Size 28.6 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
457d85f241f16c7214cb8536e6e9de1b7c6a7ffa65264031a717c2ca5d866d11
BLAKE2b-256 checksum
How to use checksums
619a101e1881750a1761bb9e26243e307b4f87feacac9eb5d69863f5148179c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.0

4 release files

This release

0.8.0 This release

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page