ITK  5.2.0
Insight Toolkit
itkMath.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkMath_h
29 #define itkMath_h
30 
31 #include <cmath>
32 #include "itkMathDetail.h"
33 #include "itkConceptChecking.h"
34 #include <vnl/vnl_math.h>
35 
36 /* Only maintain backwards compatibility with old versions
37  * of VXL back to the point where vnl_math:: was introduced
38  * versions of VXL where only vnl_math_ was available are not
39  * supported.
40  */
41 #include <vxl_version.h>
42 
43 namespace itk
44 {
45 namespace Math
46 {
47 // These constants originate from VXL's vnl_math.h. They have been
48 // moved here to improve visibility, and to ensure that the constants
49 // are available during compile time ( as opposed to static ITK_CONSTEXPR
50 // member vaiables ).
51 
52 
54 static constexpr double e = vnl_math::e;
56 static constexpr double log2e = vnl_math::log2e;
58 static constexpr double log10e = vnl_math::log10e;
60 static constexpr double ln2 = vnl_math::ln2;
62 static constexpr double ln10 = vnl_math::ln10;
64 static constexpr double pi = vnl_math::pi;
66 static constexpr double twopi = vnl_math::twopi;
68 static constexpr double pi_over_2 = vnl_math::pi_over_2;
70 static constexpr double pi_over_4 = vnl_math::pi_over_4;
72 static constexpr double pi_over_180 = vnl_math::pi_over_180;
74 static constexpr double one_over_pi = vnl_math::one_over_pi;
76 static constexpr double two_over_pi = vnl_math::two_over_pi;
78 static constexpr double deg_per_rad = vnl_math::deg_per_rad;
80 static constexpr double sqrt2pi = vnl_math::sqrt2pi;
82 static constexpr double two_over_sqrtpi = vnl_math::two_over_sqrtpi;
84 static constexpr double one_over_sqrt2pi = vnl_math::one_over_sqrt2pi;
86 static constexpr double sqrt2 = vnl_math::sqrt2;
88 static constexpr double sqrt1_2 = vnl_math::sqrt1_2;
90 static constexpr double sqrt1_3 = vnl_math::sqrt1_3;
92 static constexpr double euler = vnl_math::euler;
93 
94 //: IEEE double machine precision
95 static constexpr double eps = vnl_math::eps;
96 static constexpr double sqrteps = vnl_math::sqrteps;
97 //: IEEE single machine precision
98 static constexpr float float_eps = vnl_math::float_eps;
99 static constexpr float float_sqrteps = vnl_math::float_sqrteps;
100 
104 #define itkTemplateFloatingToIntegerMacro(name) \
105  template <typename TReturn, typename TInput> \
106  inline TReturn name(TInput x) \
107  { \
108  \
109  if (sizeof(TReturn) <= 4) \
110  { \
111  return static_cast<TReturn>(Detail::name##_32(x)); \
112  } \
113  else if (sizeof(TReturn) <= 8) \
114  { \
115  return static_cast<TReturn>(Detail::name##_64(x)); \
116  } \
117  else \
118  { \
119  return static_cast<TReturn>(Detail::name##_base<TReturn, TInput>(x)); \
120  } \
121  }
122 
123 
144 
168 
176 template <typename TReturn, typename TInput>
177 inline TReturn
178 Round(TInput x)
179 {
180  return RoundHalfIntegerUp<TReturn, TInput>(x);
181 }
182 
196 
208 
209 #undef itkTemplateFloatingToIntegerMacro
210 
211 template <typename TReturn, typename TInput>
212 inline TReturn
214 {
215 #ifdef ITK_USE_CONCEPT_CHECKING
216  itkConceptMacro(OnlyDefinedForIntegerTypes1, (itk::Concept::IsInteger<TReturn>));
217  itkConceptMacro(OnlyDefinedForIntegerTypes2, (itk::Concept::IsInteger<TInput>));
218 #endif // ITK_USE_CONCEPT_CHECKING
219 
220  auto ret = static_cast<TReturn>(x);
221  if (sizeof(TReturn) > sizeof(TInput) &&
223  {
224  // if the output type is bigger and we are not converting a signed
225  // integer to an unsigned integer then we have no problems
226  return ret;
227  }
228  else if (sizeof(TReturn) >= sizeof(TInput))
229  {
231  {
232  itk::RangeError _e(__FILE__, __LINE__);
233  throw _e;
234  }
235  }
236  else if (static_cast<TInput>(ret) != x ||
238  {
239  itk::RangeError _e(__FILE__, __LINE__);
240  throw _e;
241  }
242  return ret;
243 }
244 
252 template <typename T>
253 inline typename Detail::FloatIEEE<T>::IntType
255 {
256  Detail::FloatIEEE<T> x1f(x1);
257  Detail::FloatIEEE<T> x2f(x2);
258  return x1f.AsULP() - x2f.AsULP();
259 }
260 
268 template <typename T>
269 inline T
271 {
272  Detail::FloatIEEE<T> representInput(x);
273  Detail::FloatIEEE<T> representOutput(representInput.asInt + ulps);
274  return representOutput.asFloat;
275 }
276 
307 template <typename T>
308 inline bool
310  T x2,
311  typename Detail::FloatIEEE<T>::IntType maxUlps = 4,
312  typename Detail::FloatIEEE<T>::FloatType maxAbsoluteDifference = 0.1 *
314 {
315  // Check if the numbers are really close -- needed
316  // when comparing numbers near zero.
317  const T absDifference = std::abs(x1 - x2);
318  if (absDifference <= maxAbsoluteDifference)
319  {
320  return true;
321  }
322 
323  // This check for different signs is necessary for several reasons, see the blog link above.
324  // Subtracting the signed-magnitude representation of floats using twos-complement
325  // math isn't particularly meaningful, and the subtraction would produce a 33-bit
326  // result and overflow an int.
327  if (std::signbit(x1) != std::signbit(x2))
328  {
329  return false;
330  }
331 
332  typename Detail::FloatIEEE<T>::IntType ulps = FloatDifferenceULP(x1, x2);
333  if (ulps < 0)
334  {
335  ulps = -ulps;
336  }
337  return ulps <= maxUlps;
338 }
339 
340 // The following code cannot be moved to the itkMathDetail.h file without introducing circular dependencies
341 namespace Detail // The Detail namespace holds the templates used by AlmostEquals
342 {
343 // The following structs and templates are used to choose
344 // which version of the AlmostEquals function
345 // should be implemented base on input parameter types
346 
347 // Structs for choosing AlmostEquals function
348 
350 {
351  template <typename TFloatType1, typename TFloatType2>
352  static bool
353  AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
354  {
355  return FloatAlmostEqual<double>(x1, x2);
356  }
357 
358  template <typename TFloatType1, typename TFloatType2>
359  static bool
360  AlmostEqualsFunction(double x1, double x2)
361  {
362  return FloatAlmostEqual<double>(x1, x2);
363  }
364 
365  template <typename TFloatType1, typename TFloatType2>
366  static bool
367  AlmostEqualsFunction(double x1, float x2)
368  {
369  return FloatAlmostEqual<float>(x1, x2);
370  }
371 
372  template <typename TFloatType1, typename TFloatType2>
373  static bool
374  AlmostEqualsFunction(float x1, double x2)
375  {
376  return FloatAlmostEqual<float>(x1, x2);
377  }
378 
379  template <typename TFloatType1, typename TFloatType2>
380  static bool
381  AlmostEqualsFunction(float x1, float x2)
382  {
383  return FloatAlmostEqual<float>(x1, x2);
384  }
385 };
386 
388 {
389  template <typename TFloatType, typename TIntType>
390  static bool
391  AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
392  {
393  return FloatAlmostEqual<TFloatType>(floatingVariable, integerVariable);
394  }
395 };
396 
398 {
399  template <typename TIntType, typename TFloatType>
400  static bool
401  AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
402  {
403  return AlmostEqualsFloatVsInteger::AlmostEqualsFunction(floatingVariable, integerVariable);
404  }
405 };
406 
408 {
409  template <typename TSignedInt, typename TUnsignedInt>
410  static bool
411  AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
412  {
413  if (signedVariable < 0)
414  return false;
415  if (unsignedVariable > static_cast<size_t>(itk::NumericTraits<TSignedInt>::max()))
416  return false;
417  return signedVariable == static_cast<TSignedInt>(unsignedVariable);
418  }
419 };
420 
422 {
423  template <typename TUnsignedInt, typename TSignedInt>
424  static bool
425  AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
426  {
427  return AlmostEqualsSignedVsUnsigned::AlmostEqualsFunction(signedVariable, unsignedVariable);
428  }
429 };
430 
432 {
433  template <typename TIntegerType1, typename TIntegerType2>
434  static bool
435  AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
436  {
437  return x1 == x2;
438  }
439 };
440 // end of structs that choose the specific AlmostEquals function
441 
442 // Selector structs, these select the correct case based on its types
443 // input1 is int? input 1 is signed? input2 is int? input 2 is signed?
444 template <bool TInput1IsIntger, bool TInput1IsSigned, bool TInput2IsInteger, bool TInput2IsSigned>
446 { // default case
448 };
449 
451 template <>
452 struct AlmostEqualsFunctionSelector<false, true, false, true>
453 // floating type v floating type
454 {
456 };
457 
458 template <>
459 struct AlmostEqualsFunctionSelector<false, true, true, true>
460 // float vs signed int
461 {
462  using SelectedVersion = AlmostEqualsFloatVsInteger;
463 };
464 
465 template <>
466 struct AlmostEqualsFunctionSelector<false, true, true, false>
467 // float vs unsigned int
468 {
469  using SelectedVersion = AlmostEqualsFloatVsInteger;
470 };
471 
472 template <>
473 struct AlmostEqualsFunctionSelector<true, false, false, true>
474 // unsigned int vs float
475 {
476  using SelectedVersion = AlmostEqualsIntegerVsFloat;
477 };
478 
479 template <>
480 struct AlmostEqualsFunctionSelector<true, true, false, true>
481 // signed int vs float
482 {
483  using SelectedVersion = AlmostEqualsIntegerVsFloat;
484 };
485 
486 template <>
487 struct AlmostEqualsFunctionSelector<true, true, true, false>
488 // signed vs unsigned
489 {
490  using SelectedVersion = AlmostEqualsSignedVsUnsigned;
491 };
492 
493 template <>
494 struct AlmostEqualsFunctionSelector<true, false, true, true>
495 // unsigned vs signed
496 {
497  using SelectedVersion = AlmostEqualsUnsignedVsSigned;
498 };
499 
500 template <>
501 struct AlmostEqualsFunctionSelector<true, true, true, true>
502 // signed vs signed
503 {
504  using SelectedVersion = AlmostEqualsPlainOldEquals;
505 };
506 
507 template <>
508 struct AlmostEqualsFunctionSelector<true, false, true, false>
509 // unsigned vs unsigned
510 {
511  using SelectedVersion = AlmostEqualsPlainOldEquals;
512 };
513 // end of AlmostEqualsFunctionSelector structs
514 
515 // The implementor tells the selector what to do
516 template <typename TInputType1, typename TInputType2>
517 struct AlmostEqualsScalarImplementer
518 {
519  static constexpr bool TInputType1IsInteger = itk::NumericTraits<TInputType1>::IsInteger;
520  static constexpr bool TInputType1IsSigned = itk::NumericTraits<TInputType1>::IsSigned;
521  static constexpr bool TInputType2IsInteger = itk::NumericTraits<TInputType2>::IsInteger;
522  static constexpr bool TInputType2IsSigned = itk::NumericTraits<TInputType2>::IsSigned;
523 
524  using SelectedVersion = typename AlmostEqualsFunctionSelector<TInputType1IsInteger,
525  TInputType1IsSigned,
526  TInputType2IsInteger,
527  TInputType2IsSigned>::SelectedVersion;
528 };
529 
530 // The AlmostEqualsScalarComparer returns the result of an
531 // approximate comparison between two scalar values of
532 // potentially different data types.
533 template <typename TScalarType1, typename TScalarType2>
534 inline bool
535 AlmostEqualsScalarComparer(TScalarType1 x1, TScalarType2 x2)
536 {
537  return AlmostEqualsScalarImplementer<TScalarType1, TScalarType2>::SelectedVersion::
538  template AlmostEqualsFunction<TScalarType1, TScalarType2>(x1, x2);
539 }
540 
541 // The following structs are used to evaluate approximate comparisons between
542 // complex and scalar values of potentially different types.
543 
544 // Comparisons between scalar types use the AlmostEqualsScalarComparer function.
545 struct AlmostEqualsScalarVsScalar
546 {
547  template <typename TScalarType1, typename TScalarType2>
548  static bool
549  AlmostEqualsFunction(TScalarType1 x1, TScalarType2 x2)
550  {
551  return AlmostEqualsScalarComparer(x1, x2);
552  }
553 };
554 
555 // Comparisons between two complex values compare the real and imaginary components
556 // separately with the AlmostEqualsScalarComparer function.
557 struct AlmostEqualsComplexVsComplex
558 {
559  template <typename TComplexType1, typename TComplexType2>
560  static bool
561  AlmostEqualsFunction(TComplexType1 x1, TComplexType2 x2)
562  {
563  return AlmostEqualsScalarComparer(x1.real(), x2.real()) && AlmostEqualsScalarComparer(x1.imag(), x2.imag());
564  }
565 };
566 
567 // Comparisons between complex and scalar values first check to see if the imaginary component
568 // of the complex value is approximately 0. Then a ScalarComparison is done between the real
569 // part of the complex number and the scalar value.
570 struct AlmostEqualsScalarVsComplex
571 {
572  template <typename TScalarType, typename TComplexType>
573  static bool
574  AlmostEqualsFunction(TScalarType scalarVariable, TComplexType complexVariable)
575  {
576  if (!AlmostEqualsScalarComparer(
577  complexVariable.imag(),
579  {
580  return false;
581  }
582  return AlmostEqualsScalarComparer(scalarVariable, complexVariable.real());
583  }
584 };
585 
586 struct AlmostEqualsComplexVsScalar
587 {
588  template <typename TComplexType, typename TScalarType>
589  static bool
590  AlmostEqualsFunction(TComplexType complexVariable, TScalarType scalarVariable)
591  {
592  return AlmostEqualsScalarVsComplex::AlmostEqualsFunction(scalarVariable, complexVariable);
593  }
594 };
595 
596 // The AlmostEqualsComplexChooser structs choose the correct case
597 // from the input parameter types' IsComplex property
598 // The default case is scalar vs scalar
599 template <bool T1IsComplex, bool T2IsComplex> // Default is false, false
600 struct AlmostEqualsComplexChooser
601 {
602  using ChosenVersion = AlmostEqualsScalarVsScalar;
603 };
604 
605 template <>
606 struct AlmostEqualsComplexChooser<true, true>
607 {
608  using ChosenVersion = AlmostEqualsComplexVsComplex;
609 };
610 
611 template <>
612 struct AlmostEqualsComplexChooser<false, true>
613 {
614  using ChosenVersion = AlmostEqualsScalarVsComplex;
615 };
616 
617 template <>
618 struct AlmostEqualsComplexChooser<true, false>
619 {
620  using ChosenVersion = AlmostEqualsComplexVsScalar;
621 };
622 // End of AlmostEqualsComplexChooser structs.
623 
624 // The AlmostEqualsComplexImplementer determines which of the input
625 // parameters are complex and which are real, and sends that information
626 // to the AlmostEqualsComplexChooser structs to determine the proper
627 // type of evaluation.
628 template <typename T1, typename T2>
629 struct AlmostEqualsComplexImplementer
630 {
631  static constexpr bool T1IsComplex = NumericTraits<T1>::IsComplex;
632  static constexpr bool T2IsComplex = NumericTraits<T2>::IsComplex;
633 
634  using ChosenVersion = typename AlmostEqualsComplexChooser<T1IsComplex, T2IsComplex>::ChosenVersion;
635 };
637 
638 } // end namespace Detail
639 
682 // The AlmostEquals function
683 template <typename T1, typename T2>
684 inline bool
685 AlmostEquals(T1 x1, T2 x2)
686 {
687  return Detail::AlmostEqualsComplexImplementer<T1, T2>::ChosenVersion::AlmostEqualsFunction(x1, x2);
688 }
689 
690 // The NotAlmostEquals function
691 template <typename T1, typename T2>
692 inline bool
693 NotAlmostEquals(T1 x1, T2 x2)
694 {
695  return !AlmostEquals(x1, x2);
696 }
697 
698 
720 // The ExactlyEquals function
721 template <typename TInput1, typename TInput2>
722 inline bool
723 ExactlyEquals(const TInput1 & x1, const TInput2 & x2)
724 {
725  CLANG_PRAGMA_PUSH
726  CLANG_SUPPRESS_Wfloat_equal return x1 == x2;
727  CLANG_PRAGMA_POP
728 }
729 
730 // The NotExactlyEquals function
731 template <typename TInput1, typename TInput2>
732 inline bool
733 NotExactlyEquals(const TInput1 & x1, const TInput2 & x2)
734 {
735  return !ExactlyEquals(x1, x2);
736 }
737 
738 
743 ITKCommon_EXPORT bool
744 IsPrime(unsigned short n);
745 ITKCommon_EXPORT bool
746 IsPrime(unsigned int n);
747 ITKCommon_EXPORT bool
748 IsPrime(unsigned long n);
749 ITKCommon_EXPORT bool
750 IsPrime(unsigned long long n);
752 
753 
755 ITKCommon_EXPORT unsigned short
756 GreatestPrimeFactor(unsigned short n);
757 ITKCommon_EXPORT unsigned int
758 GreatestPrimeFactor(unsigned int n);
759 ITKCommon_EXPORT unsigned long
760 GreatestPrimeFactor(unsigned long n);
761 ITKCommon_EXPORT unsigned long long
762 GreatestPrimeFactor(unsigned long long n);
764 
765 // C++11 does not guarantee that assert can be used in constexpr
766 // functions. This is a work-around for GCC 4.8, 4.9. Originating
767 // from Andrzej's C++ blog:
768 // https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
769 #if defined NDEBUG
770 # define ITK_X_ASSERT(CHECK) void(0)
771 #else
772 # define ITK_X_ASSERT(CHECK) ((CHECK) ? void(0) : [] { assert(!#CHECK); }())
773 #endif
774 
778 template <typename TReturnType = std::uintmax_t>
779 constexpr TReturnType
780 UnsignedProduct(const std::uintmax_t a, const std::uintmax_t b) ITK_NOEXCEPT
781 {
782  static_assert(std::is_unsigned<TReturnType>::value, "UnsignedProduct only supports unsigned return types");
783 
784  // Note that numeric overflow is not "undefined behavior", for unsigned numbers.
785  // This function checks if the result of a*b is mathematically correct.
786  return (a == 0) || (b == 0) ||
787  (((static_cast<TReturnType>(a * b) / a) == b) && ((static_cast<TReturnType>(a * b) / b) == a))
788  ? static_cast<TReturnType>(a * b)
789  : (ITK_X_ASSERT(!"UnsignedProduct overflow!"), 0);
790 }
791 
792 
800 template <typename TReturnType = std::uintmax_t>
801 constexpr TReturnType
802 UnsignedPower(const std::uintmax_t base, const std::uintmax_t exponent) ITK_NOEXCEPT
803 {
804  static_assert(std::is_unsigned<TReturnType>::value, "UnsignedPower only supports unsigned return types");
805 
806  // Uses recursive function calls because C++11 does not support other ways of
807  // iterations for a constexpr function.
808  return (exponent == 0)
809  ? (ITK_X_ASSERT(base > 0), 1)
810  : (exponent == 1) ? base
811  : UnsignedProduct<TReturnType>(UnsignedPower<TReturnType>(base, exponent / 2),
812  UnsignedPower<TReturnType>(base, (exponent + 1) / 2));
813 }
814 
815 #undef ITK_X_ASSERT
816 
817 
818 /*==========================================
819  * Alias the vnl_math functions in the itk::Math
820  * namespace. If possible, use the std:: equivalents
821  */
822 using std::isnan;
823 using std::isinf;
824 using std::isfinite;
825 using std::isnormal;
826 using std::cbrt;
827 using std::hypot;
828 using vnl_math::angle_0_to_2pi;
829 using vnl_math::angle_minuspi_to_pi;
830 using vnl_math::rnd_halfinttoeven;
831 using vnl_math::rnd_halfintup;
832 using vnl_math::rnd;
833 using vnl_math::floor;
834 using vnl_math::ceil;
835 using vnl_math::sgn;
836 using vnl_math::sgn0;
837 using vnl_math::remainder_truncated;
838 using vnl_math::remainder_floored;
839 using vnl_math::abs;
840 using vnl_math::sqr;
841 using vnl_math::cube;
842 using vnl_math::squared_magnitude;
843 
844 } // end namespace Math
845 } // end namespace itk
846 
847 #endif // end of itkMath.h
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(double x1, double x2)
Definition: itkMath.h:360
itk::Math::FloatAddULP
T FloatAddULP(T x, typename Detail::FloatIEEE< T >::IntType ulps)
Add the given ULPs (units in the last place) to a float.
Definition: itkMath.h:270
itk::Math::GreatestPrimeFactor
ITKCommon_EXPORT unsigned short GreatestPrimeFactor(unsigned short n)
itk::Math::Detail::AlmostEqualsUnsignedVsSigned::AlmostEqualsFunction
static bool AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
Definition: itkMath.h:425
itk::Math::euler
static constexpr double euler
euler constant
Definition: itkMath.h:92
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
Definition: itkMath.h:353
itk::Math::sqrt1_2
static constexpr double sqrt1_2
Definition: itkMath.h:88
itk::Math::Detail::FloatIEEE::FloatType
T FloatType
Definition: itkMathDetail.h:492
itk::Math::Detail::AlmostEqualsSignedVsUnsigned::AlmostEqualsFunction
static bool AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
Definition: itkMath.h:411
itk::Math::Detail::AlmostEqualsSignedVsUnsigned
Definition: itkMath.h:407
itk::Math::sqrt1_3
static constexpr double sqrt1_3
Definition: itkMath.h:90
itk::Math::Detail::FloatIEEE::IntType
typename FloatIEEETraits< T >::IntType IntType
Definition: itkMathDetail.h:493
itk::Math::Round
TReturn Round(TInput x)
Round towards nearest integer (This is a synonym for RoundHalfIntegerUp)
Definition: itkMath.h:178
itkMathDetail.h
itk::Math::one_over_sqrt2pi
static constexpr double one_over_sqrt2pi
Definition: itkMath.h:84
itk::Math::Detail::AlmostEqualsFunctionSelector::SelectedVersion
AlmostEqualsPlainOldEquals SelectedVersion
Definition: itkMath.h:447
itk::Math::Detail::FloatIEEE
Definition: itkMathDetail.h:490
itk::Math::Detail::AlmostEqualsFloatVsFloat
Definition: itkMath.h:349
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:723
itk::Math::Detail::AlmostEqualsIntegerVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
Definition: itkMath.h:401
itkConceptChecking.h
itk::Math::Detail::FloatIEEE::AsULP
IntType AsULP() const
Definition: itkMathDetail.h:512
itk::Math::RoundHalfIntegerUp
RoundHalfIntegerUp(TInput x)
Round towards nearest integer.
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itkTemplateFloatingToIntegerMacro
#define itkTemplateFloatingToIntegerMacro(name)
Definition: itkMath.h:104
itk::Math::pi_over_4
static constexpr double pi_over_4
Definition: itkMath.h:70
itk::Math::sqrt2pi
static constexpr double sqrt2pi
Definition: itkMath.h:80
itk::Concept::IsInteger
Definition: itkConceptChecking.h:875
itk::Math::float_eps
static constexpr float float_eps
Definition: itkMath.h:98
itk::Math::eps
static constexpr double eps
Definition: itkMath.h:95
itk::Math::two_over_sqrtpi
static constexpr double two_over_sqrtpi
Definition: itkMath.h:82
itk::Math::one_over_pi
static constexpr double one_over_pi
Definition: itkMath.h:74
itk::Math::Detail::AlmostEqualsPlainOldEquals
Definition: itkMath.h:431
itk::Math::log10e
static constexpr double log10e
Definition: itkMath.h:58
itk::Math::ln10
static constexpr double ln10
Definition: itkMath.h:62
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(double x1, float x2)
Definition: itkMath.h:367
itk::Math::RoundHalfIntegerToEven
RoundHalfIntegerToEven(TInput x)
Round towards nearest integer.
itk::Math::Detail::AlmostEqualsUnsignedVsSigned
Definition: itkMath.h:421
itk::Math::Floor
Floor(TInput x)
Round towards minus infinity.
itk::Math::UnsignedPower
constexpr TReturnType UnsignedPower(const std::uintmax_t base, const std::uintmax_t exponent) noexcept
Definition: itkMath.h:802
itk::Math::log2e
static constexpr double log2e
Definition: itkMath.h:56
itk::Math::NotAlmostEquals
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:693
itk::Math::CastWithRangeCheck
TReturn CastWithRangeCheck(TInput x)
Definition: itkMath.h:213
itk::Math::Detail::FloatIEEE::asInt
IntType asInt
Definition: itkMathDetail.h:497
itk::Math::FloatAlmostEqual
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())
Compare two floats and return if they are effectively equal.
Definition: itkMath.h:309
itk::Math::pi_over_2
static constexpr double pi_over_2
Definition: itkMath.h:68
itk::uintmax_t
::uintmax_t uintmax_t
Definition: itkIntTypes.h:56
itk::Math::pi_over_180
static constexpr double pi_over_180
Definition: itkMath.h:72
ITK_X_ASSERT
#define ITK_X_ASSERT(CHECK)
Definition: itkMath.h:772
itk::Math::Detail::AlmostEqualsFloatVsInteger
Definition: itkMath.h:387
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::Math::sqrt2
static constexpr double sqrt2
Definition: itkMath.h:86
itk::Math::deg_per_rad
static constexpr double deg_per_rad
Definition: itkMath.h:78
itk::Math::IsPrime
ITKCommon_EXPORT bool IsPrime(unsigned short n)
itk::Math::Detail::AlmostEqualsFloatVsInteger::AlmostEqualsFunction
static bool AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
Definition: itkMath.h:391
itk::Math::float_sqrteps
static constexpr float float_sqrteps
Definition: itkMath.h:99
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::Math::Detail::AlmostEqualsPlainOldEquals::AlmostEqualsFunction
static bool AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
Definition: itkMath.h:435
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(float x1, double x2)
Definition: itkMath.h:374
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits::IsComplex
static constexpr bool IsComplex
Definition: itkNumericTraits.h:143
itk::Math::Ceil
Ceil(TInput x)
Round towards plus infinity.
itk::Math::two_over_pi
static constexpr double two_over_pi
Definition: itkMath.h:76
itk::Math::UnsignedProduct
constexpr TReturnType UnsignedProduct(const std::uintmax_t a, const std::uintmax_t b) noexcept
Definition: itkMath.h:780
itk::Math::AlmostEquals
bool AlmostEquals(T1 x1, T2 x2)
Provide consistent equality checks between values of potentially different scalar or complex types.
Definition: itkMath.h:685
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(float x1, float x2)
Definition: itkMath.h:381
itk::Math::Detail::AlmostEqualsIntegerVsFloat
Definition: itkMath.h:397
itk::Math::pi
static constexpr double pi
Definition: itkMath.h:64
itk::Math::FloatDifferenceULP
Detail::FloatIEEE< T >::IntType FloatDifferenceULP(T x1, T x2)
Return the signed distance in ULPs (units in the last place) between two floats.
Definition: itkMath.h:254
itk::Math::twopi
static constexpr double twopi
Definition: itkMath.h:66
itk::Math::Detail::FloatIEEE::asFloat
FloatType asFloat
Definition: itkMathDetail.h:496
itk::Math::sqrteps
static constexpr double sqrteps
Definition: itkMath.h:96
itk::Math::ln2
static constexpr double ln2
Definition: itkMath.h:60
itk::Math::Detail::AlmostEqualsFunctionSelector
Definition: itkMath.h:445