[Numpy-discussion] double-precision sqrt?
Adam Ginsburg
adam.ginsburg@colorado....
Sat Oct 17 13:08:18 CDT 2009
Hi folks,
I'm trying to write a ray-tracing code for which high precision is
required. I also "need" to use square roots. However, math.sqrt and
numpy.sqrt seem to only use single-precision floats. Is there a
simple way to make sqrt use higher precision? Alternately, am I
simply being obtuse?
Thanks,
Adam
Example code:
from scipy.optimize.minpack import fsolve
from numpy import sqrt
sqrt(float64(1.034324523462345))
# 1.0170174646791199
f=lambda x: x**2-float64(1.034324523462345)**2
f(sqrt(float64(1.034324523462345)))
# -0.03550269637326231
fsolve(f,1.01)
# 1.0343245234623459
f(fsolve(f,1.01))
# 1.7763568394002505e-15
fsolve(f,1.01) - sqrt(float64(1.034324523462345))
# 0.017307058783226026
More information about the NumPy-Discussion
mailing list