{ "info": { "author": "Andrew Barnert", "author_email": "abarnert@yahoo.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3" ], "description": "# floatextras\nExtra functions on the built-in `float` similar to those on `Decimal`.\n\nAPI\n---\n\n >>> from floatextras import *\n >>> f = -123.456\n >>> as_tuple(f)\n\tFloatTuple(sign=1, digits=(1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1), exponent=6)\n >>> sign, digits, exponent = as_tuple(f)\n\t>>> from_tuple((0, digits, exponent+1))\n\t246.912\n >>> next_minus(f)\n\t-123.45600000000002\n >>> next_plus(f)\n\t-123.45599999999999\n >>> next_toward(f, 0)\n\t-123.45599999999999\n\t>>> float_difference(1, next_minus(next_minus(1)))\n\t2\n\t>>> qnan2 = make_nan(2)\n\t>>> isnan(qnan2)\n\tTrue\n\t>>> isqnan(qnan2)\n\tTrue\n\t>>> issnan(qnan2)\n\tFalse\n\t>>> nan_payload(qnan2)\n\t2\n\t>>> isqnan(float('nan'))\n\tTrue\n\t>>> nan_payload(float('nan'))\n\t0\n\nThe functions `as_tuple`, `next_minus`, `next_plus`, and `next_toward`\nhave the same effect as the corresponding methods on\n[`Decimal`][1] objects, but for values of the builtin [`float`][2]\ntype, and `from_tuple` is equivalent to the `Decimal` constructor from \na tuple.\n\n [1]: https://docs.python.org/3/library/decimal.html\n [2]: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex\n\nThe `float_difference` function is an inverse `next_plus`--it tells\nyou how many times you'd need to call `next_plus` on `g` to get `f`.\n\nThe `nan` functions are utility functions to construct and examine NaN\nvalues with specific payloads.\n\nAn optional `direct` argument to most functions can be used to force\nthe module to use [`ctypes`][3] to reinterpret-cast the bits of the\nvalue as stored, instead of encoding it portably using the\n[`struct`][4] module. On almost all platforms, this will give the \nsame results; on platforms that don't natively use [IEEE floats][5], \nor store them in a different byte order than the primary byte order, \nthis will instead give the _wrong_ results (but that may be useful \nto check for while experimenting).\n\n [3]: https://docs.python.org/3/library/ctypes.html\n [4]: https://docs.python.org/3/library/struct.html\n [5]: http://en.wikipedia.org/wiki/IEEE_floating_point\n\nDifferences from Decimal\n------------------------\n\nA fixed-size binary float is of course not identical to an\narbitrary-size decimal float. That means the tuple representation is\nsignificantly different. In particular: \n\n`Decimal` is stored as an integer plus an exponent, with separate\nspecial exponents for infinity, quiet NaN, and signaling NaN (`F`,\n`n`, and `N`, respectively).\n\n`float` is stored as a fraction between 1 and 2, with the leading 1\nimplicit, plus an exponent, with a single special exponent for\ninfinity and both NaNs (1024, which is infinity if all digits are 0,\notherwise NaN, quiet if the first digit is 1) and another one for zero\nand denormal values (-1023, which is treated as -1022 but without the\nimplicit leading 1 on the fraction).\n\nThe differences are easier to see through experimentation than\nexplanation (which is partly why this module exists).\n\nMotivation\n----------\n\nPython's `Decimal` type represents an IEEE 854-1987 decimal float, and \nit comes with a number of handy operations for exploring the details of \nthat representation, like the [`next_plus`][6] family and \n[`as_tuple`][6]. And sometimes these operations are useful beyond \nexploration\u2014e.g., to test whether the result of an algorithm is within \n1 ulp of the expected result.\n\n [6]: https://docs.python.org/3/library/decimal.html#decimal.Decimal.next_plus\n [7]: https://docs.python.org/3/library/decimal.html#decimal.Decimal.as_tuple\n\nHowever, while the built-in `float` type nearly always represents\nan IEEE 754-1985 binary float, for which the same operations would be\nhandy, they aren't included.\n\nOf course it's possible to get the bits of a `float` and operator on\nthem manually, as explained in [IEEE Floats and Python][8], it isn't\nnearly as convenient.\n\n [8]: http://stupidpythonideas.blogspot.com/2015/01/ieee-floats-and-python.html\n\nSo, this module provides similar functions for `float`.", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/abarnert/floatextras", "keywords": "float", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "floatextras", "package_url": "https://pypi.org/project/floatextras/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/floatextras/", "project_urls": { "Homepage": "https://github.com/abarnert/floatextras" }, "release_url": "https://pypi.org/project/floatextras/0.0.3/", "requires_dist": null, "requires_python": null, "summary": "Extra functions on the built-in `float` similar to those on `Decimal`.", "version": "0.0.3" }, "last_serial": 1388678, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "497dc89648d4c18c863ac069a5e96570", "sha256": "eb52604f6bcba9648da2332d8b7a8628ffa8b3755fbc18da07fe3a9134074bd0" }, "downloads": -1, "filename": "floatextras-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "497dc89648d4c18c863ac069a5e96570", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6117, "upload_time": "2015-01-20T00:36:07", "url": "https://files.pythonhosted.org/packages/8e/b8/94e1f4c68ca8183a12798d7b346b09b5e1959478258fb91441122dd707a0/floatextras-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ece591259aa013d6f4a98eecbcec6bfb", "sha256": "ab8ddcf09750660f42d7219f6949140f503677a808a45520092da853578907fa" }, "downloads": -1, "filename": "floatextras-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ece591259aa013d6f4a98eecbcec6bfb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6112, "upload_time": "2015-01-20T00:36:11", "url": "https://files.pythonhosted.org/packages/cf/a0/dcea6821fd03e5ac89f48533eb1398087605f78e89310ec21308a316fcfe/floatextras-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0cfa25f067c2775a525451c3cf2e5c19", "sha256": "b146fd286b08863bbdb8fc357bc19b441691283e9cc73ee9969fd47b2d9a777a" }, "downloads": -1, "filename": "floatextras-0.0.1.tar.gz", "has_sig": false, "md5_digest": "0cfa25f067c2775a525451c3cf2e5c19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3950, "upload_time": "2015-01-20T00:36:13", "url": "https://files.pythonhosted.org/packages/08/ae/e3e782dbb30d2d529dd2a6f23a73afea026fde37195ecd627008480cef96/floatextras-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "990294f109c4aed2b55b0281916bfa1b", "sha256": "8c651c7ced78dc624821fb790476de5645eb5d9653f7b1585473ff4881c1f0b8" }, "downloads": -1, "filename": "floatextras-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "990294f109c4aed2b55b0281916bfa1b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6112, "upload_time": "2015-01-20T00:37:31", "url": "https://files.pythonhosted.org/packages/9b/05/7e92563f058260854920ff65d4944108bd7b9d798019e7a4e4f816b851d3/floatextras-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "910f2c0297f814b3fde60d890575d8e2", "sha256": "baea5fc93363be050c35d34153284db5cff661cccb7be8d401a45e10132ac842" }, "downloads": -1, "filename": "floatextras-0.0.2.tar.gz", "has_sig": false, "md5_digest": "910f2c0297f814b3fde60d890575d8e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3953, "upload_time": "2015-01-20T00:37:34", "url": "https://files.pythonhosted.org/packages/c2/85/feda7872a25984ad53c8d1752b68c38691ed6c5746a919bcec0e2e208cbc/floatextras-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "7fc09bcdb8efba912206b8154d68c8dd", "sha256": "49a68e49178d892eeec255c0e4a1194494389b158187ba26c76c5d37b21a51ed" }, "downloads": -1, "filename": "floatextras-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "7fc09bcdb8efba912206b8154d68c8dd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7879, "upload_time": "2015-01-20T03:09:05", "url": "https://files.pythonhosted.org/packages/7d/37/128617423107a0b47973692003627ddb4d0a3d16bd2d4043db3992bdc603/floatextras-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c1ce727aeb31bd08cc9e0bec1dd3ce7d", "sha256": "3b7edfeba8cf5f0d6d0b1acaaedb14b31be050ab2f7319ff5854e48a1220d44f" }, "downloads": -1, "filename": "floatextras-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c1ce727aeb31bd08cc9e0bec1dd3ce7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4916, "upload_time": "2015-01-20T03:09:07", "url": "https://files.pythonhosted.org/packages/b0/a2/12a6dd0418a708535ff114ed1611f15e4bcc78da37997912a86c76bfcdac/floatextras-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7fc09bcdb8efba912206b8154d68c8dd", "sha256": "49a68e49178d892eeec255c0e4a1194494389b158187ba26c76c5d37b21a51ed" }, "downloads": -1, "filename": "floatextras-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "7fc09bcdb8efba912206b8154d68c8dd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7879, "upload_time": "2015-01-20T03:09:05", "url": "https://files.pythonhosted.org/packages/7d/37/128617423107a0b47973692003627ddb4d0a3d16bd2d4043db3992bdc603/floatextras-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c1ce727aeb31bd08cc9e0bec1dd3ce7d", "sha256": "3b7edfeba8cf5f0d6d0b1acaaedb14b31be050ab2f7319ff5854e48a1220d44f" }, "downloads": -1, "filename": "floatextras-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c1ce727aeb31bd08cc9e0bec1dd3ce7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4916, "upload_time": "2015-01-20T03:09:07", "url": "https://files.pythonhosted.org/packages/b0/a2/12a6dd0418a708535ff114ed1611f15e4bcc78da37997912a86c76bfcdac/floatextras-0.0.3.tar.gz" } ] }