This release is a pre-release and may not be stable for production use.
cfmath
A continued-fraction arithmetic library for Python. Every function returns a
lazy CF object whose terms can be consumed one at a time, or in batches, to
any desired precision.
Public API by module
The tables below list the public functions and the input types they accept. ✓ = supported, — = not applicable.
The *GCF, *CF, and *MP variant rows are implementation backends, not
separate exports. A dispatcher such as Sin (or Arctan) picks one
automatically; to force a particular backend, pass the module's mode enum, e.g.
Sin(x, TrigMode.MP) or Arctan(x, ArctrigMode.CF).
Updating this table: regenerate it by reading
cfmath/__init__.pyfor the exported names, then checking each function's signature (especially the first positional parameter) in the defining module listed here. The column split (int / Fraction / CF) maps toisinstancechecks in the function body; look for_coerce_trig_arg(int+Fraction only),_coerce_meta_trig_arg(int+Fraction+CF),isinstance(x, CF)guards, or the raw type annotation.The
*GCF/*CF/*MPvariants are not exported fromcfmath— they are module-private (e.g.cfmath.trig._SinCF,cfmath.arctrig._ArctanMP) and selected through the function's mode enum, so they will not appear incfmath/__init__.py. Keep their rows; they document the backends the enum chooses between.
cfmath.core — base type
| Symbol | int | Fraction | CF | Notes |
|---|---|---|---|---|
CF |
— | — | — | The lazy continued-fraction type itself; construct via CF.from_int, CF.from_rational, CF.from_fraction, CF.from_float |
cfmath.constants — mathematical constants (no input)
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Pi |
— | — | — | π |
Tau |
— | — | — | 2π |
E |
— | — | — | Euler's number |
Phi |
— | — | — | Golden ratio |
EulerGamma |
— | — | — | Euler–Mascheroni constant |
Catalan |
— | — | — | Catalan's constant |
Apery |
— | — | — | Apéry's constant ζ(3) |
Khinchin |
— | — | — | Khinchin's constant |
Plastic |
— | — | — | Plastic constant |
cfmath.quadratic — quadratic irrationals
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Sqrt |
✓ | — | — | √n for integer n |
cfmath.power — general exponentiation
PowArg = int | Fraction | CF
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Pow |
✓ | ✓ | ✓ | Pow(x, r) — both args accept any PowArg |
PowCF |
✓ | ✓ | ✓ | meta-CF backend for Pow |
PowMP |
✓ | ✓ | ✓ | mpmath backend for Pow |
PowIntExponent |
✓ | ✓ | ✓ | integer-exponent fast path |
PowInterval |
✓ | ✓ | ✓ | interval-arithmetic backend |
Nthroot |
✓ | ✓ | — | Nthroot(x, k) — k-th root of rational x |
Cuberoot |
✓ | — | — | ∛n for integer n |
cfmath.exponential — exponential function
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Exp |
✓ | ✓ | ✓ | eˣ — alias for ExpMP |
cfmath.logarithm — logarithms
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Ln |
✓ | ✓ | ✓ | natural log |
Log |
✓ | ✓ | ✓ | Log(x, base=None) — base defaults to e; base is int | Fraction | None |
Log2 |
✓ | ✓ | ✓ | log base 2 |
Log10 |
✓ | ✓ | ✓ | log base 10 |
cfmath.trig — trigonometric functions
Angles are in radians. *GCF variants accept only rational inputs and use
exact generalized-CF arithmetic. *CF variants accept any CF and use the
meta-GCF algorithm. *MP variants use mpmath for verification.
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Sin |
✓ | ✓ | ✓ | dispatches to SinGCF (rational) or SinCF (CF) |
SinGCF |
✓ | ✓ | — | exact Lambert GCF for rational x |
SinCF |
✓ | ✓ | ✓ | sin/x meta-GCF with z = x², reduces modulo 2π |
SinMP |
✓ | ✓ | ✓ | mpmath; for CF input uses dual-precision convergent approach |
Cos |
✓ | ✓ | ✓ | dispatches to CosGCF (rational) or CosMP (CF) |
CosGCF |
✓ | ✓ | — | exact Lambert GCF for rational x |
CosCF |
✓ | ✓ | ✓ | 1/cos meta-GCF (z = x²); ended up slower than expected, so AUTO sends CF to CosMP — request it explicitly with TrigMode.CF |
CosMP |
✓ | ✓ | ✓ | mpmath; for CF input uses the convergent approach |
Tan |
✓ | ✓ | ✓ | dispatches to TanGCF (rational) or TanCF (CF) |
TanGCF |
✓ | ✓ | — | exact Lambert GCF for rational x |
TanCF |
✓ | ✓ | ✓ | meta-GCF with argument reduction modulo π |
TanMP |
✓ | ✓ | ✓ | mpmath; for CF input uses the convergent approach |
cfmath.arctrig — inverse trigonometric functions
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Arctan |
✓ | ✓ | ✓ | dispatches to ArctanGCF (rational) or ArctanCF (CF) |
ArctanGCF |
✓ | ✓ | — | Gauss GCF for rational x |
ArctanCF |
✓ | ✓ | ✓ | meta-GCF path |
ArctanMP |
✓ | ✓ | ✓ | mpmath; for CF input uses the convergent approach |
Arcsin |
✓ | ✓ | ✓ | rational uses Euler GCF; CF uses mpmath |
Arccos |
✓ | ✓ | ✓ | rational uses π/2 − arcsin; CF uses mpmath |
cfmath.hyperbolic — hyperbolic functions
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Sinh |
✓ | ✓ | ✓ | rational via mpmath/decimal; CF via ExpCF |
Cosh |
✓ | ✓ | ✓ | rational via mpmath/decimal; CF via ExpCF |
Tanh |
✓ | ✓ | ✓ | rational uses Lambert GCF; CF uses mpmath |
cfmath.archyperbolic — inverse hyperbolic functions
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Arcsinh |
✓ | ✓ | ✓ | rational via mpmath/decimal; CF via mpmath |
Arccosh |
✓ | ✓ | ✓ | rational via mpmath/decimal; CF via mpmath |
Arctanh |
✓ | ✓ | ✓ | rational via Ln; CF via mpmath |
cfmath.special — special functions
| Function | int | Fraction | CF | Notes |
|---|---|---|---|---|
Gamma |
✓ | ✓ | — | Γ(x) |
Zeta |
✓ | — | — | ζ(s) for integer s ≥ 2 |
cfmath.gosper — Gosper arithmetic on CFs
All functions take CF inputs and return CF.
| Function | Notes |
|---|---|
cf_add |
x + y |
cf_sub |
x − y |
cf_mul |
x · y |
cf_div |
x / y |
cf_homographic |
(ax + b) / (cx + d) |
cf_min |
min(x, y) |
cf_max |
max(x, y) |
cfmath.convergents — rational approximations
All functions take a CF and work with its convergents p_n/q_n.
| Function | Notes |
|---|---|
convergent |
n-th convergent as Fraction |
convergent_pair |
n-th convergent as (p, q) |
convergent_pairs |
lazy iterator of (p, q) pairs |
convergents |
lazy iterator of Fraction values |
Version compatibility
Python 3.10+. This library follows meanver.
License
cfmath is copyright Tim Hatch, and licensed under
the MIT license. See the LICENSE file for details.
Metadata
Release files for cfmath 1.0.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cfmath-1.0.0rc1.tar.gz | 145.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cfmath-1.0.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 231.6 kB
Release files / cfmath-1.0.0rc1.tar.gz
| Download URL | cfmath-1.0.0rc1.tar.gz |
|---|---|
| Size | 145.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b53c3674f4f984a2d50c0c633e1d5ed69df7fb89f780c477493b0b57dc03257b
|
|
BLAKE2b-256 checksum How to use checksums |
327582fc8401bda85cdf6dafb62910d5e8d61adb2b6acf00ae593c0573558c4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 22, 2026.
Transparency logRelease files / cfmath-1.0.0rc1-py3-none-any.whl
| Download URL | cfmath-1.0.0rc1-py3-none-any.whl |
|---|---|
| Size | 86.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7bd4ce484fe8a59cadd8cd4a63c098cd82b94eea7a8c4bd9e1fcb0ffa81c64e3
|
|
BLAKE2b-256 checksum How to use checksums |
980a18f425710a151ecdc0c535ee555ae1e0476742388c4b33e5d1e029f73ce6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 22, 2026.
Transparency log