Skip to main content

fast-math-rs

PyPI Python CI License

Arithmetic and number theory on Python numbers, implemented in Rust.

Every function behaves as the Python operator or math function of the same name: int with int gives an exact int, anything with a float gives a float, -7 // 2 is -4, and the errors are Python's own. The one difference is the width of an integer: 64 bits, and a result that does not fit raises OverflowError instead of growing. The core is written in Rust with PyO3, ships as one wheel per platform for every CPython from 3.11 on, and runs without the GIL on free-threaded Python.

Installation

pip install fast-math-rs

The distribution is fast-math-rs (PyPI keeps fast-math for the older fastmath); the module it installs is fast_math.

Requires CPython 3.11+. Wheels: Linux (x86_64, aarch64; glibc and musl), macOS (x86_64, arm64) and Windows (x64), each an abi3 wheel plus one for free-threaded CPython 3.14t. Elsewhere pip builds the sdist, which needs a Rust toolchain.

Quick start

>>> import fast_math as fm
>>> fm.add(2, 3)
5
>>> fm.add(2, 0.5)
2.5
>>> fm.div(7, 2)
3.5
>>> fm.floordiv(-7, 2), fm.mod(-7, 2)
(-4, 1)
>>> fm.pow(2, 10), fm.pow(2, -1)
(1024, 0.5)
>>> fm.gcd(12, 18), fm.lcm(4, 6)
(6, 12)
>>> fm.is_prime(2**61 - 1)
True
>>> fm.primes_up_to(30)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

An integer result beyond 64 bits raises instead of wrapping around or losing precision:

>>> fm.add(2**63 - 1, 1)
Traceback (most recent call last):
  ...
OverflowError: integer result does not fit into 64 bits
>>> fm.factorial(21)
Traceback (most recent call last):
  ...
OverflowError: integer result does not fit into 64 bits

Functions

function Python equivalent result
add(a, b), sub(a, b), mul(a, b) a + b, a - b, a * b int for two ints, float otherwise
div(a, b) a / b always float, correctly rounded for two ints
floordiv(a, b), mod(a, b) a // b, a % b floored: the remainder has the sign of b
pow(base, exp) base ** exp int for an int base and a non-negative int exponent
abs(x) abs(x) the type of x
sqrt(x) math.sqrt(x) float
gcd(a, b), lcm(a, b) math.gcd(a, b), math.lcm(a, b) int, never negative
factorial(n) math.factorial(n) int, up to factorial(20)
fibonacci(n) — int, fibonacci(0) == 0, up to fibonacci(92)
is_prime(n) — bool, exact for every 64-bit integer
primes_up_to(n) — list[int] of the primes <= n, without the GIL meanwhile

Arguments are int (and bool) or float; anything else raises TypeError, an int beyond 64 bits OverflowError. Every difference from Python is listed in Semantics.

Performance

A call into Rust costs about 20 ns more than a call of a C builtin, so fast_math.add is slower than a + b; the core pays off where it does the work in a loop. On an Apple M-series CPU, Python 3.14:

operation fast_math baseline speedup
add(2, 3) 48 ns operator.add, 26 ns 0.54x
fibonacci(90) 66 ns Python loop, 1.6 µs 24x
is_prime, 1000 numbers near 10**18 0.90 ms Python Miller-Rabin, 4.9 ms 5.5x
primes_up_to(10**6) 2.2 ms Python sieve, 19.8 ms 9.0x

Every case and how to rerun them: Benchmarks.

Documentation

License

MIT

Metadata

Release files for fast-math-rs 0.1.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 fast-math-rs 0.1.0
File Size Uploaded Provenance
fast_math_rs-0.1.0.tar.gz 82.1 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for fast-math-rs 0.1.0
File
fast_math_rs-0.1.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 Details
fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64 Details
fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details
fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 Details
fast_math_rs-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
fast_math_rs-0.1.0-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
fast_math_rs-0.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details
fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
fast_math_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
fast_math_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.3 MB

Release files / fast_math_rs-0.1.0.tar.gz

Download URL fast_math_rs-0.1.0.tar.gz
Size 82.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14cbd90693b51fd1f6920435e2b5f826cba6ba2e07d5c05f9375f28fb36f5b87
BLAKE2b-256 checksum
How to use checksums
8db717a977740bafb2529a546e2edf66c4485fa7a16515e9819fbd2a52e8102d
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-win_amd64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-win_amd64.whl
Size 105.1 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
3dcce73fb2289f2021a99ea1c98b5b21a1fc94e402625a2ff0a262835f1b64df
BLAKE2b-256 checksum
How to use checksums
b8f884a17d882b190f8f015624923f89dc060684ac41d587ca7e2e6fb63024e2
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Size 403.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
41cb60bf85f417144afba99eb8f5d57f25cef20bfb42c7d806c8877258c87238
BLAKE2b-256 checksum
How to use checksums
7dea5e43486b0e80e4baa360f888b240cd6013049d70b71cc193332f338f6f38
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_aarch64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-musllinux_1_2_aarch64.whl
Size 364.7 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
669ec5dc1f04a187afc3c5f2fcbef20c388b9d1650952978604a09f5595e5682
BLAKE2b-256 checksum
How to use checksums
d6d43598c59dd77255dcae5821eed2185ee7f20718b3ee40d243e333dddea913
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 191.4 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
56f4b3a8b952234929142bce52c9143bbad1af88bab58c970266b856dfb7f11f
BLAKE2b-256 checksum
How to use checksums
41b74b0c68dab3503c5e15a1a9e3206d052cad29ad3d7897270793b431194f4a
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-manylinux_2_28_aarch64.whl
Size 186.7 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
057600c76b0de220e06977ec63cd9d0ce8f3f0e4ac8a3bd7469f241f866e5d73
BLAKE2b-256 checksum
How to use checksums
be2a539160d33aeeea92b30616bf0f8fba265a6efa895418d8a2ff86d3e7ef58
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 178.8 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1d37ac50442b10bb7c78797286b53e2204bc2255c2153e2dc03cac5885af924a
BLAKE2b-256 checksum
How to use checksums
4eab15d39974321d28321ea1e8d123198b088d4e954f0c64e4454a08c1084238
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL fast_math_rs-0.1.0-cp314-cp314t-macosx_10_12_x86_64.whl
Size 187.4 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
eabf74becbfef4a48702791d8bed966e33b2d2a60d3a54343068d1bd59fb39b5
BLAKE2b-256 checksum
How to use checksums
93c813da65bd7f8c7a74134518be2df3117a4a8422ca1acb97bee966843dd0d4
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-win_amd64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-win_amd64.whl
Size 106.8 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
abc521dc8196d79a6c471d2e2c2af0f0be8879b60e56ffbcc86e3791e5c5ea8e
BLAKE2b-256 checksum
How to use checksums
73a17669125acfb0f53c442d0e8cc1bf00ed1eb2911019d1631847bcc4c96ad9
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 404.3 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6c31626c3ba9c1fe1455a15b9b5bba457f34fa2290e8ffab8ba53e18099b3936
BLAKE2b-256 checksum
How to use checksums
5dd87398902db5ff5af60b04b1ab0d166b959a13b1bba51782bbc0338bb0ba3c
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 365.4 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
116bb809c33c9fdb2357fe9579334f48a14bcd1741f45383cb289335ae06d40e
BLAKE2b-256 checksum
How to use checksums
79f19359829e32ff3cf48b5bf3cd6eff1aed804026eef114c08677bf209220b2
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 192.4 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
a69155c36ac98e9c167ecd4b6e6663e6195cfb8863899909641e38686d860f80
BLAKE2b-256 checksum
How to use checksums
fab8e76ae4ce159f8412783bb2dec2f91a1fc758fc693bc8abef5b6e64e91e82
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 187.4 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
582ef7a65c18af30d996ede3a0402c24ef5ebac28c9301a8e370ee2f7723d784
BLAKE2b-256 checksum
How to use checksums
6336ae9e57e07799f8896410ea521f541ff656066ca48a201c090870be6a4ad9
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 180.7 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ca71bff0da38c29baa267246aded41398e0272143e6701fd6ff360c10b1e548f
BLAKE2b-256 checksum
How to use checksums
e7ecedb205e0aa66cf35b97d6fcdb58261a878c6c792935e5a7e6e5899b395ed
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 17, 2026.

Transparency log

Release files / fast_math_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL fast_math_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 187.8 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c65b96aa60d4c17a17a9483d1adf270e21ec3ea31283219ac27aed0624ea62c1
BLAKE2b-256 checksum
How to use checksums
c490bc9fdae0c6b849345597422b88de1eef9253afefa3dd85161ff0039b27b4
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 17, 2026.

Transparency log

Security for fast-math-rs 0.1.0

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.

Full provenance

All 15 files in this release have been uploaded with provenance metadata.

Select from 15 files

Attestation for fast_math_rs-0.1.0.tar.gz

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 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

15 release files Full provenance

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