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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

py_ieee754-1.1.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.1.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.1.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.1.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.1.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.1.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.1.0-py3-none-macosx_26_0_x86_64.whl (37.2 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.1.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.1.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: py_ieee754-1.1.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 37.8 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.1.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 4b2bee2333e67fc7fdf5809a3a96c9981745f26b04ed9e34651215a92980bb96
MD5 c3f921d12984946ab55bc0b81cbf9837
BLAKE2b-256 963f67853849db09e6bd559b37764a7ddfec1f79dd182ae41abe26442280cda1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_ieee754-1.1.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.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5684789028b45d7a732e38fc0191f3d719ff052522355e95f8d123a220133dfd
MD5 d3cb800e77b9ec11d5ce73e18106c30e
BLAKE2b-256 dd6097b63962422b219da9272afb9276b343729e25e80231fd685f150a379cc0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0575390198661a71d415b7475df6eb38303b1e7a9b480310ba2040206484c556
MD5 f2b18efc8bf701aa278c40156193a372
BLAKE2b-256 b7ef85365863c8aaaed2038d835dc727398b7702f12b79482b308bb16808e10f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bee60f28cdd088adc11520bf700495e556dd26b4b618ae554a75c5d52a2b04ae
MD5 46c4aa61e85c72b0dc3cb6c3c20f7189
BLAKE2b-256 97832c3fe1e141e70fd1f66eec19f3ce5b670f405f13f5677cdfc909d99f2ebf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4135ae1c8834cd03fb7e7464a3d269e9cf171568ed4c84a57347ccf9dd195827
MD5 787387c4bb433fbc6ff9bb7542f4ed34
BLAKE2b-256 45fd3b1f5fcd541d1003d37dfb9ffef7a1ff2108fdcb077571e0f3617b772d54

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89f24503506b02c3112c20263fee798d070f3e0eeaa407819a360233022a0b37
MD5 91077b19102af4f2261a3eb9c9d94e1a
BLAKE2b-256 be4aca5984dea4321edd0a019f14e950b56517fd135e9cd5e015832ce7f2c68b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 b1ddf88cfe07a40da66c87101972ff0867fc9b94adaeab3c015335b15ed42d8f
MD5 605290920256ee894c90ee3746955d18
BLAKE2b-256 c2bf5bab31cad09e7c0af9acf442e9f558d768d92a5f85a796981f7f77bf67d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.1.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.1.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.1.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 63fe9276260a81802eb80c7fa222140bd4b823d0b138281a089258d6bdba53c5
MD5 f9fb3b27f0d0df1dc96545868729f861
BLAKE2b-256 a262dcdd974fde5677f438b0f612514d2359d0c735c4e7c7c1adcd05745eb646

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 935c0cd6bb9e225ba5837a674b2753f36eabd3995ea1d084d39422c2dea838cd
MD5 63b5f3b59b437ce279231fc4215d43d8
BLAKE2b-256 7835f454b8d1b46c1d19537748e6487ef56f51ab7e409c49ec68bb3051313911

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.1.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8fde81a2a099c8da0867106c64c3a0798b4ac752453bf990f661830df4d472e8
MD5 a9155897e143f745ba56138183f2b229
BLAKE2b-256 1a0c5674faa1baccd866d1df4db55ab4200826728e0590f1ae43f128781cbf68

See more details on using hashes here.

Provenance

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