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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

py_ieee754-1.3.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (42.1 kB view details)

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

py_ieee754-1.3.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.3.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.3.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.3.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.3.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.3.0-py3-none-macosx_26_0_x86_64.whl (37.3 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.3.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.3.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: py_ieee754-1.3.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.3.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 9fff04bacc94fe8c724135c379a9cdd8aec83be33c42f5fe6b733fcbff021b90
MD5 d7ace65cfd7e3d798973a3f114e90df2
BLAKE2b-256 062ec1474ba87141ce3b766eadda16b4e85b9936435fca6c999578f73933708d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_ieee754-1.3.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.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 71dbb5aea1369f3d9f262a6289b341749a1e1860a13f73f2969d7cb11fe2d432
MD5 7a2309b3df35eda9b2c5931a324867d4
BLAKE2b-256 c1423ec1fcba876a33069fd5a292aaf541bee5d94bae108c40bf0c6ecd023b92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c5d486ff61ee12981431717b32cd0ed750b3078731f0fbc11d01cc7dc04863ab
MD5 94ff6ea23a6fde871e2cc392347754b5
BLAKE2b-256 d802919fe3544f1b951d171ff48562c14e7dd3d02db5b515c8e3cda1cd5f4e3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9840ff3f2717192cf30a5c8f32b297d01188cd721f7a3693f9b64340079a5e12
MD5 19f7561acab585845158a5d2eb986e85
BLAKE2b-256 9073def1838298b7a30ace01ba4a9b1c692e90ea7eb6d61dce593dd618c5ad37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7fba1700c395073a8767ad90f525439ff8d32715bfc2573b25a029cafc5a4550
MD5 6f01b87421296bb4e78d7ddcb5c70a3f
BLAKE2b-256 e6afbdc6645d2aa459c980ba187e19993347c687bae0f7cf39b3294898d2b39b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 de6ce2e65210204245aaf5f857435ed3f5937e1db3b5fdf53c944497044ff426
MD5 8c2e534eb1dd84adc542ebbcea7905a8
BLAKE2b-256 829d208b6593c7a57a2f753bf9ebd758ee2c2db2cfe648a997fd4dd3be5fb10f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 9dced8974f6109085d2af08756abf5a8210dfc4121c4664ad17847b52b063506
MD5 fdf764c680d879b1dedeb1c2be37e196
BLAKE2b-256 228728eec68cd273ac0b22e4e81b2c7e614b76b52afa9fd96dc95ea77988677c

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.3.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.3.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.3.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 11c45e89a9080a35809a9cd44fe351c34db40e22363fa1e92380067087d0a886
MD5 f452417caa4669bcca9ae18873638f1b
BLAKE2b-256 703f03ce2d47e3afae4ddc66ef4804a60928c42ee06e72ee0fb4f128b39fd8d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 44b97365764001e8617bff355ec0949439b15dd8f775234de482b24191f79a33
MD5 59ab8fc1ffbb231d61b0c5e56c847850
BLAKE2b-256 7403332346d77177d579b0bfeb7593d3d6d69f08817e34cd164a28fc7bdc950e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.3.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b2b25e36fc8a55c5442283e986a79482f2f0c6309a5d13d7b58826c4e121bb27
MD5 f8de53c55dd654a98f43a6086371e2ca
BLAKE2b-256 8926d3c72574d0e3db789bb0430b26e82cdfc6b12bac5eec0393e9430e64280b

See more details on using hashes here.

Provenance

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