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