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

Uploaded Python 3Windows ARM64

py_ieee754-1.0.1-py3-none-win_amd64.whl (39.7 kB view details)

Uploaded Python 3Windows x86-64

py_ieee754-1.0.1-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (41.3 kB view details)

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

py_ieee754-1.0.1-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl (39.8 kB view details)

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

py_ieee754-1.0.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (41.3 kB view details)

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

py_ieee754-1.0.1-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (39.8 kB view details)

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

py_ieee754-1.0.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (39.2 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

py_ieee754-1.0.1-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (41.1 kB view details)

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

py_ieee754-1.0.1-py3-none-macosx_26_0_x86_64.whl (36.5 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.0.1-py3-none-macosx_15_0_arm64.whl (36.7 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: py_ieee754-1.0.1-py3-none-win_arm64.whl
  • Upload date:
  • Size: 37.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.0.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 fb6a3a68b0a2ce8ecec90b0c57c03646549906683238ca58170140f7cd073810
MD5 a0891e7411957af27412b90e6bc63a64
BLAKE2b-256 88cff895614e681a3571dae36db3bae77e4631d6f2d9620ea31783b4d3d88e38

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_ieee754-1.0.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 39.7 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.0.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 d1a9187921a82e3e824b16f8139e3b1005de3b6b68d73cd466b9c556864f6613
MD5 5552a96fa5b095dc0b10794365eff33f
BLAKE2b-256 6648e019c7e7752620701b0107a6bdd1f15c322baa4341a50ff11f7ffbc98827

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4fe80fee6437a16806c3cffcbb1da25257018769cbd24d423048f4c3c3e6fe45
MD5 faa871bb1bb34ad32a153df12ae397eb
BLAKE2b-256 935ffa0064c39c361fc263c6f97addd6dcc44c059af77ac9fca4c138aca93eb3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 e2a342ba977e7b4d932a6c86de5e7f9a46edd36417ba5618ae7a3ef2cff54974
MD5 0292afb211ed2edc180ec9cc2a2ad5a9
BLAKE2b-256 14010cd3b2a0054ad1265cbfb0502886520482753b4629efa9db5c223f1e2c8b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb4a621a92c7dd229aec35afbf2d6102d8a3559dde6b637a01bf60f67bdb1613
MD5 86761d79fc8a7e049f0edcddc0a0f706
BLAKE2b-256 852e01ddb0535584a2819ff65c97172dcb98e9a40a19b9633e46be337e08825c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e2b51c24392ce946fc6a9cdf4ed3e04f4a09dc0e4d865efdeb019263ef54cddd
MD5 d6951f45ad0c0baaf45b71db0e830c4a
BLAKE2b-256 c125428885526ed62025371de4de51f49acb7863807d504ed93d72a1e6ec8e73

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 6118a83e3ca022a4c554ee3769919aa0ffea8dd357daf4d136b065fab61312c7
MD5 9d4ffd71b4f8cfea935e78054b7e8b07
BLAKE2b-256 c1cffd6ad440898fa274bc57cc36a2b5262641e32f138e3cbae41df819399eeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.0.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-1.0.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-1.0.1-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 930ac4a09397caf472661e390ff6652157371351a2a4e464d5ea2e835f6b289d
MD5 a15c08e912378dc24d933b774973ee11
BLAKE2b-256 9c2adaa2c7acb26b2e44766517771f66b74b7bb4cb178951dcd68f3dad0b1ffd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 96c78816713d2f8e2536cd88e6be0e3d61c9cf9e44363796ad5edbce95572c2d
MD5 bada57fe32db69c79bb9573b1be0cae5
BLAKE2b-256 028ca932e47ae999754d54d9da79a7babe3101b7f168e1714b6436dd69b9ef62

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.1-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 228b1b215a5a0a82601a99c959a8d43e40f9ce7284ee71ae240792a01bbbb176
MD5 3742cc344325b801713ef8defa61dd59
BLAKE2b-256 04d4df40567fd69bf7734824fec958c6dde4b96db406211e18c769cd98608f82

See more details on using hashes here.

Provenance

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