[Numpy-discussion] double-precision sqrt?

Anne Archibald peridot.faceted at gmail.com
Sat Oct 17 14:37:18 EDT 2009


2009/10/17 Adam Ginsburg <adam.ginsburg at colorado.edu>:
> My code is actually wrong.... but I still have the problem I've
> identified that sqrt is leading to precision errors.  Sorry about the
> earlier mistake.

I think you'll find that numpy's sqrt is as good as it gets for double
precision. You can try using numpy's float96 type, which at least on
my machine, does give sa few more significant figures. If you really,
really need accuracy, there are arbitrary-precision packages for
python, which you could try.

But I think you may find that your problem is not solved by higher
precision. Something about ray-tracing just leads it to ferret out
every little limitation of floating-point computation. For example,
you can easily get "surface acne" when shooting shadow rays, where a
ray shot from a surface to a light source accidentally intersects that
same surface for some pixels but not for others. You can try to fix it
by requiring some minimum intersection distance, but then you'll find
lots of weird little quirks where your minimum distance causes
problems. A better solution is one which takes into account the
awkwardness of floating-point; for this particular case one trick is
to mark the object you're shooting rays from as not a candidate for
intersection. (This doesn't work, of course, if the object can cast
shadows on itself...) I have even seen people advocate for using
interval analysis inside ray tracers, to avoid this kind of problem.

Anne



More information about the NumPy-Discussion mailing list