{ "info": { "author": "Sebastian Wehrmann", "author_email": "sw@gocept.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "==========\nFixedPoint\n==========\n\nFixedPoint is licensed under ZPL 2.1\n\nCopyright 2007-2008 by gocept gmbh & co. kg\n\n\n\n\n================\nFixedPoint Usage\n================\n\n>>> from gocept.fixedpoint import FixedPoint\n\nFixedPoint objects support decimal arithmetic with a fixed number of\ndigits (called the object's precision) after the decimal point. The\nnumber of digits before the decimal point is variable & unbounded.\n\nThe precision is user-settable on a per-object basis when a FixedPoint\nis constructed, and may vary across FixedPoint objects. The precision\nmay also be changed after construction via FixedPoint.set_precision(p).\nNote that if the precision of a FixedPoint is reduced via set_precision,\ninformation may be lost to rounding.\n\n>>> x = FixedPoint(\"5.55\") # precision defaults to 2\n>>> print x\n5.55\n>>> x.set_precision(1) # round to one fraction digit\n>>> print x\n5.6\n>>> print FixedPoint(\"5.55\", 1) # same thing setting to 1 in constructor\n5.6\n>>> repr(x) # returns constructor string that reproduces object exactly\n\"FixedPoint('5.6', 1)\"\n\nWhen FixedPoint objects of different precision are combined via + - * /,\nthe result is computed to the larger of the inputs' precisions, which also\nbecomes the precision of the resulting FixedPoint object.\n\n>>> print FixedPoint(\"3.42\") + FixedPoint(\"100.005\", 3)\n103.425\n>>> print FixedPoint(\"2.1\") * FixedPoint(\"10.995\", 3)\n23.090\n\nWhen a FixedPoint is combined with other numeric types (ints, floats,\nstrings representing a number) via + - * /, then similarly the computation\nis carried out using-- and the result inherits --the FixedPoint's\nprecision.\n\n>>> print FixedPoint(1) / 7\n0.14\n>>> print FixedPoint(1, 30) / 7\n0.142857142857142857142857142857\n>>>\n\nThe string produced by str(x) (implictly invoked by \"print\") always\ncontains at least one digit before the decimal point, followed by a\ndecimal point, followed by exactly x.get_precision() digits. If x is\nnegative, str(x)[0] == \"-\".\n\n>>> print FixedPoint(\"1.0\", 5)\n1.00000\n>>> print FixedPoint(\"1.234567\", 2)\n1.23\n>>> str(FixedPoint(\"-1.45\"))[0] == \"-\"\nTrue\n\nThe FixedPoint constructor can be passed an int, long, string, float,\nFixedPoint, or any object convertible to a float via float() or to a\nlong via long(). Passing a precision is optional; if specified, the\nprecision must be a non-negative int. There is no inherent limit on\nthe size of the precision, but if very very large you'll probably run\nout of memory.\n\n>>> FixedPoint(\"1.0\", -3) # negative precision values are not allowed\nTraceback (most recent call last):\n...\nValueError: precision must be >= 0: -3\n\nNote that conversion of floats to FixedPoint can be surprising, and\nshould be avoided whenever possible. Conversion from string is exact\n(up to final rounding to the requested precision), so is greatly\npreferred.\n\n>>> print FixedPoint(1.1e30)\n1099999999999999993725589651456.00\n>>> print FixedPoint(\"1.1e30\")\n1100000000000000000000000000000.00\n>>>\n\nThe following Python operators and functions accept FixedPoints in the\nexpected ways:\n\n - binary + - * / % divmod with auto-coercion of other types to\n FixedPoint. + - % divmod of FixedPoints are always exact.* / of\n FixedPoints may lose information to rounding, in which case the\n result is the infinitely precise answer rounded to the result's\n precision.\n - divmod(x, y) returns (q, r) where q is a long equal to\n floor(x/y) as if x/y were computed to infinite precision,\n and r is a FixedPoint equal to x - q * y; no information\n is lost. Note that q has the sign of y, and abs(r) < abs(y).\n - unary -\n - == != < > <= >= cmp\n - min, max\n - float, int, long (int and long truncate)\n - abs\n - str, repr\n - hash\n - use as dict keys\n - use as boolean (e.g. \"if some_FixedPoint:\" -- true iff not zero)\n\nMethods unique to FixedPoints:\n - copy(): return new FixedPoint with same value\n - frac(): long(x) + x.frac() == x\n - get_precision(): return the precision(p) of this FixedPoint object\n - set_precision(p): set the precision of this FixedPoint object\n\n>>> FixedPoint(\"1.0\", 3).copy()\nFixedPoint('1.000', 3)\n>>> FixedPoint(\"1.0\").copy() # default precision is 2\nFixedPoint('1.00', 2)\n\n>>> FixedPoint('123.45').frac()\nFixedPoint('0.45', 2)\n\n>>> FixedPoint('123').get_precision()\n2\n>>> fp = FixedPoint('123')\n>>> fp.set_precision(5)\n>>> fp\nFixedPoint('123.00000', 5)\n\nTesting several operators:\n\n>>> fp = FixedPoint\n>>> o = fp(\"0.1\")\n>>> str(o) == \"0.10\"\nTrue\n>>> t = fp(\"-20e-2\", 5)\n>>> str(t) == \"-0.20000\"\nTrue\n>>> t < o\nTrue\n>>> o > t\nTrue\n>>> min(o, t) == min(t, o) == t\nTrue\n>>> max(o, t) == max(t, o) == o\nTrue\n>>> o != t\nTrue\n>>> --t == t\nTrue\n>>> abs(t) > abs(o)\nTrue\n>>> abs(o) < abs(t)\nTrue\n>>> o == o and t == t\nTrue\n>>> t.copy() == t\nTrue\n>>> o == -t/2 == -.5 * t\nTrue\n>>> abs(t) == o + o\nTrue\n>>> abs(o) == o\nTrue\n>>> o/t == -0.5\nTrue\n>>> -(t/o) == (-t)/o == t/-o == 2\nTrue\n>>> 1 + o == o + 1 == fp(\" +00.000011e+5 \")\nTrue\n>>> 1/o == 10\nTrue\n>>> o + t == t + o == -o\nTrue\n>>> 2.0 * t == t * 2 == \"2\" * t == o/o * 2L * t\nTrue\n>>> 1 - t == -(t - 1) == fp(6L)/5\nTrue\n>>> t*t == 4*o*o == o*4*o == o*o*4\nTrue\n>>> fp(2) - \"1\" == 1\nTrue\n>>> float(-1/t) == 5.0\nTrue\n>>> 1/(42 + fp(\"1e-20\", 20) - 42) == fp(\"100.0E18\")\nTrue\n>>> o = fp(\".9995\", 4)\n>>> 1 - o == fp(\"5e-4\", 10)\nTrue\n>>> o.set_precision(3)\n>>> o == 1\nTrue\n>>> o = fp(\".9985\", 4)\n>>> o.set_precision(3)\n>>> o == fp(\".998\", 10)\nTrue\n>>> o == o.frac()\nTrue\n>>> o.set_precision(100)\n>>> o == fp(\".998\", 10)\nTrue\n>>> o.set_precision(2)\n>>> o == 1\nTrue\n>>> x = fp(1.99)\n>>> long(x) == -long(-x) == 1L\nTrue\n>>> int(x) == -int(-x) == 1\nTrue\n>>> x == long(x) + x.frac()\nTrue\n>>> -x == long(-x) + (-x).frac()\nTrue\n>>> fp(7) % 4 == 7 % fp(4) == 3\nTrue\n>>> fp(-7) % 4 == -7 % fp(4) == 1\nTrue\n>>> fp(-7) % -4 == -7 % fp(-4) == -3\nTrue\n>>> fp(7.0) % \"-4.0\" == 7 % fp(-4) == -1\nTrue\n>>> fp(\"5.5\") % fp(\"1.1\") == fp(\"5.5e100\") % fp(\"1.1e100\") == 0\nTrue\n>>> divmod(fp(\"1e100\"), 3) == (long(fp(\"1e100\")/3), 1)\nTrue\n>>> fp(\"1\") != ''\nTrue\n\n\nChanges\n=======\n\n0.2 (2008-05-26)\n----------------\n\n- moved source to __init__.py to make it more usable\n- updated pypi meta data\n\n0.1 (2007-11-27)\n----------------\n\n- initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.python.org/pypi/gocept.fixedpoint", "keywords": "fixedpoint decimal datatype", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "gocept.fixedpoint", "package_url": "https://pypi.org/project/gocept.fixedpoint/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/gocept.fixedpoint/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://www.python.org/pypi/gocept.fixedpoint" }, "release_url": "https://pypi.org/project/gocept.fixedpoint/0.2/", "requires_dist": null, "requires_python": null, "summary": "Fixedpoint datatype in python.", "version": "0.2" }, "last_serial": 792555, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ded82827a33ba524502feeb2710ab6d2", "sha256": "a5f0981411c349b8db0117b12fa0fc6eebe76dfd783bfef4238a297cdb697d33" }, "downloads": -1, "filename": "gocept.fixedpoint-0.1.tar.gz", "has_sig": false, "md5_digest": "ded82827a33ba524502feeb2710ab6d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10404, "upload_time": "2007-11-27T15:53:50", "url": "https://files.pythonhosted.org/packages/ce/75/f51667fa38986f0a5b23d2ff6dd2be9e33b409e566c09c60dd23bca162b5/gocept.fixedpoint-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "0581f77ad5b30c4a4c76fedd712ad65f", "sha256": "32be6fb8896f281560d0a5bcca4d7dcdfd85831f59b15812c87bffcc3026f637" }, "downloads": -1, "filename": "gocept.fixedpoint-0.2.tar.gz", "has_sig": false, "md5_digest": "0581f77ad5b30c4a4c76fedd712ad65f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12328, "upload_time": "2008-05-26T16:21:32", "url": "https://files.pythonhosted.org/packages/75/12/345b1f5ce238c9a5c60f38b154c0ba35b6923bcfe4dd460cc2d805b42680/gocept.fixedpoint-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0581f77ad5b30c4a4c76fedd712ad65f", "sha256": "32be6fb8896f281560d0a5bcca4d7dcdfd85831f59b15812c87bffcc3026f637" }, "downloads": -1, "filename": "gocept.fixedpoint-0.2.tar.gz", "has_sig": false, "md5_digest": "0581f77ad5b30c4a4c76fedd712ad65f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12328, "upload_time": "2008-05-26T16:21:32", "url": "https://files.pythonhosted.org/packages/75/12/345b1f5ce238c9a5c60f38b154c0ba35b6923bcfe4dd460cc2d805b42680/gocept.fixedpoint-0.2.tar.gz" } ] }