This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mick Press, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2017-08-09.09:58:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502272722.9.0.472366433672.issue31157@psf.upfronthosting.co.za>
In-reply-to
Content
The math module uses the float type which has a limited precision: it's 64-bit IEEE.

For better precision, you can use the decimal module which has configurable precision.

Example:
---
import decimal

decimal.getcontext().prec = 5
root = decimal.Decimal('123').sqrt()
print(root)

decimal.getcontext().prec = 50
root = decimal.Decimal('123').sqrt()
print(root)
---

Output:
---
11.091
11.090536506409417162051600102609932918463376742454
---

Said differently: the behaviour that you noticed is not a bug, but a known limitation of Python, of the Python float type to be exact.

https://docs.python.org/3/tutorial/floatingpoint.html
History
Date User Action Args
2017-08-09 09:58:42vstinnersetrecipients: + vstinner, paul.moore, tim.golden, zach.ware, steve.dower, Mick Press
2017-08-09 09:58:42vstinnersetmessageid: <1502272722.9.0.472366433672.issue31157@psf.upfronthosting.co.za>
2017-08-09 09:58:42vstinnerlinkissue31157 messages
2017-08-09 09:58:42vstinnercreate