{"id":18613907,"url":"https://github.com/enthought/ibm2ieee","last_synced_at":"2025-04-10T23:32:10.658Z","repository":{"id":55103023,"uuid":"157259450","full_name":"enthought/ibm2ieee","owner":"enthought","description":"NumPy ufuncs for converting IBM-format hexadecimal floating-point to IEEE 754-format binary floating-point.","archived":false,"fork":false,"pushed_at":"2023-10-08T08:52:28.000Z","size":105,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":23,"default_branch":"main","last_synced_at":"2025-03-25T06:51:12.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enthought.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T18:40:55.000Z","updated_at":"2022-12-16T05:13:16.000Z","dependencies_parsed_at":"2024-06-19T22:50:34.658Z","dependency_job_id":"f9992737-7010-4686-894b-37dd13d0099a","html_url":"https://github.com/enthought/ibm2ieee","commit_stats":{"total_commits":85,"total_committers":2,"mean_commits":42.5,"dds":0.07058823529411762,"last_synced_commit":"c3644a4227971e1b6a5ff81bad1910fb1b819e50"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fibm2ieee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fibm2ieee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fibm2ieee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enthought%2Fibm2ieee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enthought","download_url":"https://codeload.github.com/enthought/ibm2ieee/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248316485,"owners_count":21083453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T03:24:17.218Z","updated_at":"2025-04-10T23:32:10.315Z","avatar_url":"https://github.com/enthought.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"The **ibm2ieee** package provides NumPy universal functions (\"ufuncs\") for\nconverting IBM single-precision and double-precision hexadecimal floats\nto the IEEE 754-format floats used by Python and NumPy on almost all\ncurrent platforms.\n\n\nFeatures\n--------\n\n- Fast: 200-400 million values converted per second on a typical modern\n  machine, assuming normal inputs.\n- Correct: converted results are correctly rounded, according to the default\n  IEEE 754 round-ties-to-even rounding mode. Corner cases (overflow, underflow,\n  subnormal results, signed zeros, non-normalised input) are all handled\n  correctly. Where the rounded converted value is out of range for the target\n  type, an appropriately-signed infinity is returned.\n- Handles both single-precision and double-precision input and output formats.\n\nPortability note: the conversion functions provided in this module assume that\n``numpy.float32`` and ``numpy.float64`` are based on the standard IEEE 754\nbinary32 and binary64 floating-point formats. This is true on the overwhelming\nmajority of current platforms, but is not guaranteed by the relevant language\nstandards.\n\n\nUsage\n-----\n\nThe package provides two functions:\n\n- ``ibm2float32`` converts IBM single- or double-precision data to\n  IEEE 754 single-precision values, in ``numpy.float32`` format.\n\n- ``ibm2float64`` converts IBM single- or double-precision data to\n  IEEE 754 double-precision values, in ``numpy.float64`` format.\n\nFor both functions, IBM single-precision input data must be represented\nusing the ``numpy.uint32`` dtype, while IBM double-precision inputs must\nbe represented using ``numpy.uint64``.\n\nBoth functions assume that the IBM data have been converted to NumPy integer\nformat in such a way that the most significant bits of the floating-point\nnumber become the most significant bits of the integer values. So when decoding\nbyte data representing IBM hexadecimal floating-point numbers, it's important\nto take the endianness of the byte data into account. See the Examples section\nbelow for an example of converting big-endian byte data.\n\n\nExamples\n--------\n\n\u003e\u003e\u003e import numpy\n\u003e\u003e\u003e from ibm2ieee import ibm2float32, ibm2float64\n\u003e\u003e\u003e ibm2float32(numpy.uint32(0xc1180000))\n-1.5\n\u003e\u003e\u003e type(ibm2float32(numpy.uint32(0xc1180000)))\n\u003cclass 'numpy.float32'\u003e\n\u003e\u003e\u003e ibm2float32(numpy.uint64(0x413243f6a8885a31))\n3.1415927\n\u003e\u003e\u003e ibm2float32(numpy.uint32(0x61100000))\ninf\n\u003e\u003e\u003e ibm2float64(numpy.uint32(0xc1180000))\n-1.5\n\u003e\u003e\u003e ibm2float64(numpy.uint64(0x413243f6a8885a31))\n3.141592653589793\n\u003e\u003e\u003e ibm2float64(numpy.uint32(0x61100000))\n3.402823669209385e+38\n\u003e\u003e\u003e input_array = numpy.arange(\n        0x40fffffe, 0x41000002, dtype=numpy.uint32).reshape(2, 2)\n\u003e\u003e\u003e input_array\narray([[1090519038, 1090519039],\n       [1090519040, 1090519041]], dtype=uint32)\n\u003e\u003e\u003e ibm2float64(input_array)\narray([[9.99999881e-01, 9.99999940e-01],\n       [0.00000000e+00, 9.53674316e-07]])\n\nWhen converting byte data read from a file, it's important to know the\nendianness of that data (which is frequently big-endian in historical data\nfiles using IBM hex floating-point). Here's an example of converting IBM\nsingle-precision data stored in big-endian form to ``numpy.float32``. Note the\nuse of the ``'\u003eu4'`` dtype when converting the bytestring to a NumPy ``uint32``\narray. For little-endian input data, you would use ``'\u003cu4'`` instead.\n\n\u003e\u003e\u003e input_data = b'\\xc12C\\xf7\\xc1\\x19!\\xfb\\x00\\x00\\x00\\x00A\\x19!\\xfbA2C\\xf7'\n\u003e\u003e\u003e input_as_uint32 = numpy.frombuffer(input_data, dtype='\u003eu4')\n\u003e\u003e\u003e input_as_uint32\narray([3241296887, 3239649787,          0, 1092166139, 1093813239],\n      dtype=uint32)\n\u003e\u003e\u003e ibm2float32(input_as_uint32)\narray([-3.141593, -1.570796,  0.      ,  1.570796,  3.141593],\n      dtype=float32)\n\n\nNotes on the formats\n--------------------\n\nThe IBM single-precision format has a precision of 6 hexadecimal digits, which\nin practice translates to a precision of 21-24 bits, depending on the binade\nthat the relevant value belongs to. IEEE 754 single-precision has a precision\nof 24 bits. So all not-too-small, not-too-large IBM single-precision values can\nbe translated to IEEE 754 single-precision values with no loss of precision.\nHowever, the IBM single precision range is larger than the corresponding IEEE\n754 range, so extreme IBM single-precision values may overflow to infinity,\nunderflow to zero, or be rounded to a subnormal value when converted to IEEE\n754 single-precision.\n\nFor double-precision conversions, the tradeoff works the other way: the IBM\ndouble-precision format has an effective precision of 53-56 bits, while IEEE\n754 double-precision has 53-bit precision. So most IBM values will be rounded\nwhen converted to IEEE 754. However, the IEEE 754 double-precision range is\nlarger than that of IBM double-precision, so there's no danger of overflow,\nunderflow, or reduced-precision subnormal results when converting IBM\ndouble-precision to IEEE 754 double-precision.\n\nEvery IBM single-precision value can be exactly represented in IEEE 754\ndouble-precision, so if you want a lossless representation of IBM\nsingle-precision data, use ``ibm2float64``.\n\nNote that the IBM formats do not allow representations of special values like\ninfinities and NaNs. However, signed zeros are representable, and the sign of a\nzero is preserved under all conversions.\n\n\nInstallation\n------------\n\nThe latest release of ibm2ieee is available from the Python Package Index, at\nhttps://pypi.org/project/ibm2ieee. It can be installed with ``pip`` in the\nusual way::\n\n    pip install ibm2ieee\n\nWheels are provided for common platforms and Python versions. If installing\nfrom source, note that ibm2ieee includes a C extension, so you'll need the\nappropriate compiler on your system to be able to install.\n\nibm2ieee requires Python \u003e= 3.7.\n\n\nLicense\n-------\n\n(C) Copyright 2018-2023 Enthought, Inc., Austin, TX\nAll rights reserved.\n\nThis software is provided without warranty under the terms of the BSD\nlicense included in LICENSE.txt and may be redistributed only under\nthe conditions described in the aforementioned license. The license\nis also available online at http://www.enthought.com/licenses/BSD.txt\n\nThanks for using Enthought open source!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenthought%2Fibm2ieee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenthought%2Fibm2ieee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenthought%2Fibm2ieee/lists"}