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":

  • "exponent" means the raw exp bit pattern interpreted as a uint
  • "biased exponent" means the exponent after the IEEE754 bias rule applied, i.e. (exponent - bias) for normalized float, (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.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.significand, a.bits
(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

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-0.1.1-py3-none-win_arm64.whl (35.9 kB view details)

Uploaded Python 3Windows ARM64

py_ieee754-0.1.1-py3-none-win_amd64.whl (38.6 kB view details)

Uploaded Python 3Windows x86-64

py_ieee754-0.1.1-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (40.2 kB view details)

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

py_ieee754-0.1.1-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl (38.7 kB view details)

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

py_ieee754-0.1.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (40.1 kB view details)

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

py_ieee754-0.1.1-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (38.7 kB view details)

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

py_ieee754-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (38.1 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

py_ieee754-0.1.1-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (40.0 kB view details)

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

py_ieee754-0.1.1-py3-none-macosx_26_0_x86_64.whl (35.4 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-0.1.1-py3-none-macosx_15_0_arm64.whl (35.6 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: py_ieee754-0.1.1-py3-none-win_arm64.whl
  • Upload date:
  • Size: 35.9 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-0.1.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 c2461a1588396c46c4b8847ea0e0e38ef92715d5b45b4534435af72db80fe8ba
MD5 fb2d82874f1296d69db8c7273d694e2b
BLAKE2b-256 599a868a9a98f14c9ebeee38f7460de8b701d26995cb6ec1de0d0f575222ced1

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: py_ieee754-0.1.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 38.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-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 11d353d4d8a8d88f52fe829da8336c025a32e4d7166a362d004ae835c4e99843
MD5 c93504513dd2abb322a95eb0a8fccb81
BLAKE2b-256 baaab5b3a74b4d508fe30ae4649bb78130e638a18beeab501c546db2468693f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0164b8918876bebb98136513801b51acacbf549dfe979b23e67576c6907202ff
MD5 edd8ad8cf3eb787c02ba0b41a8c52179
BLAKE2b-256 bd8b8f6ce458afd530b01e26e2bb3f121d193671b31c4d12c952232227d778d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 957492139c4cf9f7f9505259fcc0bef00dad5025ab85bda3140944fcd51081b9
MD5 37c4e9aeb983223e698e2b01a9375eae
BLAKE2b-256 56b6ac4d855c8938b693e5a8fbac4b4ee79742a8f345b1a34cb6ef5f6319d1e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3972025f3ab79e85f4fec8d810a5281f43503599a3a6e4a4b95c77c7c1df19ab
MD5 34c64edb2e9026ae6c506c4310428190
BLAKE2b-256 336dbcb1141f337f88ed7c8ec7934166be805dfc6e0ee3b31dfd8ba7fd4823a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f516faf037c7265d32e9335ce02cb849df80abfe8c6f299501bfddf15d1b4a68
MD5 e260ef220344b6845dd24c1fe415394d
BLAKE2b-256 18b2db63fe15ae5a278b23ef6c7776e36872b8749ba9948c37e69b92d5341f98

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 14bac8fe6f5fcb687d234e4000863d48faec2514e847732ed536316a08803c00
MD5 4f8ff2e4eab7390ac2e3047db684a9d0
BLAKE2b-256 015aa07119a120a079031e5687124b240bd24e9967df52f0f34a25184ca4f9eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-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-0.1.1-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0c01aa248dd1b59972e52a08e760abcdd1780ce12565a91411503b8e656dc73f
MD5 1e285e648edb5741cd53941b9a0254e6
BLAKE2b-256 09115cd3dd5f913636a41a6372055ee806cf705667ba8168aba699b67d18327d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-macosx_26_0_x86_64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 c7cd7f4f13a3e28f9ffbe00c428bbb42fb228a3bda323240d24ae26362bb3ad7
MD5 af9db76f6e6c0d90b3465decc951df2d
BLAKE2b-256 edc2af3c53dfc4d0cf359b8b0ce8202d1a5bce86aea486be699b0b7c6c2901d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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-0.1.1-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for py_ieee754-0.1.1-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c9b358491e057aefb96556ced699af0928f9e129f3dd397f7527e25384a45f3e
MD5 f17f7131fd23282b457eb82195f571f6
BLAKE2b-256 da24502aeacbb77c0c4a70267e08d1387c34d8d72448e248d78312f3d8abd874

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-0.1.1-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