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

Uploaded Python 3Windows ARM64

py_ieee754-1.0.0-py3-none-win_amd64.whl (39.3 kB view details)

Uploaded Python 3Windows x86-64

py_ieee754-1.0.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl (40.9 kB view details)

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

py_ieee754-1.0.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl (39.4 kB view details)

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

py_ieee754-1.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (40.9 kB view details)

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

py_ieee754-1.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (39.4 kB view details)

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

py_ieee754-1.0.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (38.9 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

py_ieee754-1.0.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (40.8 kB view details)

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

py_ieee754-1.0.0-py3-none-macosx_26_0_x86_64.whl (36.1 kB view details)

Uploaded Python 3macOS 26.0+ x86-64

py_ieee754-1.0.0-py3-none-macosx_15_0_arm64.whl (36.3 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: py_ieee754-1.0.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 36.6 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.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 99acf89790b34df5b6060f6862fdcbd8fcb143c29ef7584f88d53b398cf4c2c7
MD5 2bbf17973225b9e6f65d6e1317308f6d
BLAKE2b-256 aaae9d0e6f3fdc89e21ad923c72ec1787a760c40e8ca16c769d60b31a4818dde

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_ieee754-1.0.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 39.3 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.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4342fbdc581013dedc575df9576f40c85263b44dfddec25bd2d1be9d01ec6849
MD5 2b4f0b888f18394606fb7664d36af81b
BLAKE2b-256 e0f6a318bc854049a7bbf8f0f10aa391caf1b2388a0c8b122c51cfb9539d852f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bb31b104d024600c0455fe5192fba82996e1d431b6bf9fb3fd10b260c1aa8b48
MD5 5b41cc70773c2eee7ae914999811cfe8
BLAKE2b-256 8318dd26f3cbc1b6b16fd0ca216545c6e3ca954433e05e3ad69d611e96b940e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 24ff0eaae7c7b2f8dfb8095b223eacfbb4ae01d61a960ce7f5972d7020a77646
MD5 9d188ae13ff22d8f1dd94338039820f9
BLAKE2b-256 c7e7962532e318dfeda749b679f8b7d63e6128aafef9f25b960a1d0c15d66eca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f079656a5facb4f0175d07b42621a8084b746252753e06680c9d628ac7e054c9
MD5 cc0fd7fb7e5eb512072b1849e225a2a2
BLAKE2b-256 3d7e2dbd1d5ba461868be5cc7a5a7e195a40b09602ff8d6a93f518f99063b9a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 36e7cf940a967eef633d262b2e3b83946b6fa361565a1d551e38451e2f8ce22f
MD5 655289b2c399b68d07e4d80a35ba400a
BLAKE2b-256 0337a3fb4d136aab17bb3e472587aa3680c20634866cf644b899e8482061a9a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 abe65d6cf39cc6b886558d0dc6f807254664416f63751679ce5dbf6838650560
MD5 b668ef1a57884a629db9a181936b372b
BLAKE2b-256 9a968cd1fb638a4bb837d629785124f75d25843dfe8c5cf340767c637ecf9e49

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ieee754-1.0.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.0.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.0.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b3eff14631e62718dfd091cf049060245e9e2443dd617f66481f5b2657d1dddf
MD5 0798337ff8e9093635cb1c53fc7b6202
BLAKE2b-256 740ee2c3faa74ecec7af2ae2fd011f0d897a206bad80df5f755a52bbbd0a0125

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-macosx_26_0_x86_64.whl
Algorithm Hash digest
SHA256 4fb0b47d9bb4b97a863d1a870de6bacd22d363b849b799da2ec5f0f911a2f473
MD5 381e8b8820081c5019ed0e9a4b1be62f
BLAKE2b-256 791ebfdc7d184a27ebb5b38ebc0efdc4f50a6f679a2e8dd9f624d9694aec4716

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for py_ieee754-1.0.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8a80c0c08998f3fc3722f556c621e0fd22536f91769f9a762bc60858a436ea23
MD5 3fa93e25989f2082362a64ad355c2075
BLAKE2b-256 52ae6bd8af07eabe8579dae746ee9ed4c10427ccb5fe80b479b9c8b144603690

See more details on using hashes here.

Provenance

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