Skip to main content

Portable Floating Point Decomposition

Project description

https://img.shields.io/pypi/v/defloat.svg https://img.shields.io/pypi/l/defloat https://img.shields.io/pypi/pyversions/defloat.svg

DeFloat

Floating Point Decomposition

A small implementation of a portable floating point format (i.e. with no loss of precision across floating point implementations).

Examples

Object-Oriented style:

if __name__ == '__main__':
        from defloat import DeFloat

        a = 5.32515
        b = b_z, b_e = DeFloat.decomp(a)
        c = float(b)  # 1 way to do it
        d = b.recomp()  # the other way to do it

        print(f"decomposition:   fraction={b_z}, exponent={b_e}")
        print(f"recomposition 1: {c}")
        print(f"recomposition 2: {d}")
        print(f"check:           {a}")

        assert c == d == a

        """
        expected output:
                decomposition:   fraction=5995585888922999, exponent=3
                recomposition 1: 5.32515
                recomposition 2: 5.32515
                check:           5.32515
        """

Procedural style:

if __name__ == '__main__':
        import defloat

        a = 5.32515
        b_z, b_e = defloat.decomp(a)
        c = defloat.recomp(b_z, b_e)

        print(f"decomposition: fraction={b_z}, exponent={b_e}")
        print(f"recomposition: {c}")
        print(f"check:         {a}")

        assert c == a

        """
        expected output:
                decomposition: fraction=5995585888922999, exponent=3
                recomposition: 5.32515
                check:         5.32515
        """

Notes

Recomposition on hardware with lower precision may/will result in data/precision loss. Precision is only guaranteed within the decomposed format, and recomposition to the same implementation as decomposed from.

License

DeFloat is licensed under Mozilla Public License.

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

defloat-0.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

DeFloat-0.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file defloat-0.0.1.tar.gz.

File metadata

  • Download URL: defloat-0.0.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for defloat-0.0.1.tar.gz
Algorithm Hash digest
SHA256 db7c5a544299f35d475f2081cf7d81cb88da4425484097b81eac3453eef51f39
MD5 0afeaad3b3dfc402c51b3d9a14b90348
BLAKE2b-256 04955000d767111e44cee0e247cb25699eb9eeabc45809e8f40c1135d4383be9

See more details on using hashes here.

File details

Details for the file DeFloat-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: DeFloat-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for DeFloat-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a618a332e22eb016ceb67af725c728520a41ee339143cfdf4e5c08b260e31b96
MD5 1b7f1d314cc5be17b700d892100b6e87
BLAKE2b-256 8bfa66f7d7fcde89af9dbbcbced947a3020a6d44839dd83ed97b17a781c05c77

See more details on using hashes here.

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