ITK  5.4.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  * https://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 
44 namespace itk
45 {
46 namespace Math
47 {
48 // These constants originate from VXL's vnl_math.h. They have been
49 // moved here to improve visibility, and to ensure that the constants
50 // are available during compile time ( as opposed to static ITK_CONSTEXPR
51 // member variables ).
52 
53 
55 static constexpr double e = vnl_math::e;
57 static constexpr double log2e = vnl_math::log2e;
59 static constexpr double log10e = vnl_math::log10e;
61 static constexpr double ln2 = vnl_math::ln2;
63 static constexpr double ln10 = vnl_math::ln10;
65 static constexpr double pi = vnl_math::pi;
67 static constexpr double twopi = vnl_math::twopi;
69 static constexpr double pi_over_2 = vnl_math::pi_over_2;
71 static constexpr double pi_over_4 = vnl_math::pi_over_4;
73 static constexpr double pi_over_180 = vnl_math::pi_over_180;
75 static constexpr double one_over_pi = vnl_math::one_over_pi;
77 static constexpr double two_over_pi = vnl_math::two_over_pi;
79 static constexpr double deg_per_rad = vnl_math::deg_per_rad;
81 static constexpr double sqrt2pi = vnl_math::sqrt2pi;
83 static constexpr double two_over_sqrtpi = vnl_math::two_over_sqrtpi;
85 static constexpr double one_over_sqrt2pi = vnl_math::one_over_sqrt2pi;
87 static constexpr double sqrt2 = vnl_math::sqrt2;
89 static constexpr double sqrt1_2 = vnl_math::sqrt1_2;
91 static constexpr double sqrt1_3 = vnl_math::sqrt1_3;
93 static constexpr double euler = vnl_math::euler;
94 
95 //: IEEE double machine precision
96 static constexpr double eps = vnl_math::eps;
97 static constexpr double sqrteps = vnl_math::sqrteps;
98 //: IEEE single machine precision
99 static constexpr float float_eps = vnl_math::float_eps;
100 static constexpr float float_sqrteps = vnl_math::float_sqrteps;
101 
105 #define itkTemplateFloatingToIntegerMacro(name) \
106  template <typename TReturn, typename TInput> \
107  inline TReturn name(TInput x) \
108  { \
109  \
110  if (sizeof(TReturn) <= 4) \
111  { \
112  return static_cast<TReturn>(Detail::name##_32(x)); \
113  } \
114  else if (sizeof(TReturn) <= 8) \
115  { \
116  return static_cast<TReturn>(Detail::name##_64(x)); \
117  } \
118  else \
119  { \
120  return static_cast<TReturn>(Detail::name##_base<TReturn, TInput>(x)); \
121  } \
122  }
123 
145 
169 
177 template <typename TReturn, typename TInput>
178 inline TReturn
179 Round(TInput x)
180 {
181  return RoundHalfIntegerUp<TReturn, TInput>(x);
182 }
183 
197 
209 
210 #undef itkTemplateFloatingToIntegerMacro
211 
212 template <typename TReturn, typename TInput>
213 inline TReturn
215 {
216 #ifdef ITK_USE_CONCEPT_CHECKING
217  itkConceptMacro(OnlyDefinedForIntegerTypes1, (itk::Concept::IsInteger<TReturn>));
218  itkConceptMacro(OnlyDefinedForIntegerTypes2, (itk::Concept::IsInteger<TInput>));
219 #endif // ITK_USE_CONCEPT_CHECKING
220 
221  auto ret = static_cast<TReturn>(x);
222  if (sizeof(TReturn) > sizeof(TInput) &&
224  {
225  // if the output type is bigger and we are not converting a signed
226  // integer to an unsigned integer then we have no problems
227  return ret;
228  }
229  else if (sizeof(TReturn) >= sizeof(TInput))
230  {
232  {
233  itk::RangeError _e(__FILE__, __LINE__);
234  throw _e;
235  }
236  }
237  else if (static_cast<TInput>(ret) != x ||
239  {
240  itk::RangeError _e(__FILE__, __LINE__);
241  throw _e;
242  }
243  return ret;
244 }
245 
253 template <typename T>
254 inline typename Detail::FloatIEEE<T>::IntType
256 {
257  Detail::FloatIEEE<T> x1f(x1);
258  Detail::FloatIEEE<T> x2f(x2);
259  return x1f.AsULP() - x2f.AsULP();
260 }
261 
269 template <typename T>
270 inline T
272 {
273  Detail::FloatIEEE<T> representInput(x);
274  Detail::FloatIEEE<T> representOutput(representInput.asInt + ulps);
275  return representOutput.asFloat;
276 }
277 
308 template <typename T>
309 inline bool
311  T x2,
312  typename Detail::FloatIEEE<T>::IntType maxUlps = 4,
313  typename Detail::FloatIEEE<T>::FloatType maxAbsoluteDifference = 0.1 *
315 {
316  // Check if the numbers are really close -- needed
317  // when comparing numbers near zero.
318  const T absDifference = std::abs(x1 - x2);
319  if (absDifference <= maxAbsoluteDifference)
320  {
321  return true;
322  }
323 
324  // This check for different signs is necessary for several reasons, see the blog link above.
325  // Subtracting the signed-magnitude representation of floats using twos-complement
326  // math isn't particularly meaningful, and the subtraction would produce a 33-bit
327  // result and overflow an int.
328  if (std::signbit(x1) != std::signbit(x2))
329  {
330  return false;
331  }
332 
333  typename Detail::FloatIEEE<T>::IntType ulps = FloatDifferenceULP(x1, x2);
334  if (ulps < 0)
335  {
336  ulps = -ulps;
337  }
338  return ulps <= maxUlps;
339 }
340 
341 // The following code cannot be moved to the itkMathDetail.h file without introducing circular dependencies
342 namespace Detail // The Detail namespace holds the templates used by AlmostEquals
343 {
344 // The following structs and templates are used to choose
345 // which version of the AlmostEquals function
346 // should be implemented base on input parameter types
347 
348 // Structs for choosing AlmostEquals function
349 
351 {
352  template <typename TFloatType1, typename TFloatType2>
353  static bool
354  AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
355  {
356  return FloatAlmostEqual<double>(x1, x2);
357  }
358 
359  template <typename TFloatType1, typename TFloatType2>
360  static bool
361  AlmostEqualsFunction(double x1, double x2)
362  {
363  return FloatAlmostEqual<double>(x1, x2);
364  }
365 
366  template <typename TFloatType1, typename TFloatType2>
367  static bool
368  AlmostEqualsFunction(double x1, float x2)
369  {
370  return FloatAlmostEqual<float>(x1, x2);
371  }
372 
373  template <typename TFloatType1, typename TFloatType2>
374  static bool
375  AlmostEqualsFunction(float x1, double x2)
376  {
377  return FloatAlmostEqual<float>(x1, x2);
378  }
379 
380  template <typename TFloatType1, typename TFloatType2>
381  static bool
382  AlmostEqualsFunction(float x1, float x2)
383  {
384  return FloatAlmostEqual<float>(x1, x2);
385  }
386 };
387 
389 {
390  template <typename TFloatType, typename TIntType>
391  static bool
392  AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
393  {
394  return FloatAlmostEqual<TFloatType>(floatingVariable, integerVariable);
395  }
396 };
397 
399 {
400  template <typename TIntType, typename TFloatType>
401  static bool
402  AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
403  {
404  return AlmostEqualsFloatVsInteger::AlmostEqualsFunction(floatingVariable, integerVariable);
405  }
406 };
407 
409 {
410  template <typename TSignedInt, typename TUnsignedInt>
411  static bool
412  AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
413  {
414  if (signedVariable < 0)
415  {
416  return false;
417  }
418  if (unsignedVariable > static_cast<size_t>(itk::NumericTraits<TSignedInt>::max()))
419  {
420  return false;
421  }
422  return signedVariable == static_cast<TSignedInt>(unsignedVariable);
423  }
424 };
425 
427 {
428  template <typename TUnsignedInt, typename TSignedInt>
429  static bool
430  AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
431  {
432  return AlmostEqualsSignedVsUnsigned::AlmostEqualsFunction(signedVariable, unsignedVariable);
433  }
434 };
435 
437 {
438  template <typename TIntegerType1, typename TIntegerType2>
439  static bool
440  AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
441  {
442  return x1 == x2;
443  }
444 };
445 // end of structs that choose the specific AlmostEquals function
446 
447 // Selector structs, these select the correct case based on its types
448 // input1 is int? input 1 is signed? input2 is int? input 2 is signed?
449 template <bool TInput1IsIntger, bool TInput1IsSigned, bool TInput2IsInteger, bool TInput2IsSigned>
451 { // default case
453 };
454 
456 template <>
457 struct AlmostEqualsFunctionSelector<false, true, false, true>
458 // floating type v floating type
459 {
461 };
462 
463 template <>
464 struct AlmostEqualsFunctionSelector<false, true, true, true>
465 // float vs int
466 {
467  using SelectedVersion = AlmostEqualsFloatVsInteger;
468 };
469 
470 template <>
471 struct AlmostEqualsFunctionSelector<false, true, true, false>
472 // float vs unsigned int
473 {
474  using SelectedVersion = AlmostEqualsFloatVsInteger;
475 };
476 
477 template <>
478 struct AlmostEqualsFunctionSelector<true, false, false, true>
479 // unsigned int vs float
480 {
481  using SelectedVersion = AlmostEqualsIntegerVsFloat;
482 };
483 
484 template <>
485 struct AlmostEqualsFunctionSelector<true, true, false, true>
486 // int vs float
487 {
488  using SelectedVersion = AlmostEqualsIntegerVsFloat;
489 };
490 
491 template <>
492 struct AlmostEqualsFunctionSelector<true, true, true, false>
493 // signed vs unsigned
494 {
495  using SelectedVersion = AlmostEqualsSignedVsUnsigned;
496 };
497 
498 template <>
499 struct AlmostEqualsFunctionSelector<true, false, true, true>
500 // unsigned vs signed
501 {
502  using SelectedVersion = AlmostEqualsUnsignedVsSigned;
503 };
504 
505 template <>
506 struct AlmostEqualsFunctionSelector<true, true, true, true>
507 // signed vs signed
508 {
509  using SelectedVersion = AlmostEqualsPlainOldEquals;
510 };
511 
512 template <>
513 struct AlmostEqualsFunctionSelector<true, false, true, false>
514 // unsigned vs unsigned
515 {
516  using SelectedVersion = AlmostEqualsPlainOldEquals;
517 };
518 // end of AlmostEqualsFunctionSelector structs
519 
520 // The implementor tells the selector what to do
521 template <typename TInputType1, typename TInputType2>
522 struct AlmostEqualsScalarImplementer
523 {
524  static constexpr bool TInputType1IsInteger = std::is_integral_v<TInputType1>;
525  static constexpr bool TInputType1IsSigned = std::is_signed_v<TInputType1>;
526  static constexpr bool TInputType2IsInteger = std::is_integral_v<TInputType2>;
527  static constexpr bool TInputType2IsSigned = std::is_signed_v<TInputType2>;
528 
529  using SelectedVersion = typename AlmostEqualsFunctionSelector<TInputType1IsInteger,
530  TInputType1IsSigned,
531  TInputType2IsInteger,
532  TInputType2IsSigned>::SelectedVersion;
533 };
534 
535 // The AlmostEqualsScalarComparer returns the result of an
536 // approximate comparison between two scalar values of
537 // potentially different data types.
538 template <typename TScalarType1, typename TScalarType2>
539 inline bool
540 AlmostEqualsScalarComparer(TScalarType1 x1, TScalarType2 x2)
541 {
542  return AlmostEqualsScalarImplementer<TScalarType1, TScalarType2>::SelectedVersion::
543  template AlmostEqualsFunction<TScalarType1, TScalarType2>(x1, x2);
544 }
545 
546 // The following structs are used to evaluate approximate comparisons between
547 // complex and scalar values of potentially different types.
548 
549 // Comparisons between scalar types use the AlmostEqualsScalarComparer function.
550 struct AlmostEqualsScalarVsScalar
551 {
552  template <typename TScalarType1, typename TScalarType2>
553  static bool
554  AlmostEqualsFunction(TScalarType1 x1, TScalarType2 x2)
555  {
556  return AlmostEqualsScalarComparer(x1, x2);
557  }
558 };
559 
560 // Comparisons between two complex values compare the real and imaginary components
561 // separately with the AlmostEqualsScalarComparer function.
562 struct AlmostEqualsComplexVsComplex
563 {
564  template <typename TComplexType1, typename TComplexType2>
565  static bool
566  AlmostEqualsFunction(TComplexType1 x1, TComplexType2 x2)
567  {
568  return AlmostEqualsScalarComparer(x1.real(), x2.real()) && AlmostEqualsScalarComparer(x1.imag(), x2.imag());
569  }
570 };
571 
572 // Comparisons between complex and scalar values first check to see if the imaginary component
573 // of the complex value is approximately 0. Then a ScalarComparison is done between the real
574 // part of the complex number and the scalar value.
575 struct AlmostEqualsScalarVsComplex
576 {
577  template <typename TScalarType, typename TComplexType>
578  static bool
579  AlmostEqualsFunction(TScalarType scalarVariable, TComplexType complexVariable)
580  {
581  if (!AlmostEqualsScalarComparer(
582  complexVariable.imag(),
584  {
585  return false;
586  }
587  return AlmostEqualsScalarComparer(scalarVariable, complexVariable.real());
588  }
589 };
590 
591 struct AlmostEqualsComplexVsScalar
592 {
593  template <typename TComplexType, typename TScalarType>
594  static bool
595  AlmostEqualsFunction(TComplexType complexVariable, TScalarType scalarVariable)
596  {
597  return AlmostEqualsScalarVsComplex::AlmostEqualsFunction(scalarVariable, complexVariable);
598  }
599 };
600 
601 // The AlmostEqualsComplexChooser structs choose the correct case
602 // from the input parameter types' IsComplex property
603 // The default case is scalar vs scalar
604 template <bool T1IsComplex, bool T2IsComplex> // Default is false, false
605 struct AlmostEqualsComplexChooser
606 {
607  using ChosenVersion = AlmostEqualsScalarVsScalar;
608 };
609 
610 template <>
611 struct AlmostEqualsComplexChooser<true, true>
612 {
613  using ChosenVersion = AlmostEqualsComplexVsComplex;
614 };
615 
616 template <>
617 struct AlmostEqualsComplexChooser<false, true>
618 {
619  using ChosenVersion = AlmostEqualsScalarVsComplex;
620 };
621 
622 template <>
623 struct AlmostEqualsComplexChooser<true, false>
624 {
625  using ChosenVersion = AlmostEqualsComplexVsScalar;
626 };
627 // End of AlmostEqualsComplexChooser structs.
628 
629 // The AlmostEqualsComplexImplementer determines which of the input
630 // parameters are complex and which are real, and sends that information
631 // to the AlmostEqualsComplexChooser structs to determine the proper
632 // type of evaluation.
633 template <typename T1, typename T2>
634 struct AlmostEqualsComplexImplementer
635 {
636  static constexpr bool T1IsComplex = NumericTraits<T1>::IsComplex;
637  static constexpr bool T2IsComplex = NumericTraits<T2>::IsComplex;
638 
639  using ChosenVersion = typename AlmostEqualsComplexChooser<T1IsComplex, T2IsComplex>::ChosenVersion;
640 };
642 
643 } // end namespace Detail
644 
687 // The AlmostEquals function
688 template <typename T1, typename T2>
689 inline bool
690 AlmostEquals(T1 x1, T2 x2)
691 {
692  return Detail::AlmostEqualsComplexImplementer<T1, T2>::ChosenVersion::AlmostEqualsFunction(x1, x2);
693 }
694 
695 // The NotAlmostEquals function
696 template <typename T1, typename T2>
697 inline bool
698 NotAlmostEquals(T1 x1, T2 x2)
699 {
700  return !AlmostEquals(x1, x2);
701 }
702 
703 
725 // The ExactlyEquals function
726 template <typename TInput1, typename TInput2>
727 inline bool
728 ExactlyEquals(const TInput1 & x1, const TInput2 & x2)
729 {
730  CLANG_PRAGMA_PUSH
731  CLANG_SUPPRESS_Wfloat_equal return x1 == x2;
732  CLANG_PRAGMA_POP
733 }
734 
735 // The NotExactlyEquals function
736 template <typename TInput1, typename TInput2>
737 inline bool
738 NotExactlyEquals(const TInput1 & x1, const TInput2 & x2)
739 {
740  return !ExactlyEquals(x1, x2);
741 }
742 
743 
748 ITKCommon_EXPORT bool
749 IsPrime(unsigned short n);
750 ITKCommon_EXPORT bool
751 IsPrime(unsigned int n);
752 ITKCommon_EXPORT bool
753 IsPrime(unsigned long n);
754 ITKCommon_EXPORT bool
755 IsPrime(unsigned long long n);
760 ITKCommon_EXPORT unsigned short
761 GreatestPrimeFactor(unsigned short n);
762 ITKCommon_EXPORT unsigned int
763 GreatestPrimeFactor(unsigned int n);
764 ITKCommon_EXPORT unsigned long
765 GreatestPrimeFactor(unsigned long n);
766 ITKCommon_EXPORT unsigned long long
767 GreatestPrimeFactor(unsigned long long n);
770 // C++11 does not guarantee that assert can be used in constexpr
771 // functions. This is a work-around for GCC 4.8, 4.9. Originating
772 // from Andrzej's C++ blog:
773 // https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
774 #if defined NDEBUG
775 # define ITK_X_ASSERT(CHECK) void(0)
776 #else
777 # define ITK_X_ASSERT(CHECK) ((CHECK) ? void(0) : [] { assert(!#CHECK); }())
778 #endif
779 
783 template <typename TReturnType = uintmax_t>
784 constexpr TReturnType
785 UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
786 {
787  static_assert(std::is_unsigned_v<TReturnType>, "UnsignedProduct only supports unsigned return types");
788 
789  // Note that numeric overflow is not "undefined behavior", for unsigned numbers.
790  // This function checks if the result of a*b is mathematically correct.
791  return (a == 0) || (b == 0) ||
792  (((static_cast<TReturnType>(a * b) / a) == b) && ((static_cast<TReturnType>(a * b) / b) == a))
793  ? static_cast<TReturnType>(a * b)
794  : (ITK_X_ASSERT(!"UnsignedProduct overflow!"), 0);
795 }
796 
797 
805 template <typename TReturnType = uintmax_t>
806 constexpr TReturnType
807 UnsignedPower(const uintmax_t base, const uintmax_t exponent) noexcept
808 {
809  static_assert(std::is_unsigned_v<TReturnType>, "UnsignedPower only supports unsigned return types");
810 
811  // Uses recursive function calls because C++11 does not support other ways of
812  // iterations for a constexpr function.
813  return (exponent == 0)
814  ? (ITK_X_ASSERT(base > 0), 1)
815  : (exponent == 1) ? base
816  : UnsignedProduct<TReturnType>(UnsignedPower<TReturnType>(base, exponent / 2),
817  UnsignedPower<TReturnType>(base, (exponent + 1) / 2));
818 }
819 
820 #undef ITK_X_ASSERT
821 
822 
823 /*==========================================
824  * Alias the vnl_math functions in the itk::Math
825  * namespace. If possible, use the std:: equivalents
826  */
827 using std::isnan;
828 using std::isinf;
829 using std::isfinite;
830 using std::isnormal;
831 using std::cbrt;
832 using std::hypot;
833 using vnl_math::angle_0_to_2pi;
834 using vnl_math::angle_minuspi_to_pi;
835 using vnl_math::rnd_halfinttoeven;
836 using vnl_math::rnd_halfintup;
837 using vnl_math::rnd;
838 using vnl_math::floor;
839 using vnl_math::ceil;
840 using vnl_math::sgn;
841 using vnl_math::sgn0;
842 using vnl_math::remainder_truncated;
843 using vnl_math::remainder_floored;
844 using vnl_math::sqr;
845 using vnl_math::cube;
846 using vnl_math::squared_magnitude;
847 
848 
849 /*============================================
850 Decouple dependence and exposure of vnl_math::abs operations
851 in ITK. Placing this small amount of duplicate vnl_math
852 code directly in ITK removes backward compatibility
853 issues with system installed VXL versions.
854 */
855 inline bool
856 abs(bool x)
857 {
858  return x;
859 }
860 inline unsigned char
861 abs(unsigned char x)
862 {
863  return x;
864 }
865 inline unsigned char
866 abs(signed char x)
867 {
868  return x < 0 ? static_cast<unsigned char>(-x) : x;
869 }
870 inline unsigned char
871 abs(char x)
872 {
873  return static_cast<unsigned char>(x);
874 }
875 inline unsigned short
876 abs(short x)
877 {
878  return x < 0 ? static_cast<unsigned short>(-x) : x;
879 }
880 inline unsigned short
881 abs(unsigned short x)
882 {
883  return x;
884 }
885 inline unsigned int
886 abs(unsigned int x)
887 {
888  return x;
889 }
890 inline unsigned long
891 abs(unsigned long x)
892 {
893  return x;
894 }
895 // long long - target type will have width of at least 64 bits. (since C++11)
896 inline unsigned long long
897 abs(unsigned long long x)
898 {
899  return x;
900 }
901 
902 using std::abs;
903 
904 } // end namespace Math
905 } // end namespace itk
906 
907 #endif // end of itkMath.h
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(double x1, double x2)
Definition: itkMath.h:361
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:271
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:430
itk::Math::euler
static constexpr double euler
euler constant
Definition: itkMath.h:93
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
Definition: itkMath.h:354
itk::Math::sqrt1_2
static constexpr double sqrt1_2
Definition: itkMath.h:89
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:412
itk::Math::Detail::AlmostEqualsSignedVsUnsigned
Definition: itkMath.h:408
itk::Math::sqrt1_3
static constexpr double sqrt1_3
Definition: itkMath.h:91
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:179
itkMathDetail.h
itk::Math::one_over_sqrt2pi
static constexpr double one_over_sqrt2pi
Definition: itkMath.h:85
itk::Math::Detail::AlmostEqualsFunctionSelector::SelectedVersion
AlmostEqualsPlainOldEquals SelectedVersion
Definition: itkMath.h:452
itk::Math::UnsignedProduct
constexpr TReturnType UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
Definition: itkMath.h:785
itk::Math::Detail::FloatIEEE
Definition: itkMathDetail.h:490
itk::Math::Detail::AlmostEqualsFloatVsFloat
Definition: itkMath.h:350
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:728
itk::Math::Detail::AlmostEqualsIntegerVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
Definition: itkMath.h:402
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:738
itkTemplateFloatingToIntegerMacro
#define itkTemplateFloatingToIntegerMacro(name)
Definition: itkMath.h:105
itk::Math::pi_over_4
static constexpr double pi_over_4
Definition: itkMath.h:71
itk::Math::abs
bool abs(bool x)
Definition: itkMath.h:856
itk::Math::sqrt2pi
static constexpr double sqrt2pi
Definition: itkMath.h:81
itk::Concept::IsInteger
Definition: itkConceptChecking.h:875
itk::Math::float_eps
static constexpr float float_eps
Definition: itkMath.h:99
itk::Math::eps
static constexpr double eps
Definition: itkMath.h:96
itk::Math::two_over_sqrtpi
static constexpr double two_over_sqrtpi
Definition: itkMath.h:83
itk::Math::one_over_pi
static constexpr double one_over_pi
Definition: itkMath.h:75
itk::Math::Detail::AlmostEqualsPlainOldEquals
Definition: itkMath.h:436
itk::Math::log10e
static constexpr double log10e
Definition: itkMath.h:59
itk::Math::ln10
static constexpr double ln10
Definition: itkMath.h:63
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(double x1, float x2)
Definition: itkMath.h:368
itk::Math::RoundHalfIntegerToEven
RoundHalfIntegerToEven(TInput x)
Round towards nearest integer.
itk::Math::Detail::AlmostEqualsUnsignedVsSigned
Definition: itkMath.h:426
itk::Math::Floor
Floor(TInput x)
Round towards minus infinity.
itk::Math::log2e
static constexpr double log2e
Definition: itkMath.h:57
itk::Math::NotAlmostEquals
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:698
itk::Math::CastWithRangeCheck
TReturn CastWithRangeCheck(TInput x)
Definition: itkMath.h:214
itk::Math::UnsignedPower
constexpr TReturnType UnsignedPower(const uintmax_t base, const uintmax_t exponent) noexcept
Definition: itkMath.h:807
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:310
itk::Math::pi_over_2
static constexpr double pi_over_2
Definition: itkMath.h:69
itk::Math::pi_over_180
static constexpr double pi_over_180
Definition: itkMath.h:73
ITK_X_ASSERT
#define ITK_X_ASSERT(CHECK)
Definition: itkMath.h:777
itk::Math::Detail::AlmostEqualsFloatVsInteger
Definition: itkMath.h:388
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::Math::sqrt2
static constexpr double sqrt2
Definition: itkMath.h:87
itk::Math::deg_per_rad
static constexpr double deg_per_rad
Definition: itkMath.h:79
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:392
itk::Math::float_sqrteps
static constexpr float float_sqrteps
Definition: itkMath.h:100
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::Math::Detail::AlmostEqualsPlainOldEquals::AlmostEqualsFunction
static bool AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
Definition: itkMath.h:440
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(float x1, double x2)
Definition: itkMath.h:375
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:144
itk::Math::Ceil
Ceil(TInput x)
Round towards plus infinity.
itk::Math::two_over_pi
static constexpr double two_over_pi
Definition: itkMath.h:77
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:690
itk::Math::e
static constexpr double e
Definition: itkMath.h:55
itk::Math::abs
unsigned long long abs(unsigned long long x)
Definition: itkMath.h:897
itk::Math::Detail::AlmostEqualsFloatVsFloat::AlmostEqualsFunction
static bool AlmostEqualsFunction(float x1, float x2)
Definition: itkMath.h:382
itk::Math::Detail::AlmostEqualsIntegerVsFloat
Definition: itkMath.h:398
itk::Math::pi
static constexpr double pi
Definition: itkMath.h:65
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:255
itk::Math::twopi
static constexpr double twopi
Definition: itkMath.h:67
itk::Math::Detail::FloatIEEE::asFloat
FloatType asFloat
Definition: itkMathDetail.h:496
itk::Math::sqrteps
static constexpr double sqrteps
Definition: itkMath.h:97
itk::Math::ln2
static constexpr double ln2
Definition: itkMath.h:61
itk::Math::Detail::AlmostEqualsFunctionSelector
Definition: itkMath.h:450