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