[vtk-developers] Adding IsNan() to vtkMath

Brad King brad.king at kitware.com
Tue Jul 21 09:28:13 EDT 2009


Moreland, Kenneth wrote:
> OK.  That seems like a good idea to me, and pretty close to what I
> figured in the first place.  But that does not look like what the VXL
> example you sent is doing.  In there, it looks like it is only using
> isnan on the Intel and Borland compilers.  On most other it is doing an
> x != x comparison, and as a fallback doing a bit comparison.
> 
> Would it be better for VTK to have a CMake do a TRY_COMPILE on isnan?
>  If that fails, do a TRY_COMPILE on x != x?

I don't know/remember all the details of how/why vnl_math.cxx got to the
current state.  I provided the link as a reference.  Your try-compile
with fallback approach sounds good.

> That said, what is the right way to generate a NaN (or Inf or –Inf) in
> the first place?  I imagine you should get one doing division by zero,
> but would that cause floating exceptions on some platforms?

#include <limits>
...
std::numeric_limits<double>::quiet_NaN()
std::numeric_limits<double>::signaling_NaN()

A quiet NaN silently propagates through expressions, while a
signaling NaN will trigger a floating point exception.

-Brad



More information about the vtk-developers mailing list