[vtk-developers] Adding IsNan() to vtkMath

Moreland, Kenneth kmorel at sandia.gov
Tue Jul 21 09:19:32 EDT 2009


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?

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?

-Ken


On 7/21/09 6:16 AM, "Brad King" <brad.king at kitware.com> wrote:

Moreland, Kenneth wrote:
> The source code you sent has as one of its cases a check of the bits of
> an IEEE-754 number.  I see that vtkMath already has a Nan function that
> returns an IEEE NaN.  If VTK is only supporting IEEE-754 in the first
> place, is there any problem with just performing the bit check?

We likely only support IEEE-754, but only by accident.  New code should
be as generic as possible.  Calling the native isnan() is the documented
way to perform this test in C and C++.

-Brad




   ****      Kenneth Moreland
    ***      Sandia National Laboratories
***********
*** *** ***  email: kmorel at sandia.gov
**  ***  **  phone: (505) 844-8919
    ***      web:   http://www.cs.unm.edu/~kmorel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20090721/7903b78f/attachment.html>


More information about the vtk-developers mailing list