# ieee754
ieee754 is a Python module which finds the IEEE-754 representation of a floating point number. You can specify a precision given in the list below or you can even use your own custom precision.
<ul>
<li>Half Precision (16 bit: 1 bit for sign + 5 bits for exponent + 10 bits for mantissa)</li>
<li>Single Precision (32 bit: 1 bit for sign + 8 bits for exponent + 23 bits for mantissa)</li>
<li>Double Precision (64 bit: 1 bit for sign + 11 bits for exponent + 52 bits for mantissa)</li>
<li>Quadruple Precision (128 bit: 1 bit for sign + 15 bits for exponent + 112 bits for mantissa)</li>
<li>Octuple Precision (256 bit: 1 bit for sign + 19 bits for exponent + 236 bits for mantissa)</li>
</ul>
## Prerequisites
ieee754 does not require any external libraries or modules.
## Installing
To download ieee754, either fork this github repo or simply use Pypi via pip.
```sh
$ pip install ieee754
```
## Using
After installation, you can import ieee754 and use it in your projects.
### Simplest Example
The simplest example is to use the desired precision IEEE-754 representation of a floating point number. You can import the desired precision from ieee754 and use it like this. The available precisions are `half`, `single`, `double`, `quadruple` and `octuple`.
```Python
from ieee754 import double
print(double(13.375))
```
### Default Options
Default precision is Double Precision and you can get the output by just calling the instance as a string.
```Python
from ieee754 import IEEE754
x = 13.375
a = IEEE754(x)
# you should call the instance as a string
print(a)
print(str(a))
print(f"{a}")
# you can get the hexadecimal presentation like this
print(a.hex())
# you can get more detailed information like this
print(a.json())
```
### Select a Precision
You can use Half (p=0), Single (p=1), Double (p=2), Quadrupole (p=3) or Octuple precision (p=4).
```Python
from ieee754 import IEEE754
for p in range(5):
a = IEEE754(x, p)
print("x = %f | b = %s | h = %s" % (13.375, a, a.hex()))
```
### Use the Precision Name as an Interface
You can use the precision name as an interface to get the IEEE-754 representation of a floating point number. With this method you can get the IEEE-754 representation of a floating point number without creating an instance.
```Python
from ieee754 import half, single, double, quadruple, octuple
x = 13.375
print(half(x))
print(single(x))
print(double(x))
print(quadruple(x))
print(octuple(x))
```
### Using a Custom Precision
You can force exponent, and mantissa size by using `force_exponent` and `force_mantissa` parameters to create your own custom precision.
```Python
a = IEEE754(x, force_exponent=6, force_mantissa=12)
print(a)
```
### Finding the Error of a Floating Point Number
You can find the error of a floating point number by using the `converted_number` and `error` properties of the class.
```Python
x = 8.7
a = IEEE754(x, 1)
print(f"{x} is converted as {a.converted_number} ± {a.error}")
```
License
----
MIT License
Copyright (c) 2021 Bora Canbula
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Raw data
{
"_id": null,
"home_page": "https://github.com/canbula/ieee754",
"name": "ieee754",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "IEEE-754,precisions,double-precision,binary,floating-points,binary-representation",
"author": "Bora Canbula",
"author_email": "bora.canbula@cbu.edu.tr",
"download_url": "https://files.pythonhosted.org/packages/72/72/f552b3c2834967e5501f164a08356918bb4eede31ec845877cdc3a370e73/ieee754-0.10.tar.gz",
"platform": null,
"description": "# ieee754\n\nieee754 is a Python module which finds the IEEE-754 representation of a floating point number. You can specify a precision given in the list below or you can even use your own custom precision.\n<ul>\n <li>Half Precision (16 bit: 1 bit for sign + 5 bits for exponent + 10 bits for mantissa)</li>\n <li>Single Precision (32 bit: 1 bit for sign + 8 bits for exponent + 23 bits for mantissa)</li>\n <li>Double Precision (64 bit: 1 bit for sign + 11 bits for exponent + 52 bits for mantissa)</li>\n <li>Quadruple Precision (128 bit: 1 bit for sign + 15 bits for exponent + 112 bits for mantissa)</li>\n <li>Octuple Precision (256 bit: 1 bit for sign + 19 bits for exponent + 236 bits for mantissa)</li>\n</ul>\n\n## Prerequisites\n\nieee754 does not require any external libraries or modules.\n\n## Installing\n\nTo download ieee754, either fork this github repo or simply use Pypi via pip.\n```sh\n$ pip install ieee754\n```\n\n## Using\n\nAfter installation, you can import ieee754 and use it in your projects.\n\n### Simplest Example\n\nThe simplest example is to use the desired precision IEEE-754 representation of a floating point number. You can import the desired precision from ieee754 and use it like this. The available precisions are `half`, `single`, `double`, `quadruple` and `octuple`.\n```Python\nfrom ieee754 import double\n\nprint(double(13.375))\n```\n\n### Default Options\n\nDefault precision is Double Precision and you can get the output by just calling the instance as a string.\n```Python\nfrom ieee754 import IEEE754\n\nx = 13.375\na = IEEE754(x)\n# you should call the instance as a string\nprint(a)\nprint(str(a))\nprint(f\"{a}\")\n# you can get the hexadecimal presentation like this\nprint(a.hex())\n# you can get more detailed information like this\nprint(a.json())\n```\n\n### Select a Precision\n\nYou can use Half (p=0), Single (p=1), Double (p=2), Quadrupole (p=3) or Octuple precision (p=4).\n```Python\nfrom ieee754 import IEEE754\n\nfor p in range(5):\n a = IEEE754(x, p)\n print(\"x = %f | b = %s | h = %s\" % (13.375, a, a.hex()))\n```\n\n### Use the Precision Name as an Interface\n\nYou can use the precision name as an interface to get the IEEE-754 representation of a floating point number. With this method you can get the IEEE-754 representation of a floating point number without creating an instance.\n```Python\nfrom ieee754 import half, single, double, quadruple, octuple\n\nx = 13.375\nprint(half(x))\nprint(single(x))\nprint(double(x))\nprint(quadruple(x))\nprint(octuple(x))\n```\n\n### Using a Custom Precision\n\nYou can force exponent, and mantissa size by using `force_exponent` and `force_mantissa` parameters to create your own custom precision.\n```Python\na = IEEE754(x, force_exponent=6, force_mantissa=12)\nprint(a)\n```\n\n### Finding the Error of a Floating Point Number\n\nYou can find the error of a floating point number by using the `converted_number` and `error` properties of the class.\n```Python\nx = 8.7\na = IEEE754(x, 1)\nprint(f\"{x} is converted as {a.converted_number} \u00b1 {a.error}\")\n```\n\n\n\nLicense\n----\n\nMIT License\n\nCopyright (c) 2021 Bora Canbula\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python module which converts floating points numbers into IEEE-754 representation.",
"version": "0.10",
"project_urls": {
"Download": "https://github.com/canbula/ieee754/archive/refs/tags/v_010.tar.gz",
"Homepage": "https://github.com/canbula/ieee754"
},
"split_keywords": [
"ieee-754",
"precisions",
"double-precision",
"binary",
"floating-points",
"binary-representation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7272f552b3c2834967e5501f164a08356918bb4eede31ec845877cdc3a370e73",
"md5": "9b5707cf722ae7ddf8254460670531e7",
"sha256": "95c698fb4c43c2f00c7006a0133cb28d62d611e32882f870c8bf8ce589f47717"
},
"downloads": -1,
"filename": "ieee754-0.10.tar.gz",
"has_sig": false,
"md5_digest": "9b5707cf722ae7ddf8254460670531e7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7248,
"upload_time": "2023-11-24T11:52:25",
"upload_time_iso_8601": "2023-11-24T11:52:25.184287Z",
"url": "https://files.pythonhosted.org/packages/72/72/f552b3c2834967e5501f164a08356918bb4eede31ec845877cdc3a370e73/ieee754-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-24 11:52:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "canbula",
"github_project": "ieee754",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ieee754"
}