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.

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.2.tar.gz (518.3 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.2-cp313-cp313-win_amd64.whl (300.3 kB view details)

Uploaded CPython 3.13Windows x86-64

softfloatpy-1.2.2-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.2-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.2-cp313-cp313-macosx_10_13_universal2.whl (753.6 kB view details)

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

softfloatpy-1.2.2-cp312-cp312-win_amd64.whl (296.4 kB view details)

Uploaded CPython 3.12Windows x86-64

softfloatpy-1.2.2-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.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

softfloatpy-1.2.2-cp312-cp312-macosx_10_13_universal2.whl (756.3 kB view details)

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

softfloatpy-1.2.2-cp311-cp311-win_amd64.whl (305.5 kB view details)

Uploaded CPython 3.11Windows x86-64

softfloatpy-1.2.2-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.2-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.2-cp311-cp311-macosx_10_9_universal2.whl (772.3 kB view details)

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

File details

Details for the file softfloatpy-1.2.2.tar.gz.

File metadata

  • Download URL: softfloatpy-1.2.2.tar.gz
  • Upload date:
  • Size: 518.3 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.2.tar.gz
Algorithm Hash digest
SHA256 b098be0de209102a5771d94bbb303a95f455d861a64739df6205594865750958
MD5 41a4ab7fd86294edc22ef725f9129822
BLAKE2b-256 41face1389efc01518a049ea434bd8b8008d101f299b9d4a178daf950e610472

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2.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.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9250c1934ac7bd326b670149cb89dfb7ea110cd392898b904da089530a4ecefd
MD5 00052cc48654f1517e684e3d088d6a18
BLAKE2b-256 2355b659931b9ff12f56e6df833e66d2c55489ea15d431571c932cafcb9cbe45

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 4f0f728ead201ce82e8bdb7a4b4d6f037594d7bd9acfde5263d0dee205108679
MD5 86b755807911c3c4c86e1ea0cad30bf2
BLAKE2b-256 afc82562eb3ad42058fb17d9aadf090e681fc27bb6f70e0a06b65b5f14e6a925

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 6ae1a6b08ed0b9c5bb5785be1c0115380679a4c7348d6fc28d12c13a24b8f8fc
MD5 68e891482f45150802fd41c70dea9a06
BLAKE2b-256 afe05604750516f926b233e94695c30c303670f128faea967e3451b441607ea9

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 01448025572bf9930edea014e7069d183b1cd7a1e92fe6800c2c573b0dc886ea
MD5 64707dd10e95727e9f67b1edc9122b46
BLAKE2b-256 c7796447d24afba48a6e96fc759ddc429c20e1938c3c8ba60b7d823cc77b28a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 befd3cce640415952d18d6d8edda5b4394525de9393480828743c950d794ed4d
MD5 b256593ab02760180b6b6342dfa181f0
BLAKE2b-256 e7b8212100456ac6a01ad0294503052b8b40c1770c7b91958e35426d66b70286

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 ee7fe63496b6c6cb93b635e78776e80ddedeb1bd26df66a41d764287b923b79e
MD5 1ccb1f751c60f05637292b430954d081
BLAKE2b-256 7abec74149e974da7a02021891a0795acdf9c12e4fa3879d1b74b5c70c05834e

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f70e16eae640b6c52cd174d358d67c6c6854841a73f223a7c39ec36f43d2e98d
MD5 9727f253144936630e38acbbdce81e60
BLAKE2b-256 ff04cf43917bbbb75d23002aaff23c7ff02b6f52f50d018abf764e20cd52cdfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 d95771dda4e65ba781e3db79c1c0b2b970ee1845985fd313bc8265bfc6520e8e
MD5 aeca75b05a544dec410fb75a4aa7c8a8
BLAKE2b-256 85add4883d6a41e809a5b1f72722d3df348a025acd5af7c1774134ab8e4e345f

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b5c66357a8b25606d80b265a2c845df0583e55457d533e92a7fe79c81bd0b616
MD5 8e0ee6e52f43079bb37e2aea9d2e5b05
BLAKE2b-256 99c3bfd6b88b54a44b40f67ef0649659fc3fbe9ae262f8de443b2298b1390599

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c5225fa338401ece5d94a9018be02f1564c7a878d76a6e990c8d2bd80cd625bf
MD5 fbd5747a226a27c9df8abbdd10288eff
BLAKE2b-256 705fd0f58177273c2c2d3b631f3573fde268ced05cb1ce25a2b12b55c53ac5b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 11dcda231d22fae6393141c304d37ef6f2aea6411b21629cf58311f2022dab1e
MD5 37d4b2fc8a1fae7ee4bc4b9f02c17781
BLAKE2b-256 a81678f53e5845600dfd35761dde402ba954353c3ed65103d4e99790ce12f0a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for softfloatpy-1.2.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3a7f813618dd442210a61b3a7daa682bb1b64f0446629f4137bc78dc2e21d3d5
MD5 1aa682a5ef3a7556bf28e2c278f85cf3
BLAKE2b-256 c7484a6b3402e3766576c23e502ac390f00c1ce869eae68895e63175b51c7834

See more details on using hashes here.

Provenance

The following attestation bundles were made for softfloatpy-1.2.2-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