IEEE 754 float module with bit-operation and round arithmetic support
Project description
py_ieee754
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"
Emeans the raw exp bit pattern interpreted as a uint, i.e.E = e + biasfor normalized float,E = 0for denormalized float. - "exponent"
emeans the exponent,e = 1 - biasfor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5efedc3ba85502d624b6628a33a98718dd94aa5f2965de99246cc641c4f12340
|
|
| MD5 |
8e0795775d89ec48526f345347bb317c
|
|
| BLAKE2b-256 |
d91fce2a8bf777751e23f136d79963dc118e931505954712b614d7fdf983e515
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-win_arm64.whl -
Subject digest:
5efedc3ba85502d624b6628a33a98718dd94aa5f2965de99246cc641c4f12340 - Sigstore transparency entry: 1544980008
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c7cf1a5a5d07d55e333abbcf4d048b322bc1499f12c91812e9dccbb25c026f3
|
|
| MD5 |
42eb49e66d990284145480dfca9ae6dc
|
|
| BLAKE2b-256 |
de0f1319c5b4a66a182cb65d03ef3ec3fa37e96d8d182242710376c185c6847c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-win_amd64.whl -
Subject digest:
6c7cf1a5a5d07d55e333abbcf4d048b322bc1499f12c91812e9dccbb25c026f3 - Sigstore transparency entry: 1544979832
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
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
- Download URL: py_ieee754-1.2.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3, manylinux: glibc 2.31+ x86-64, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
071e3dea4dc3db0de157bb686334998c21626e43473fb9257ff5e01bf66c9954
|
|
| MD5 |
2dffe00ff717d2a25ec82021796a34ec
|
|
| BLAKE2b-256 |
ed9cdfd473c79cdd1479aed9649e412bdcba0a622ec2dfe8c8e565b84114b7c7
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux_2_31_x86_64.manylinux_2_34_x86_64.whl -
Subject digest:
071e3dea4dc3db0de157bb686334998c21626e43473fb9257ff5e01bf66c9954 - Sigstore transparency entry: 1544979227
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ieee754-1.2.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl.
File metadata
- Download URL: py_ieee754-1.2.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3, manylinux: glibc 2.31+ ARM64, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f58d02586434cfef40b1a519757154f63b33c643299f489abf1deedf8d37858
|
|
| MD5 |
e12dda5621a3c94f04d6d213eab954c4
|
|
| BLAKE2b-256 |
844e3e87d00eaa18c274211c62068de14b07a024202b5fae2f62320f0d2b856b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux_2_31_aarch64.manylinux_2_34_aarch64.whl -
Subject digest:
1f58d02586434cfef40b1a519757154f63b33c643299f489abf1deedf8d37858 - Sigstore transparency entry: 1544979415
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
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
- Download URL: py_ieee754-1.2.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02d08ad7cccd62c00978c6c202828167f69ef0c71f450d0507cb51650604723b
|
|
| MD5 |
b32ef8893f03df46d5c458380c399ccd
|
|
| BLAKE2b-256 |
e2c7f05b31d2a1caed94a7600fe9a477a469cc05dae234f139ab1dd1747af4e7
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
02d08ad7cccd62c00978c6c202828167f69ef0c71f450d0507cb51650604723b - Sigstore transparency entry: 1544979606
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ieee754-1.2.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: py_ieee754-1.2.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c04aff7bb8eae12c8143e16e4a13c199c9b0357e1e50687565ff51ff7690cb71
|
|
| MD5 |
667643de63677a0574a1629d5c196496
|
|
| BLAKE2b-256 |
4ddc60b8ea3c0fa36fd121d6a4d9a4de276d4219be4d9a169da2a3e3728e130d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
c04aff7bb8eae12c8143e16e4a13c199c9b0357e1e50687565ff51ff7690cb71 - Sigstore transparency entry: 1544979094
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ieee754-1.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.
File metadata
- Download URL: py_ieee754-1.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
- Upload date:
- Size: 40.0 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0c3d74623894f97f65e2136267602bd5b3ba3dcdf7a48243e3b96db12096084
|
|
| MD5 |
3d7f3e6500ffe5a0804652eab8ee9684
|
|
| BLAKE2b-256 |
40c525bba474b96303147b2112b9b17c2471dae900b0686ed087a429ac917a5d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl -
Subject digest:
f0c3d74623894f97f65e2136267602bd5b3ba3dcdf7a48243e3b96db12096084 - Sigstore transparency entry: 1544979312
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
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
- Download URL: py_ieee754-1.2.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 41.9 kB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8af812a013edeaf496c0b21b79f894fc97e8c5b12c27c74aec509fa402b14c61
|
|
| MD5 |
90c679a3bd5d128913677ea0550f4986
|
|
| BLAKE2b-256 |
e7180c05f44040d32b312389deeacc8e4434c50e5e4b716af2afacbd36786408
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
8af812a013edeaf496c0b21b79f894fc97e8c5b12c27c74aec509fa402b14c61 - Sigstore transparency entry: 1544979724
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ieee754-1.2.0-py3-none-macosx_26_0_x86_64.whl.
File metadata
- Download URL: py_ieee754-1.2.0-py3-none-macosx_26_0_x86_64.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3, macOS 26.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb216839ed1ada750e59bc6e8812b80fc49057750960a1204c9dd340c4641d85
|
|
| MD5 |
3cbf8b44baa836cdeaed806defdbf9ee
|
|
| BLAKE2b-256 |
9726bd9e1212b6f0a106ceb5a2e821d01a7ddff7af564be7c80ff0db8c6c2571
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-macosx_26_0_x86_64.whl -
Subject digest:
cb216839ed1ada750e59bc6e8812b80fc49057750960a1204c9dd340c4641d85 - Sigstore transparency entry: 1544979907
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_ieee754-1.2.0-py3-none-macosx_15_0_arm64.whl.
File metadata
- Download URL: py_ieee754-1.2.0-py3-none-macosx_15_0_arm64.whl
- Upload date:
- Size: 37.5 kB
- Tags: Python 3, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
577eee49d1a859e130011ce829e99ea2857e43a4b7e2f828c70fac22a0813c7d
|
|
| MD5 |
83edf68d50b79160d1537678f5bd8ed4
|
|
| BLAKE2b-256 |
a31fdf1c6575c9c39fc1a6a09b46f56004671f32459fddd795c6c7ee296ad6b8
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_ieee754-1.2.0-py3-none-macosx_15_0_arm64.whl -
Subject digest:
577eee49d1a859e130011ce829e99ea2857e43a4b7e2f828c70fac22a0813c7d - Sigstore transparency entry: 1544979534
- Sigstore integration time:
-
Permalink:
LXYan2333/py_ieee754@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/LXYan2333
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8accdfd8c77c31d41d045de6e4cb30db39 -
Trigger Event:
push
-
Statement type: