Get Type Basic Information

Synopsis

Get some basic information about a plain old data (POD) type, in this case the float type.

Results

Output:

Min: 1.17549e-38
Max: 3.40282e+38
Zero: 0
ZeroValue: 0
Is -1 negative? 1
Is 1 negative? 0
One: 1
Epsilon: 1.19209e-07
Infinity: inf
Good

Code

C++

#include "itkNumericTraits.h"

int
main(int, char *[])
{
  using MyType = float;

  std::cout << "Min: " << itk::NumericTraits<MyType>::min() << std::endl;
  std::cout << "Max: " << itk::NumericTraits<MyType>::max() << std::endl;
  std::cout << "Zero: " << itk::NumericTraits<MyType>::Zero << std::endl;
  std::cout << "ZeroValue: " << itk::NumericTraits<MyType>::ZeroValue() << std::endl;

  std::cout << "Is -1 negative? " << itk::NumericTraits<MyType>::IsNegative(-1) << std::endl;

  std::cout << "Is 1 negative? " << itk::NumericTraits<MyType>::IsNegative(1) << std::endl;

  std::cout << "One: " << itk::NumericTraits<MyType>::One << std::endl;

  std::cout << "Epsilon: " << itk::NumericTraits<MyType>::epsilon() << std::endl;

  std::cout << "Infinity: " << itk::NumericTraits<MyType>::infinity() << std::endl;

  if (0 == itk::NumericTraits<MyType>::infinity())
  {
    std::cout << " 0 == inf!" << std::endl;
    return EXIT_FAILURE;
  }
  else
  {
    std::cout << "Good" << std::endl;
    return EXIT_SUCCESS;
  }
}

Classes demonstrated