Skip to main content

Simple Python Fixed-Point Module (SPFPM)

spfpm is a pure-Python toolkit for performing binary fixed-point arithmetic, including trigonometric and exponential functions.

The package provides:

  • Representations of values with a fixed number of fractional bits
  • Optional constraints on the number of whole-number bits
  • Interconversion between native Python types and fixed-point objects
  • Arithmetic operations (addition, subtraction, multiplication, division) of fixed-point numbers
  • Methods for computing powers, logarithms and exponents
  • Methods for computing trigonometric functions and their inverses
  • Computation of various mathematical constants, such as pi and log(2), to maximal precision for the chosen fixed-point resolution
  • Printing fixed-point numbers as decimal numbers, or as binary/octal/hexadecimal representations.
  • Support for numbers with thousands of bits of resolution

On a modern desktop PC, spfpm is typically capable of hundreds of thousands of arithmetic operations per second, i.e. over 100 kilo-FLOPS, even for a few hundred bits of resolution. As a pure-Python library SPFPM offers portability and interactivity, but will never compete with the performance of lower-level libraries such as mpmath, Boost multiprecision or GMP for heavyweight calculations.

Development currently targets Python versions 3.7 and later, although the library may also be usable with python-2.7. The latest version of spfpm can be found on GitHub.

Examples

After installation there are two main classes that you need from the FixedPoint module:

from FixedPoint import FXfamily, FXnum

you can create fixed-point numbers with the default (64-bit) resolution as follows:

x = FXnum(22) / FXnum(7)
y = FXnum(3.1415)
print(x - y)

Creating numbers with a specific precision requires use of the FXfamily class:

fam100 = FXfamily(100)
z = FXnum(1, fam100)
z2 = fam100(2)

One can then apply various computations such as:

print(z.atan() * 4)
print(z2.sqrt())

The FXfamily class also provides access to pre-computed constants which should be accurate to about 1/2 of the least significant bit (LSB):

print('pi = ', fam100.pi)
print('log2 = ', fam100.log2)
print('sqrt2 = ', fam100.sqrt2)

This produces the following printed values of those constants:

  • 3.141592653589793238462643383279
  • 0.69314718055994530941723212145 7
  • 1.414213562373095048801688724209

The struck-through digits show where the values computed at 100-bit precision differ from the true digits in the decimal representations of these constants. Alternatively, one could print these values in base-16:

print(FXfamily(400).pi.toBinaryString(logBase=4))

giving a hexadecimal value of Pi as:

  • 3.243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c89452821e638d01377be5466cf34e90c6cc0ac

which agrees exactly with the accepted result.

Licensing

All files are released under the Python PSF License and are Copyright 2006-2026 RW Penney.

Metadata

Release files for spfpm 1.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 spfpm 1.8.0
File Size Uploaded Provenance
spfpm-1.8.0.tar.gz 27.0 kB Without provenance Details

Release files / spfpm-1.8.0.tar.gz

Download URL spfpm-1.8.0.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
98a88b0832bc575c526e8c716515c75a97c82e6ea7a5c5ce08a5adad5141955f
BLAKE2b-256 checksum
How to use checksums
33748f23fab8eec3294bcb331a87c4c710342b96d0af22b9dfa968da751deb86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for spfpm 1.8.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.8.0 This release

1 release file No provenance

1.2

1.1

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