Skip to main content

IEEE 754 float module with bit-operation and round arithmetic support

Project description

py_ieee754

cov

IEEE 754 float number python module with bit-operation and round arithmetic support.

Install

$ pip install py-ieee754

Note

I write this module with vibe coding, but I carefully read every line in src (except the _math <math.h> binding module, which is full of tedious binding code).

I found some bug when I review AI's code, so there might be more. Use with care. I really recommend you to check the code part you are using (usually very short). Bug report is welcomed.

Also note the terminology about "exponent" and "biased exponent".

IEEE 754 says:

biased exponent: The sum of the exponent and a constant (bias) chosen to make the biased exponent’s range non-negative.

  • "biased exponent" E means the raw exp bit pattern interpreted as a uint, i.e. E = e + bias for normalized float, E = 0 for denormalized float.
  • "exponent" e means the exponent, e = 1 - bias for denormalized float

Usage

>>> import py_ieee754 as pi7
>>> import ctypes as ct

>>> # Construction
>>> pi7.F32(1.5)
F32(0b0_01111111_10000000000000000000000)
>>> pi7.F64.from_components("0", "0"*11, "1"*52)# construct from sign, exp and sig bits
F64(0b0_00000000000_1111111111111111111111111111111111111111111111111111)
>>> pi7.F64.from_components("0", "0"*11, -1)    # use -1 to fill specific part with 1
F64(0b0_00000000000_1111111111111111111111111111111111111111111111111111)
>>> pi7.F32.from_bits(0x3FC00000)               # from bit pattern
F32(0b0_01111111_10000000000000000000000)
>>> pi7.IEEE754.from_ctypes(ct.c_float(1.5))    # auto-dispatch (→ F32)
F32(0b0_01111111_10000000000000000000000)

>>> # Field access & classification
>>> a = pi7.F32(1.5)
>>> a.sign, a.exponent, a.biased_exponent, a.significand, a.bits
(0, 0, 127, 4194304, 1069547520)
>>> a.is_nan, a.is_inf, a.is_zero, a.is_subnormal, a.is_normal
(False, False, False, False, True)

>>> # Arithmetic with rounding
>>> pi7.mul(pi7.F32(1.5), pi7.F32("0b1"), round_mode=pi7.RoundingMode.DOWNWARD)
F32(0b0_00000000_00000000000000000000001)

>>> # math.h functions with ctypes interface, round control and fenv exceptions
>>> pi7.math.sqrt(ct.c_double(2.0))
c_double(1.4142135623730951)
>>> pi7.math.fma(
            ct.c_double(1.5), 
            pi7.F64.from_bits(1).ctypes_value, 
            ct.c_double(0), 
            round_mode=pi7.RoundingMode.DOWNWARD)
c_double(5e-324) # = bit 0b1

>>> # interop with numpy
>>> import numpy as np
>>> np.array([pi7.F32(1.5), pi7.F32(1.6), pi7.F32(1.7)], dtype=pi7.F32)
array([1.5, 1.6, 1.7], dtype=float32)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py_ieee754-1.4.0-py3-none-win_arm64.whl (38.0 kB view details)

Uploaded Python 3Windows ARM64

py_ieee754-1.4.0-py3-none-win_amd64.whl (40.6 kB view details)

Uploaded Python 3Windows x86-64

py_ieee754-1.4.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (42.2 kB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64manylinux: glibc 2.34+ x86-64

py_ieee754-1.4.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl (40.7 kB view details)

Uploaded Python 3manylinux: glibc 2.31+ ARM64manylinux: glibc 2.34+ ARM64

py_ieee754-1.4.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (42.1 kB view details)

Uploaded Python 3manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

py_ieee754-1.4.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (40.7 kB view details)

Uploaded Python 3manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

py_ieee754-1.4.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (40.1 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

py_ieee754-1.4.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (42.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

py_ieee754-1.4.0-py3-none-macosx_26_0_x86_64.whl (37.3 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.4.0-py3-none-macosx_15_0_arm64.whl (37.6 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file py_ieee754-1.4.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: py_ieee754-1.4.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_ieee754-1.4.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 62b30facbe150ca30f2373b3342e06b5070741adb63376951f01dac3a1130a17
MD5 4232ad0a74ad0f829599de1eaf935903
BLAKE2b-256 801573dd5dff16fab8ae2bb2ec25e589a478432e912314ef99e99f0c8e409289

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-win_arm64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: py_ieee754-1.4.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_ieee754-1.4.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e0a41dd0ee30017e9798b2199f0517a2c912ff6fcf7120e9a27b8aff74cae2d2
MD5 bbdb38829a63f3c2746314cc3ae5327f
BLAKE2b-256 d86ace87c98a093c2cb185fe14510610b3e4c93c976215d6894b9e25734077b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-win_amd64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 23541e3d3de440b4117daefe037d66e3a4b480decd50fe70874f3856a23e081c
MD5 dba77fa19dc2fa26b1d5031fd30d02be
BLAKE2b-256 f954afb81b50c49a7a53f751a281d3c2d9c2836779015117af78fde9816df571

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2286809f7d3b2c873d1f6b9569edcfd5f9639582747c8aef64c1206571651518
MD5 aa908f03c33950d7b7564d048ce0064d
BLAKE2b-256 b60fb4eb981a49a09532007e003c453678a58b9e8e0edc8ce99e8eb65cb822fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75a04f68b83d9f26eb63c36c7926a2aa0153d156490501d60645394c61db9816
MD5 876de9d7a4bd6c13c65606fd75f1bff0
BLAKE2b-256 8344c3c5645c6e78c90111723d020640ff61681b3392ac78b5870dbc575ddfda

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0ba9bc289b46f8ea42b2d6808838de7ec34d1535fc107e8ebcfe6e921676cbb6
MD5 aa670ad01843d915d44ab35596f03a6a
BLAKE2b-256 bc1584a6cc1bc53e3b159a6c9b13e24d01069295cb42c3755558acb0c3e3f19f

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 2c30166f61e5bb6427d0e498b2faa176145c4b10a1d58bd85c5434fb83177407
MD5 830ae41daaf57ee7ef78a4002c19043e
BLAKE2b-256 1883125bacb807356babaddd7b425ec903669698936ff078c927f7f0163d21df

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5ebf01a343b99c3e27bc8d488bc2042704eca5604025a16851aa8e1377ba8aa8
MD5 ac3919e5313a6c2c0014b8eeca8de118
BLAKE2b-256 bff4397371ca81244457456451f8e467f8af0c9ae9e3bb9ccf57da7e49322b71

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-macosx_26_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 884d49021afdc139fb6ed5059e221d7947a842e0b92e68737db5cfd60dfe8c2e
MD5 feaa55d9e0181ce1e2ef3d803b7dafb5
BLAKE2b-256 53aef280e373b7caf10c38b9f1c01ee33d57788165f80c5cc52a35f34fea8701

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-macosx_26_0_x86_64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_ieee754-1.4.0-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for py_ieee754-1.4.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c4af776d54aba5d2659a96a5ff4700ba5872d69bcc34a821747d661fc123b7fb
MD5 f695115a1c348fd85d5820302a166cd3
BLAKE2b-256 090a745a1a23548ed2b57b85ecd119899bf5870552130573335729f5bd587124

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.4.0-py3-none-macosx_15_0_arm64.whl:

Publisher: release.yml on LXYan2333/py_ieee754

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page