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

Uploaded Python 3Windows ARM64

py_ieee754-1.2.0-py3-none-win_amd64.whl (40.5 kB view details)

Uploaded Python 3Windows x86-64

py_ieee754-1.2.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (42.0 kB view details)

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

py_ieee754-1.2.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl (40.6 kB view details)

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

py_ieee754-1.2.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (42.0 kB view details)

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

py_ieee754-1.2.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (40.6 kB view details)

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

py_ieee754-1.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (40.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

py_ieee754-1.2.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (41.9 kB view details)

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

py_ieee754-1.2.0-py3-none-macosx_26_0_x86_64.whl (37.2 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.2.0-py3-none-macosx_15_0_arm64.whl (37.5 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: py_ieee754-1.2.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 37.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-1.2.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 5efedc3ba85502d624b6628a33a98718dd94aa5f2965de99246cc641c4f12340
MD5 8e0795775d89ec48526f345347bb317c
BLAKE2b-256 d91fce2a8bf777751e23f136d79963dc118e931505954712b614d7fdf983e515

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_ieee754-1.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 40.5 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.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6c7cf1a5a5d07d55e333abbcf4d048b322bc1499f12c91812e9dccbb25c026f3
MD5 42eb49e66d990284145480dfca9ae6dc
BLAKE2b-256 de0f1319c5b4a66a182cb65d03ef3ec3fa37e96d8d182242710376c185c6847c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 071e3dea4dc3db0de157bb686334998c21626e43473fb9257ff5e01bf66c9954
MD5 2dffe00ff717d2a25ec82021796a34ec
BLAKE2b-256 ed9cdfd473c79cdd1479aed9649e412bdcba0a622ec2dfe8c8e565b84114b7c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1f58d02586434cfef40b1a519757154f63b33c643299f489abf1deedf8d37858
MD5 e12dda5621a3c94f04d6d213eab954c4
BLAKE2b-256 844e3e87d00eaa18c274211c62068de14b07a024202b5fae2f62320f0d2b856b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 02d08ad7cccd62c00978c6c202828167f69ef0c71f450d0507cb51650604723b
MD5 b32ef8893f03df46d5c458380c399ccd
BLAKE2b-256 e2c7f05b31d2a1caed94a7600fe9a477a469cc05dae234f139ab1dd1747af4e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c04aff7bb8eae12c8143e16e4a13c199c9b0357e1e50687565ff51ff7690cb71
MD5 667643de63677a0574a1629d5c196496
BLAKE2b-256 4ddc60b8ea3c0fa36fd121d6a4d9a4de276d4219be4d9a169da2a3e3728e130d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f0c3d74623894f97f65e2136267602bd5b3ba3dcdf7a48243e3b96db12096084
MD5 3d7f3e6500ffe5a0804652eab8ee9684
BLAKE2b-256 40c525bba474b96303147b2112b9b17c2471dae900b0686ed087a429ac917a5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.2.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.2.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.2.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 8af812a013edeaf496c0b21b79f894fc97e8c5b12c27c74aec509fa402b14c61
MD5 90c679a3bd5d128913677ea0550f4986
BLAKE2b-256 e7180c05f44040d32b312389deeacc8e4434c50e5e4b716af2afacbd36786408

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 cb216839ed1ada750e59bc6e8812b80fc49057750960a1204c9dd340c4641d85
MD5 3cbf8b44baa836cdeaed806defdbf9ee
BLAKE2b-256 9726bd9e1212b6f0a106ceb5a2e821d01a7ddff7af564be7c80ff0db8c6c2571

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.2.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 577eee49d1a859e130011ce829e99ea2857e43a4b7e2f828c70fac22a0813c7d
MD5 83edf68d50b79160d1537678f5bd8ed4
BLAKE2b-256 a31fdf1c6575c9c39fc1a6a09b46f56004671f32459fddd795c6c7ee296ad6b8

See more details on using hashes here.

Provenance

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