ITK  4.13.0 Insight Segmentation and Registration Toolkit
itk::Math Namespace Reference

Detail

## Functions

bool abs (const bool x)

unsigned char abs (const unsigned char x)

unsigned char abs (const signed char x)

unsigned char abs (const char x)

unsigned short abs (const short x)

unsigned short abs (const unsigned short x)

unsigned int abs (const int x)

unsigned int abs (const unsigned int x)

unsigned long abs (const long x)

unsigned long abs (const unsigned long x)

float abs (const float x)

double abs (const double x)

long double abs (const long double x)

template<typename T1 , typename T2 >
bool AlmostEquals (T1 x1, T2 x2)

template<typename T >
angle_0_to_2pi (const T angle)

template<typename T >
angle_minuspi_to_pi (const T angle)

template<typename TReturn , typename TInput >
TReturn CastWithRangeCheck (TInput x)

template<typename T >
cbrt (const T value)

template<TReturn , typename TInput >
Ceil (TInput x)

template<typename T >
int ceil (const T x)

bool cube (const bool x)

int cube (const int x)

unsigned int cube (const unsigned int x)

long cube (const long x)

unsigned long cube (const unsigned long x)

float cube (const float x)

double cube (const double x)

template<typename TInput1 , typename TInput2 >
bool ExactlyEquals (const TInput1 &x1, const TInput2 &x2)

template<typename T >
FloatAddULP (T x, typename Detail::FloatIEEE< T >::IntType ulps)

template<typename T >
bool FloatAlmostEqual (T x1, T x2, typename Detail::FloatIEEE< T >::IntType maxUlps=4, typename Detail::FloatIEEE< T >::FloatType maxAbsoluteDifference=0.1 *itk::NumericTraits< T >::epsilon())

template<typename T >
Detail::FloatIEEE< T >::IntType FloatDifferenceULP (T x1, T x2)

template<TReturn , typename TInput >
Floor (TInput x)

template<typename T >
int floor (const T x)

template<typename T >
hypot (const T value1, const T value2)

template<typename T >
bool isfinite (const T value)

template<typename T >
bool isinf (const T value)

template<typename T >
bool isnan (const T value)

template<typename T1 , typename T2 >
bool NotAlmostEquals (T1 x1, T2 x2)

template<typename TInput1 , typename TInput2 >
bool NotExactlyEquals (const TInput1 &x1, const TInput2 &x2)

template<typename T >
remainder_floored (const T x, const T y)

template<typename T >
remainder_truncated (const T x, const T y)

template<typename T >
int rnd (const T x)

template<typename T >
int rnd_halfinttoeven (const T x)

template<typename T >
int rnd_halfintup (const T x)

template<typename TReturn , typename TInput >
TReturn Round (TInput x)

template<TReturn , typename TInput >
RoundHalfIntegerToEven (TInput x)

template<TReturn , typename TInput >
RoundHalfIntegerUp (TInput x)

template<typename T >
int sgn (const T x)

template<typename T >
int sgn0 (const T x)

bool sqr (const bool x)

int sqr (const int x)

unsigned int sqr (const unsigned int x)

long sqr (const long x)

unsigned long sqr (const unsigned long x)

float sqr (const float x)

double sqr (const double x)

unsigned int squared_magnitude (const char x)

unsigned int squared_magnitude (const unsigned char x)

unsigned int squared_magnitude (const int x)

unsigned int squared_magnitude (const unsigned int x)

unsigned long squared_magnitude (const long x)

unsigned long squared_magnitude (const unsigned long x)

float squared_magnitude (const float x)

double squared_magnitude (const double x)

long double squared_magnitude (const long double x)

ITKCommon_EXPORT bool IsPrime (unsigned short n)

ITKCommon_EXPORT bool IsPrime (unsigned int n)

ITKCommon_EXPORT bool IsPrime (unsigned long n)

ITKCommon_EXPORT bool IsPrime (unsigned long long n)

ITKCommon_EXPORT unsigned short GreatestPrimeFactor (unsigned short n)

ITKCommon_EXPORT unsigned int GreatestPrimeFactor (unsigned int n)

ITKCommon_EXPORT unsigned long GreatestPrimeFactor (unsigned long n)

ITKCommon_EXPORT unsigned long long GreatestPrimeFactor (unsigned long long n)

## Variables

static ITK_CONSTEXPR_VAR double e = vnl_math::e

static ITK_CONSTEXPR_VAR double eps = vnl_math::eps

static ITK_CONSTEXPR_VAR double euler = vnl_math::euler

static ITK_CONSTEXPR_VAR float float_eps = vnl_math::float_eps

static ITK_CONSTEXPR_VAR float float_sqrteps = vnl_math::float_sqrteps

static ITK_CONSTEXPR_VAR double ln10 = vnl_math::ln10

static ITK_CONSTEXPR_VAR double ln2 = vnl_math::ln2

static ITK_CONSTEXPR_VAR double log10e = vnl_math::log10e

static ITK_CONSTEXPR_VAR double log2e = vnl_math::log2e

static ITK_CONSTEXPR_VAR double one_over_pi = vnl_math::one_over_pi

static ITK_CONSTEXPR_VAR double one_over_sqrt2pi = vnl_math::one_over_sqrt2pi

static ITK_CONSTEXPR_VAR double pi = vnl_math::pi

static ITK_CONSTEXPR_VAR double pi_over_180 = vnl_math::pi_over_180

static ITK_CONSTEXPR_VAR double pi_over_2 = vnl_math::pi_over_2

static ITK_CONSTEXPR_VAR double pi_over_4 = vnl_math::pi_over_4

static ITK_CONSTEXPR_VAR double sqrt1_2 = vnl_math::sqrt1_2

static ITK_CONSTEXPR_VAR double sqrt1_3 = vnl_math::sqrt1_3

static ITK_CONSTEXPR_VAR double sqrt2 = vnl_math::sqrt2

static ITK_CONSTEXPR_VAR double sqrt2pi = vnl_math::sqrt2pi

static ITK_CONSTEXPR_VAR double sqrteps = vnl_math::sqrteps

static ITK_CONSTEXPR_VAR double two_over_pi = vnl_math::two_over_pi

static ITK_CONSTEXPR_VAR double two_over_sqrtpi = vnl_math::two_over_sqrtpi

static ITK_CONSTEXPR_VAR double twopi = vnl_math::twopi

## Function Documentation

 unsigned char itk::Math::abs ( const unsigned char x )
inline

Definition at line 807 of file itkMath.h.

 unsigned char itk::Math::abs ( const signed char x )
inline

Definition at line 808 of file itkMath.h.

References abs().

 unsigned char itk::Math::abs ( const char x )
inline

Definition at line 809 of file itkMath.h.

References abs().

 unsigned short itk::Math::abs ( const short x )
inline

Definition at line 810 of file itkMath.h.

References abs().

 unsigned short itk::Math::abs ( const unsigned short x )
inline

Definition at line 811 of file itkMath.h.

 unsigned int itk::Math::abs ( const int x )
inline

Definition at line 812 of file itkMath.h.

References abs().

 unsigned int itk::Math::abs ( const unsigned int x )
inline

Definition at line 813 of file itkMath.h.

 unsigned long itk::Math::abs ( const long x )
inline

Definition at line 814 of file itkMath.h.

References abs().

 unsigned long itk::Math::abs ( const unsigned long x )
inline

Definition at line 815 of file itkMath.h.

 float itk::Math::abs ( const float x )
inline

Definition at line 820 of file itkMath.h.

References abs().

 double itk::Math::abs ( const double x )
inline

Definition at line 821 of file itkMath.h.

References abs().

 long double itk::Math::abs ( const long double x )
inline

Definition at line 822 of file itkMath.h.

References abs().

template<typename T1 , typename T2 >
 bool itk::Math::AlmostEquals ( T1 x1, T2 x2 )
inline

Provide consistent equality checks between values of potentially different scalar or complex types.

template< typename T1, typename T2 > AlmostEquals( T1 x1, T2 x2 )

template< typename T1, typename T2 > NotAlmostEquals( T1 x1, T2 x2 )

This function compares two scalar or complex values of potentially different types. For maximum extensibility the function is implemented through a series of templated structs which direct the AlmostEquals() call to the correct function by evaluating the parameter's types.

Overall algorithm: If both values are complex... separate values into real and imaginary components and compare them separately

If one of the values is complex.. see if the imaginary part of the complex value is approximately 0 ... compare real part of complex value with scalar value

If both values are scalars...

To compare two floating point types... use FloatAlmostEqual.

To compare a floating point and an integer type... Use static_cast<FloatingPointType>(integerValue) and call FloatAlmostEqual

To compare signed and unsigned integers... Check for negative value or overflow, then cast and use ==

To compare two signed or two unsigned integers ... Use ==

To compare anything else ... Use ==

Parameters
 x1 first scalar value to compare x2 second scalar value to compare

Definition at line 672 of file itkMath.h.

template<typename T >
 T itk::Math::angle_0_to_2pi ( const T angle )

Definition at line 794 of file itkMath.h.

template<typename T >
 T itk::Math::angle_minuspi_to_pi ( const T angle )

Definition at line 795 of file itkMath.h.

template<typename TReturn , typename TInput >
 TReturn itk::Math::CastWithRangeCheck ( TInput x )
inline

Definition at line 210 of file itkMath.h.

References itk::NumericTraits< T >::IsPositive(), and itkConceptMacro.

template<typename T >
 T itk::Math::cbrt ( const T value )

Definition at line 792 of file itkMath.h.

template<TReturn , typename TInput >
 itk::Math::Ceil ( TInput x )

Round towards plus infinity.

The behavior of overflow is undefined due to numerous implementations.

Warning
argument absolute value must be less than INT_MAX/2 for vnl_math_ceil to be guaranteed to work.
We also assume that the rounding mode is not changed from the default one (or at least that it is always restored to the default one).
template<typename T >
 int itk::Math::ceil ( const T x )
inline
Examples:
Examples/Numerics/FourierDescriptors1.cxx.

Definition at line 800 of file itkMath.h.

 bool itk::Math::cube ( const bool x )
inline

Definition at line 836 of file itkMath.h.

Referenced by cube().

 int itk::Math::cube ( const int x )
inline

Definition at line 837 of file itkMath.h.

References cube().

 unsigned int itk::Math::cube ( const unsigned int x )
inline

Definition at line 838 of file itkMath.h.

References cube().

 long itk::Math::cube ( const long x )
inline

Definition at line 839 of file itkMath.h.

References cube().

 unsigned long itk::Math::cube ( const unsigned long x )
inline

Definition at line 840 of file itkMath.h.

References cube().

 float itk::Math::cube ( const float x )
inline

Definition at line 845 of file itkMath.h.

References cube().

 double itk::Math::cube ( const double x )
inline

Definition at line 846 of file itkMath.h.

References cube().

template<typename TInput1 , typename TInput2 >
 bool itk::Math::ExactlyEquals ( const TInput1 & x1, const TInput2 & x2 )
inline

Return the result of an exact comparison between two scalar values of potetially different types.

template <typename TInput1, typename TInput2> inline bool ExactlyEquals( const TInput & x1, const TInput & x2 )

template <typename TInput1, typename TInput2> inline bool NotExactlyEquals( const TInput & x1, const TInput & x2 )

These functions complement the EqualsComparison functions and determine if two scalar values are exactly equal using the compilers casting rules when comparing two different types. While this is also easily accomplished by using the equality operators, use of this function demonstrates the intent of an exact equality check and thus improves readability and clarity of code. In addition, this function suppresses float-equal warnings produced when using Clang.

Parameters
 x1 first floating point value to compare x2 second floating point value to compare

Definition at line 710 of file itkMath.h.

template<typename T >
 T itk::Math::FloatAddULP ( T x, typename Detail::FloatIEEE< T >::IntType ulps )
inline

Add the given ULPs (units in the last place) to a float.

If the given ULPs can are negative, they are subtracted.

FloatAlmostEqual
FloatDifferenceULP

Definition at line 267 of file itkMath.h.

template<typename T >
 bool itk::Math::FloatAlmostEqual ( T x1, T x2, typename Detail::FloatIEEE< T >::IntType maxUlps = 4, typename Detail::FloatIEEE< T >::FloatType maxAbsoluteDifference = 0.1*itk::NumericTraits::epsilon() )
inline

Compare two floats and return if they are effectively equal.

Determining when floats are almost equal is difficult because of their IEEE bit representation. This function uses the integer representation of the float to determine if they are almost equal.

The implementation is based off the explanation in the white papers:

This function is not a cure-all, and reading those articles is important to understand its appropriate use in the context of ULPs, zeros, subnormals, infinities, and NANs. For example, it is preferable to use this function on two floats directly instead of subtracting them and comparing them to zero.

The tolerance is specified in ULPs (units in the last place), i.e. how many floats there are in between the numbers. Therefore, the tolerance depends on the magnitude of the values that are being compared. A second tolerance is a maximum difference allowed, which is important when comparing numbers close to zero.

A NAN compares as not equal to a number, but two NAN's may compare as equal to each other.

Parameters
 x1 first floating value to compare x2 second floating values to compare maxUlps maximum units in the last place to be considered equal maxAbsoluteDifference maximum absolute difference to be considered equal

Definition at line 306 of file itkMath.h.

References abs(), itk::Math::Detail::FloatIEEE< T >::AsULP(), and FloatDifferenceULP().

template<typename T >
 Detail::FloatIEEE::IntType itk::Math::FloatDifferenceULP ( T x1, T x2 )
inline

Return the signed distance in ULPs (units in the last place) between two floats.

This is the signed distance, i.e., if x1 > x2, then the result is positive.

FloatAlmostEqual

Definition at line 251 of file itkMath.h.

References itk::Math::Detail::FloatIEEE< T >::AsULP().

Referenced by FloatAlmostEqual().

template<TReturn , typename TInput >
 itk::Math::Floor ( TInput x )

Round towards minus infinity.

The behavior of overflow is undefined due to numerous implementations.

Warning
argument absolute value must be less than NumbericTraits<TReturn>::max()/2 for vnl_math_floor to be guaranteed to work.
We also assume that the rounding mode is not changed from the default one (or at least that it is always restored to the default one).
template<typename T >
 int itk::Math::floor ( const T x )
inline

Definition at line 799 of file itkMath.h.

 ITKCommon_EXPORT unsigned short itk::Math::GreatestPrimeFactor ( unsigned short n )

Return the greatest factor of the decomposition in prime numbers.

 ITKCommon_EXPORT unsigned int itk::Math::GreatestPrimeFactor ( unsigned int n )

Return the greatest factor of the decomposition in prime numbers.

 ITKCommon_EXPORT unsigned long itk::Math::GreatestPrimeFactor ( unsigned long n )

Return the greatest factor of the decomposition in prime numbers.

 ITKCommon_EXPORT unsigned long long itk::Math::GreatestPrimeFactor ( unsigned long long n )

Return the greatest factor of the decomposition in prime numbers.

template<typename T >
 T itk::Math::hypot ( const T value1, const T value2 )

Definition at line 793 of file itkMath.h.

template<typename T >
 bool itk::Math::isfinite ( const T value )

Definition at line 791 of file itkMath.h.

template<typename T >
 bool itk::Math::isinf ( const T value )

Definition at line 790 of file itkMath.h.

template<typename T >
 bool itk::Math::isnan ( const T value )

Definition at line 789 of file itkMath.h.

 ITKCommon_EXPORT bool itk::Math::IsPrime ( unsigned short n )

Return whether the number is a prime number or not.

Note
Negative numbers cannot be prime.
 ITKCommon_EXPORT bool itk::Math::IsPrime ( unsigned int n )

Return whether the number is a prime number or not.

Note
Negative numbers cannot be prime.
 ITKCommon_EXPORT bool itk::Math::IsPrime ( unsigned long n )

Return whether the number is a prime number or not.

Note
Negative numbers cannot be prime.
 ITKCommon_EXPORT bool itk::Math::IsPrime ( unsigned long long n )

Return whether the number is a prime number or not.

Note
Negative numbers cannot be prime.
template<typename T1 , typename T2 >
 bool itk::Math::NotAlmostEquals ( T1 x1, T2 x2 )
inline
Examples:
Examples/Statistics/KdTree.cxx.

Definition at line 680 of file itkMath.h.

References AlmostEquals().

template<typename T >
 T itk::Math::remainder_floored ( const T x, const T y )

Definition at line 804 of file itkMath.h.

template<typename T >
 T itk::Math::remainder_truncated ( const T x, const T y )

Definition at line 803 of file itkMath.h.

template<typename T >
 int itk::Math::rnd ( const T x )
inline

Definition at line 798 of file itkMath.h.

template<typename T >
 int itk::Math::rnd_halfinttoeven ( const T x )
inline

Definition at line 796 of file itkMath.h.

template<typename T >
 int itk::Math::rnd_halfintup ( const T x )
inline

Definition at line 797 of file itkMath.h.

template<typename TReturn , typename TInput >
 TReturn itk::Math::Round ( TInput x )
inline

Round towards nearest integer (This is a synonym for RoundHalfIntegerUp)

Template Parameters
 TReturn must be an integer type TInput must be float or double
RoundHalfIntegerUp<TReturn, TInput>()

Definition at line 179 of file itkMath.h.

template<TReturn , typename TInput >
 itk::Math::RoundHalfIntegerToEven ( TInput x )

Round towards nearest integer.

Template Parameters
 TReturn must be an integer type TInput must be float or double  halfway cases are rounded towards the nearest even integer, e.g.  * RoundHalfIntegerToEven( 1.5) == 2 * RoundHalfIntegerToEven(-1.5) == -2 * RoundHalfIntegerToEven( 2.5) == 2 * RoundHalfIntegerToEven( 3.5) == 4 *

The behavior of overflow is undefined due to numerous implementations.

Warning
We assume that the rounding mode is not changed from the default one (or at least that it is always restored to the default one).
template<TReturn , typename TInput >
 itk::Math::RoundHalfIntegerUp ( TInput x )

Round towards nearest integer.

Template Parameters
 TReturn must be an integer type TInput must be float or double  halfway cases are rounded upward, e.g.  * RoundHalfIntegerUp( 1.5) == 2 * RoundHalfIntegerUp(-1.5) == -1 * RoundHalfIntegerUp( 2.5) == 3 *

The behavior of overflow is undefined due to numerous implementations.

Warning
The argument absolute value must be less than NumbericTraits<TReturn>::max()/2 for RoundHalfIntegerUp to be guaranteed to work.
We also assume that the rounding mode is not changed from the default one (or at least that it is always restored to the default one).
template<typename T >
 int itk::Math::sgn ( const T x )

Definition at line 801 of file itkMath.h.

template<typename T >
 int itk::Math::sgn0 ( const T x )

Definition at line 802 of file itkMath.h.

 bool itk::Math::sqr ( const bool x )
inline
 int itk::Math::sqr ( const int x )
inline

Definition at line 825 of file itkMath.h.

References sqr().

 unsigned int itk::Math::sqr ( const unsigned int x )
inline

Definition at line 826 of file itkMath.h.

References sqr().

 long itk::Math::sqr ( const long x )
inline

Definition at line 827 of file itkMath.h.

References sqr().

 unsigned long itk::Math::sqr ( const unsigned long x )
inline

Definition at line 828 of file itkMath.h.

References sqr().

 float itk::Math::sqr ( const float x )
inline

Definition at line 833 of file itkMath.h.

References sqr().

 double itk::Math::sqr ( const double x )
inline

Definition at line 834 of file itkMath.h.

References sqr().

 unsigned int itk::Math::squared_magnitude ( const char x )
inline

Definition at line 848 of file itkMath.h.

Referenced by squared_magnitude().

 unsigned int itk::Math::squared_magnitude ( const unsigned char x )
inline

Definition at line 849 of file itkMath.h.

References squared_magnitude().

 unsigned int itk::Math::squared_magnitude ( const int x )
inline

Definition at line 850 of file itkMath.h.

References squared_magnitude().

 unsigned int itk::Math::squared_magnitude ( const unsigned int x )
inline

Definition at line 851 of file itkMath.h.

References squared_magnitude().

 unsigned long itk::Math::squared_magnitude ( const long x )
inline

Definition at line 852 of file itkMath.h.

References squared_magnitude().

 unsigned long itk::Math::squared_magnitude ( const unsigned long x )
inline

Definition at line 853 of file itkMath.h.

References squared_magnitude().

 float itk::Math::squared_magnitude ( const float x )
inline

Definition at line 858 of file itkMath.h.

References squared_magnitude().

 double itk::Math::squared_magnitude ( const double x )
inline

Definition at line 859 of file itkMath.h.

References squared_magnitude().

 long double itk::Math::squared_magnitude ( const long double x )
inline

Definition at line 860 of file itkMath.h.

References squared_magnitude().

## Variable Documentation

static

Definition at line 80 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::eps = vnl_math::eps
static
 ITK_CONSTEXPR_VAR double itk::Math::euler = vnl_math::euler
static

euler constant

Definition at line 94 of file itkMath.h.

 ITK_CONSTEXPR_VAR float itk::Math::float_eps = vnl_math::float_eps
static

Definition at line 100 of file itkMath.h.

 ITK_CONSTEXPR_VAR float itk::Math::float_sqrteps = vnl_math::float_sqrteps
static

Definition at line 101 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::ln10 = vnl_math::ln10
static

Definition at line 64 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::ln2 = vnl_math::ln2
static

Definition at line 62 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::log10e = vnl_math::log10e
static

Definition at line 60 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::log2e = vnl_math::log2e
static

Definition at line 58 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::one_over_pi = vnl_math::one_over_pi
static

Definition at line 76 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::one_over_sqrt2pi = vnl_math::one_over_sqrt2pi
static

Definition at line 86 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::pi_over_180 = vnl_math::pi_over_180
static

Definition at line 74 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::pi_over_2 = vnl_math::pi_over_2
static

Definition at line 70 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::pi_over_4 = vnl_math::pi_over_4
static

Definition at line 72 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::sqrt1_2 = vnl_math::sqrt1_2
static

Definition at line 90 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::sqrt1_3 = vnl_math::sqrt1_3
static

Definition at line 92 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::sqrt2 = vnl_math::sqrt2
static

Definition at line 88 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::sqrt2pi = vnl_math::sqrt2pi
static

Definition at line 82 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::sqrteps = vnl_math::sqrteps
static

Definition at line 98 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::two_over_pi = vnl_math::two_over_pi
static

Definition at line 78 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::two_over_sqrtpi = vnl_math::two_over_sqrtpi
static

Definition at line 84 of file itkMath.h.

 ITK_CONSTEXPR_VAR double itk::Math::twopi = vnl_math::twopi
static