[Numpy-discussion] double-precision sqrt?

Nadav Horesh nadavh@visionsense....
Sat Oct 17 13:27:02 CDT 2009

```The default precision is double unless yue specify otherwise (float32 or long double (float128 or float96))

You can see this from:

f(fsolve(f,1.01))
# 1.7763568394002505e-15

The last line should be:

>>> fsolve(f,1.01) - float64(1.034324523462345)
8.8817841970012523e-16

Nadav

-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Adam Ginsburg
נשלח: ש 17-אוקטובר-09 20:08
אל: numpy-discussion@scipy.org
נושא: [Numpy-discussion] double-precision sqrt?

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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3358 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091017/9d7fd8e8/attachment.bin
```

More information about the NumPy-Discussion mailing list