Skip to main content

A Python binding of Berkeley SoftFloat

Project description

SoftFloatPy

Overview

SoftFloatPy is a Python binding of Berkeley SoftFloat.

Berkeley SoftFloat is a software implementation of binary floating-point functionalities that conforms to the IEEE Standard for Floating-Point Arithmetic (IEEE 754 and the succeeding standards).

As of December 2025, the latest release is Berkeley SoftFloat 3e, and SoftFloatPy supports the following features in it.

  • four binary floating-point formats:
    • 16-bit half-precision format (the binary16 format),
    • 32-bit single-precision format (the binary32 format),
    • 64-bit double-precision format (the binary64 format),
    • 128-bit quadruple-precision format (the binary128 format).
  • addition, subtraction, multiplication, division, remainder, fused multiply-add, and square root.
  • round to an integer value.
  • comparisons.
  • conversions between the supported floating-point formats.
  • conversions between the 32-bit single-precision format and the 16-bit brain floating-point format (bfloat16).

The following features that are not in the IEEE 754 standard are excluded from SoftFloatPy support.

  • 80-bit extended format (known as x86 extended-precision format).
  • odd-rounding mode (known as jamming).

SoftFloatPy requires Python 3.11 or later. The build configuration provided in the SoftFloatPy repository assumes platforms with 64-bit integer arithmetic support.

The GitHub page is https://github.com/arithy/softfloatpy.

Links related to Berkeley SoftFloat:

Installation

Release Version

You can install the release version by the following command.

$ python -m pip install softfloatpy

Development Version

You can install the development version by the following commands.

$ cd softfloatpy  # the repository root directory
$ make req
$ make clean
$ make dist
$ python -m pip install --no-index --find-links=./dist softfloatpy

Usage

Import of Module

To use SoftFloatPy in a Python script, import softfloatpy module. An example is shown below.

import softfloatpy as sf

Creation of Objects

To use the SoftFloatPy functions, you need to create objects of the classes shown below.

For the floating-point classes, there are two options to create its object.

  • Creation from bytes. Below is an example of Float16 with the value 1.0.
    f = sf.Float16.from_bytes(b'\x3c\x00')  # The byte order is big-endian.
    
  • Creation from float. Below is an example of Float16 with the value 1.0.
    f = sf.Float16.from_float(1.0)
    

For the fixed-bit integer classes, there are two options to create its object.

  • Creation from bytes. Below is an example of Int32 with the value 1.
    i = sf.Int32.from_bytes(b'\x00\x00\x00\x01')  # The byte order is big-endian.
    
  • Creation from int. Below is an example of Int32 with the value 1.
    i = sf.Int32.from_int(1)
    

Arithmetic of Objects

Once creating the objects, you can use the functions described in the SoftFloat documentation.

a = sf.Float16.from_float(2.0)
b = sf.Float16.from_float(-3.0)
c = sf.f16_mul(a, b)

In addition, you can use Python operators for arithmetic operations such as +, -, *, //, and %. For more details, see the SoftFloatPy API documentation.

a = sf.Float16.from_float(2.0)
b = sf.Float16.from_float(-3.0)
c = a * b

Conversion to Built-in Types

You can retrieve the value retained in an object as a Python built-in type.

For the floating-point classes, there are two built-in types to retrieve the value.

  • Retrieve the value as bytes. Below is an example of Float16.
    print(f.to_bytes())
    # -> b'\x3c\x00'  (The byte order is big-endian.)
    
  • Retrieve the value as float. Below is an example of Float16.
    print(f.to_float())
    # -> 1.0
    

For the fixed-bit integer classes, there are two built-in types to retrieve the value.

  • Retrieve the value as bytes. Below is an example of Int32.
    print(i.to_bytes())
    # -> b'\x00\x00\x00\x01'  (The byte order is big-endian.)
    
  • Retrieve the value as int. Below is an example of Int32.
    print(i.to_int())
    # -> 1
    

The other option is to create a string representation of the object value using str() or formatted strings.

print(f'value: {f}')
# -> value: 1.0

Setting of Rounding Mode

You can set and get the default rounding mode using the functions below.

The rounding mode is a thread-local property.

Check of Floating-Point Exceptions

You can set, get, and test the floating point exceptions using the functions below.

The floating-point exceptions are thread-local properties.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

softfloatpy-1.2.3.post1.tar.gz (511.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

softfloatpy-1.2.3.post1-cp313-cp313t-win_amd64.whl (344.3 kB view details)

Uploaded CPython 3.13tWindows x86-64

softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

softfloatpy-1.2.3.post1-cp313-cp313t-macosx_10_13_universal2.whl (762.0 kB view details)

Uploaded CPython 3.13tmacOS 10.13+ universal2 (ARM64, x86-64)

softfloatpy-1.2.3.post1-cp313-cp313-win_amd64.whl (294.5 kB view details)

Uploaded CPython 3.13Windows x86-64

softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

softfloatpy-1.2.3.post1-cp313-cp313-macosx_10_13_universal2.whl (751.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

softfloatpy-1.2.3.post1-cp312-cp312-win_amd64.whl (295.3 kB view details)

Uploaded CPython 3.12Windows x86-64

softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

softfloatpy-1.2.3.post1-cp312-cp312-macosx_10_13_universal2.whl (754.5 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

softfloatpy-1.2.3.post1-cp311-cp311-win_amd64.whl (299.9 kB view details)

Uploaded CPython 3.11Windows x86-64

softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

softfloatpy-1.2.3.post1-cp311-cp311-macosx_10_9_universal2.whl (769.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file softfloatpy-1.2.3.post1.tar.gz.

File metadata

  • Download URL: softfloatpy-1.2.3.post1.tar.gz
  • Upload date:
  • Size: 511.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for softfloatpy-1.2.3.post1.tar.gz
Algorithm Hash digest
SHA256 3fa06b53c4fad09f3395138eccd5dd9ba8bb918b10665bab06143326d69ab81d
MD5 5d17010ff1cbb4bde66e134663853a6b
BLAKE2b-256 68fa29e38d4abee887ad60f63d62d591122e2ae332e5007856d744a8d3a5a782

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1.tar.gz:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 944742f0d4e6071399dd325e51aa0755950d395faa7c8d55b3fce6319197cbb0
MD5 efbf11486dc0127ced32d846d7569a6c
BLAKE2b-256 21ae0c98dd1ed5c6e99b4aede73de888705f023ff4f28c40fbca6d591bc9def6

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313t-win_amd64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d43cfb9906c035f8ade315fc0a28aaad2aeaf5181bea506fdb067842101906f4
MD5 199267236233f230ba635c7ea325c29a
BLAKE2b-256 550ebc0246446b52f397dcacd5861304fda7ad0728ccb8757b5b43c48833a1d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 fd225849392f47dba2dd68e4542cb881c2c2501777e343e73066219ec72ba0a4
MD5 858df797871e0e78c8f85adb8f501358
BLAKE2b-256 3d35fbdb92a4df96340df492f67ee23f9c27c42e1b0eca9ca445a8a05944af81

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313t-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313t-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 2c84239138d32aa9857387ef3bf38e0da852d9a0241380c0711efe3b7019df65
MD5 0c6349834347387f31a6d5657358b0e7
BLAKE2b-256 6e74b6a8c205ab78c2847d8f8446b050baf844b68fc9b143b489b97c3c55c4eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313t-macosx_10_13_universal2.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 50c541a947f2215263fd2b2133026de4565ef3f88b5289775a8eeea6f17dcb33
MD5 821627c897ca3cd2fb7d10d6d0c07876
BLAKE2b-256 edf766060d6bee7bbef0d1a8aebc57f4d695b2d7eccedf32205132fdf841472c

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313-win_amd64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 e4e7ec28b323ad1597146732bb07e230123f610435a7b44601533bb5a17a86b3
MD5 d6caa12e62a603bd0f7e76db4bc19d42
BLAKE2b-256 1364108239e7219d6cdf7bc03df6a28aa7cb0f8f9290b169cf7288c0b1b365e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 708c8856a72916aebda4150fb60069257b58a063932b8fe33ea09ec39f95282b
MD5 1c7b1caf8a89078334c27e70bea240cb
BLAKE2b-256 fcc861b02fbde491a296c719748c83c2a7b226801e04d301537632bf8f76a1e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 0c83486309a5ebce99aaff6936c8cb302f66ed601da59c4fd0660e54330a7448
MD5 55da9ba7a5a8b4db40ecf9241864a9d2
BLAKE2b-256 55dcfc7f23854ba1d9d4748f3127ec065d7d8fba077a35c37b4dc97ce65b2f77

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ad7aeddcdeeeaf6d19475fb87ea7d415ea9fc6b7c932d95310dd49b2da3892b6
MD5 9b2e030199e186ec85adccf78546e818
BLAKE2b-256 cbc31a78580bc18627767a3862fd57866129d95f8d71a5b131bcf86ae973793f

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp312-cp312-win_amd64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 2657855478c5f85075d440aaa2dedb25b731ad06303b309868f8007fdb035ff2
MD5 f5285e8b1766d75ba33b4ca2146e66e4
BLAKE2b-256 3f279fad47760d3ad780967cb04f9ab70778cf557fd0a7456f5797dd9e4933a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 a6d9a734ad80b1622c8dabbcc5fed3d8da1e9950054a4116cb9e5963e4756341
MD5 621dea99f4207404d141a18637d399d1
BLAKE2b-256 04337de6f6db28b01aafd619e95cad03f3a0e1332ec4b5b93014dbdbf9c586b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a6842ab750e460f2c462f3cf491bc760a1213e96939052c5864d962d8f0d63e8
MD5 fc34b39ea9250e9025c3dadf7a2c0acd
BLAKE2b-256 ab076117a4b723b0cd28be19372d4b39c3ee4a48c88cad405912bd24e77d8e25

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e4cbe708c6d17a4fd9a27e99ccf1b15409dd4eac61d6a9e356af1141973974b5
MD5 3c02b7aea963cf0196d6f9d77c0cb867
BLAKE2b-256 8de26aab6a60616f41169aefbfc92a9bca45e1ac684ce5da572a8dc25069d6f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp311-cp311-win_amd64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c15496f38ca516ad789cc02ab81975f18371d4cf95c586e3310f1d9ab91dc859
MD5 5f1b848fc6a164c6f1284df307994651
BLAKE2b-256 9ec52f6ef9a5326abdffdcb866c6100829fcf45d170bd16d760fc585470561c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 4deb0bf989a829dc7bbe13d61b1ae5da1d8466c0fbbc38473c29b3c9ea3c65dc
MD5 ae8dcdb3370a9174d82cd26c6b2bfc84
BLAKE2b-256 2beea610d6db66d866eeeda677a696601509517bde73ff005de0cb7ab8b59434

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on arithy/softfloatpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file softfloatpy-1.2.3.post1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.3.post1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f26cedc3e46f18e137976c7f15a5c6bfb15ecac6612d5d0aee0e4fd51d14310c
MD5 314794b4c8cc61b182b1c8abdd7c0d01
BLAKE2b-256 047601f9286c0a3f1202a8a6917cea38f4f0a20e5941b80e497c018b8dd0188a

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.3.post1-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: release.yml on arithy/softfloatpy

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