[vtk-developers] isnan

Brad King brad.king at kitware.com
Tue Jan 16 10:38:36 EST 2007


Thompson, David C wrote:
>>>> In the mean time, how about the question of where to put
>>>> the actual isnan function in VTK, hopefully in a way that
>>>> introduces as little overhead as possible? Is vtkstd::isnan()
>>>> the right place (since that's analogous to std::isnan() )?
>>> Note that vtkMath already has static member functions
>>> Inf(), NegInf(), and Nan() that return constants.
>>
>> Honestly, I missed those because I was looking for the test.
>> However, I think you really need the isnan() test too.
> 
> I was not trying to suggest otherwise; I just wanted to
> keep the API consistent.
> 
>> ...
>> I believe ITK supports isnan(), but I didn't really
>> follow the discussing thread about it except to get
>> it running on the Mac.  Is there a difference in ITK
>> and VTK supported compilers?
> 
> I don't know. I'll ask around next week and see if I
> can find someone who knows exactly what the portability
> issue was.

If done this will have to be wrapped up in a vtkMath::IsNan method
(perhaps inlined).  I have investigated isnan in the past.  There are
many portability issues with isnan because (from memory):

1.) Some compilers provide a single isnan macro for float, double and
long double
2.) Some compilers provide separate overloads for the types
3.) Some compilers provide separate names like isnanf and isnanl
4.) Some compilers change their behavior between C and C++ modes
5.) Some compilers provide broken isnan on certain architectures
6.) On compilers where it is not provided it is hard to simulate

There is an attempt at overcoming these issues in vxl, which is then
used by ITK:

http://www.itk.org/cgi-bin/viewcvs.cgi/Utilities/vxl/core/vnl/vnl_math.cxx?root=Insight&view=markup

Look for a note about isnan on OSX Tiger in that file to get an idea how
broken things get.  I still don't think this version works everywhere,
at least without manually coding it for each new platform.

I once investigated replacing the vnl_math.cxx implementation of isnan
and similar functions with a more portable one.  I concluded that it was
taking too much time and left a note in vxl's TODO list:

http://vxl.cvs.sourceforge.net/vxl/vxl/TODO.txt?revision=1.12&view=markup

There is a thread over 100 messages long spread over two months on the
boost mailing list about isnan.  Here is the start:

http://lists.boost.org/Archives/boost/2006/10/111138.php

-Brad




More information about the vtk-developers mailing list