STINNER Victor added the comment:
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
----------
nosy: +haypo
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue31157>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com