[Insight-developers] Be careful when using NumericTraits<>::min
Lorensen, William E (Research)
lorensen@crd.ge.com
Mon, 3 Mar 2003 09:13:59 -0500
Folks,
The C++ min() for floats and doubles behaves differently than it does for other types.
For all but float and double, min() returns what you might expect, the minimum value for the type.
For float and double, it returns the least significant value. itk has a NonpositiveMin which
consistently represents the minimum value for the type.
There were several incorrect uses of min() in itk. Most notable, the MinimumMaximumImageFilter.
Others occurred in statistics classes. I changed these to NonpositiveMin(). The FEM classes used
<double>min() correctly, so I left them alone.
Here is the output of a new test Common/itkNumericTraitsTest
itk::NumericTraits<char>
min(): -128
max(): 127
NonpositiveMin(): -128
itk::NumericTraits<unsigned char>
min(): 0
max(): 255
NonpositiveMin(): 0
itk::NumericTraits<short>
min(): -32768
max(): 32767
NonpositiveMin(): -32768
itk::NumericTraits<unsigned short>
min(): 0
max(): 65535
NonpositiveMin(): 0
itk::NumericTraits<int>
min(): -2147483648
max(): 2147483647
NonpositiveMin(): -2147483648
itk::NumericTraits<unsigned int>
min(): 0
max(): 4294967295
NonpositiveMin(): 0
itk::NumericTraits<long>
min(): -2147483648
max(): 2147483647
NonpositiveMin(): -2147483648
itk::NumericTraits<unsigned long>
min(): 0
max(): 4294967295
NonpositiveMin(): 0
itk::NumericTraits<float>
min(): 1.17549e-38
max(): 3.40282e+38
NonpositiveMin(): -3.40282e+38
itk::NumericTraits<double>
min(): 2.22507e-308
max(): 1.79769e+308
NonpositiveMin(): -1.79769e+308