Python math.sqrt loss precision
python
Solution
>>> import decimal
>>> decimal.getcontext().prec = 100
>>> a=decimal.Decimal(410241186411534352)**decimal.Decimal(.5)
>>> print a
640500730.9999999929742468943411712910588335443486974564849183256021518032770726219326459594197730639
>>> print a*a
410241186411534352.0000000000000000000000000000000000000000000000000000000000000000000000000000000000
>>>
Problem
I tried to get sqrt value of a long int ``` from math import sqrt print sqrt(410241186411534352) << 640500731.0 ``` It returned 640500731.0, which indeed is 640500730.999999993... in precision. How to fix that? I solved it according to @DSM and @Rob's reply, thank you so much. ``` from math import sqrt from decimal import Decimal print Decimal(410241186411534352).sqrt() ```