ITK  6.0.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
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;
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 }
145
146
169
177template <typename TReturn, typename TInput>
178inline TReturn
179Round(TInput x)
180{
181 return RoundHalfIntegerUp<TReturn, TInput>(x);
182}
183
197
198
209
210#undef itkTemplateFloatingToIntegerMacro
211
212template <typename TReturn, typename TInput>
213inline 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 constexpr (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 constexpr (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
253template <typename T>
254inline 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
269template <typename T>
270inline T
272{
273 Detail::FloatIEEE<T> representInput(x);
274 Detail::FloatIEEE<T> representOutput(representInput.asInt + ulps);
275 return representOutput.asFloat;
276}
277
308template <typename T>
309inline 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
334 return ulps <= maxUlps;
335}
336
337// The following code cannot be moved to the itkMathDetail.h file without introducing circular dependencies
338namespace Detail // The Detail namespace holds the templates used by AlmostEquals
339{
340// The following structs and templates are used to choose
341// which version of the AlmostEquals function
342// should be implemented base on input parameter types
343
344// Structs for choosing AlmostEquals function
345
347{
348 template <typename TFloatType1, typename TFloatType2>
349 static bool
350 AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
351 {
352 return FloatAlmostEqual<double>(x1, x2);
353 }
354
355 template <typename TFloatType1, typename TFloatType2>
356 static bool
357 AlmostEqualsFunction(double x1, double x2)
358 {
359 return FloatAlmostEqual<double>(x1, x2);
360 }
361
362 template <typename TFloatType1, typename TFloatType2>
363 static bool
364 AlmostEqualsFunction(double x1, float x2)
365 {
366 return FloatAlmostEqual<float>(x1, x2);
367 }
368
369 template <typename TFloatType1, typename TFloatType2>
370 static bool
371 AlmostEqualsFunction(float x1, double x2)
372 {
373 return FloatAlmostEqual<float>(x1, x2);
374 }
375
376 template <typename TFloatType1, typename TFloatType2>
377 static bool
378 AlmostEqualsFunction(float x1, float x2)
379 {
380 return FloatAlmostEqual<float>(x1, x2);
381 }
382};
383
385{
386 template <typename TFloatType, typename TIntType>
387 static bool
388 AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
389 {
390 return FloatAlmostEqual<TFloatType>(floatingVariable, integerVariable);
391 }
392};
393
395{
396 template <typename TIntType, typename TFloatType>
397 static bool
398 AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
399 {
400 return AlmostEqualsFloatVsInteger::AlmostEqualsFunction(floatingVariable, integerVariable);
401 }
402};
403
405{
406 template <typename TSignedInt, typename TUnsignedInt>
407 static bool
408 AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
409 {
410 if (signedVariable < 0)
411 {
412 return false;
413 }
414 if (unsignedVariable > static_cast<size_t>(itk::NumericTraits<TSignedInt>::max()))
415 {
416 return false;
417 }
418 return signedVariable == static_cast<TSignedInt>(unsignedVariable);
419 }
420};
421
423{
424 template <typename TUnsignedInt, typename TSignedInt>
425 static bool
426 AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
427 {
428 return AlmostEqualsSignedVsUnsigned::AlmostEqualsFunction(signedVariable, unsignedVariable);
429 }
430};
431
433{
434 template <typename TIntegerType1, typename TIntegerType2>
435 static bool
436 AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
437 {
438 return x1 == x2;
439 }
440};
441// end of structs that choose the specific AlmostEquals function
442
443// Selector structs, these select the correct case based on its types
444// input1 is int? input 1 is signed? input2 is int? input 2 is signed?
445template <bool TInput1IsIntger, bool TInput1IsSigned, bool TInput2IsInteger, bool TInput2IsSigned>
447{ // default case
449};
450
452template <>
453struct AlmostEqualsFunctionSelector<false, true, false, true>
454// floating type v floating type
455{
457};
458
459template <>
460struct AlmostEqualsFunctionSelector<false, true, true, true>
461// float vs int
462{
463 using SelectedVersion = AlmostEqualsFloatVsInteger;
464};
465
466template <>
467struct AlmostEqualsFunctionSelector<false, true, true, false>
468// float vs unsigned int
469{
470 using SelectedVersion = AlmostEqualsFloatVsInteger;
471};
472
473template <>
474struct AlmostEqualsFunctionSelector<true, false, false, true>
475// unsigned int vs float
476{
477 using SelectedVersion = AlmostEqualsIntegerVsFloat;
478};
479
480template <>
481struct AlmostEqualsFunctionSelector<true, true, false, true>
482// int vs float
483{
484 using SelectedVersion = AlmostEqualsIntegerVsFloat;
485};
486
487template <>
488struct AlmostEqualsFunctionSelector<true, true, true, false>
489// signed vs unsigned
490{
491 using SelectedVersion = AlmostEqualsSignedVsUnsigned;
492};
493
494template <>
495struct AlmostEqualsFunctionSelector<true, false, true, true>
496// unsigned vs signed
497{
498 using SelectedVersion = AlmostEqualsUnsignedVsSigned;
499};
500
501template <>
502struct AlmostEqualsFunctionSelector<true, true, true, true>
503// signed vs signed
504{
505 using SelectedVersion = AlmostEqualsPlainOldEquals;
506};
507
508template <>
509struct AlmostEqualsFunctionSelector<true, false, true, false>
510// unsigned vs unsigned
511{
512 using SelectedVersion = AlmostEqualsPlainOldEquals;
513};
514// end of AlmostEqualsFunctionSelector structs
515
516// The implementor tells the selector what to do
517template <typename TInputType1, typename TInputType2>
518struct AlmostEqualsScalarImplementer
519{
520 static constexpr bool TInputType1IsInteger = std::is_integral_v<TInputType1>;
521 static constexpr bool TInputType1IsSigned = std::is_signed_v<TInputType1>;
522 static constexpr bool TInputType2IsInteger = std::is_integral_v<TInputType2>;
523 static constexpr bool TInputType2IsSigned = std::is_signed_v<TInputType2>;
524
525 using SelectedVersion = typename AlmostEqualsFunctionSelector<TInputType1IsInteger,
526 TInputType1IsSigned,
527 TInputType2IsInteger,
528 TInputType2IsSigned>::SelectedVersion;
529};
530
531// The AlmostEqualsScalarComparer returns the result of an
532// approximate comparison between two scalar values of
533// potentially different data types.
534template <typename TScalarType1, typename TScalarType2>
535inline bool
536AlmostEqualsScalarComparer(TScalarType1 x1, TScalarType2 x2)
537{
538 return AlmostEqualsScalarImplementer<TScalarType1, TScalarType2>::SelectedVersion::
539 template AlmostEqualsFunction<TScalarType1, TScalarType2>(x1, x2);
540}
541
542// The following structs are used to evaluate approximate comparisons between
543// complex and scalar values of potentially different types.
544
545// Comparisons between scalar types use the AlmostEqualsScalarComparer function.
546struct AlmostEqualsScalarVsScalar
547{
548 template <typename TScalarType1, typename TScalarType2>
549 static bool
550 AlmostEqualsFunction(TScalarType1 x1, TScalarType2 x2)
551 {
552 return AlmostEqualsScalarComparer(x1, x2);
553 }
554};
555
556// Comparisons between two complex values compare the real and imaginary components
557// separately with the AlmostEqualsScalarComparer function.
558struct AlmostEqualsComplexVsComplex
559{
560 template <typename TComplexType1, typename TComplexType2>
561 static bool
562 AlmostEqualsFunction(TComplexType1 x1, TComplexType2 x2)
563 {
564 return AlmostEqualsScalarComparer(x1.real(), x2.real()) && AlmostEqualsScalarComparer(x1.imag(), x2.imag());
565 }
566};
567
568// Comparisons between complex and scalar values first check to see if the imaginary component
569// of the complex value is approximately 0. Then a ScalarComparison is done between the real
570// part of the complex number and the scalar value.
571struct AlmostEqualsScalarVsComplex
572{
573 template <typename TScalarType, typename TComplexType>
574 static bool
575 AlmostEqualsFunction(TScalarType scalarVariable, TComplexType complexVariable)
576 {
577 if (!AlmostEqualsScalarComparer(complexVariable.imag(), typename itk::NumericTraits<TComplexType>::ValueType{}))
578 {
579 return false;
580 }
581 return AlmostEqualsScalarComparer(scalarVariable, complexVariable.real());
582 }
583};
584
585struct AlmostEqualsComplexVsScalar
586{
587 template <typename TComplexType, typename TScalarType>
588 static bool
589 AlmostEqualsFunction(TComplexType complexVariable, TScalarType scalarVariable)
590 {
591 return AlmostEqualsScalarVsComplex::AlmostEqualsFunction(scalarVariable, complexVariable);
592 }
593};
594
595// The AlmostEqualsComplexChooser structs choose the correct case
596// from the input parameter types' IsComplex property
597// The default case is scalar vs scalar
598template <bool T1IsComplex, bool T2IsComplex> // Default is false, false
599struct AlmostEqualsComplexChooser
600{
601 using ChosenVersion = AlmostEqualsScalarVsScalar;
602};
603
604template <>
605struct AlmostEqualsComplexChooser<true, true>
606{
607 using ChosenVersion = AlmostEqualsComplexVsComplex;
608};
609
610template <>
611struct AlmostEqualsComplexChooser<false, true>
612{
613 using ChosenVersion = AlmostEqualsScalarVsComplex;
614};
615
616template <>
617struct AlmostEqualsComplexChooser<true, false>
618{
619 using ChosenVersion = AlmostEqualsComplexVsScalar;
620};
621// End of AlmostEqualsComplexChooser structs.
622
623// The AlmostEqualsComplexImplementer determines which of the input
624// parameters are complex and which are real, and sends that information
625// to the AlmostEqualsComplexChooser structs to determine the proper
626// type of evaluation.
627template <typename T1, typename T2>
628struct AlmostEqualsComplexImplementer
629{
630 static constexpr bool T1IsComplex = NumericTraits<T1>::IsComplex;
631 static constexpr bool T2IsComplex = NumericTraits<T2>::IsComplex;
632
633 using ChosenVersion = typename AlmostEqualsComplexChooser<T1IsComplex, T2IsComplex>::ChosenVersion;
634};
636
637} // end namespace Detail
638
681// The AlmostEquals function
682template <typename T1, typename T2>
683inline bool
684AlmostEquals(T1 x1, T2 x2)
685{
686 return Detail::AlmostEqualsComplexImplementer<T1, T2>::ChosenVersion::AlmostEqualsFunction(x1, x2);
687}
688
689// The NotAlmostEquals function
690template <typename T1, typename T2>
691inline bool
692NotAlmostEquals(T1 x1, T2 x2)
693{
694 return !AlmostEquals(x1, x2);
695}
696
697
719// The ExactlyEquals function
720template <typename TInput1, typename TInput2>
721inline bool
722ExactlyEquals(const TInput1 & x1, const TInput2 & x2)
723{
724 ITK_GCC_PRAGMA_PUSH
725 ITK_GCC_SUPPRESS_Wfloat_equal
726 return x1 == x2;
727 ITK_GCC_PRAGMA_POP
728}
729
730// The NotExactlyEquals function
731template <typename TInput1, typename TInput2>
732inline bool
733NotExactlyEquals(const TInput1 & x1, const TInput2 & x2)
734{
735 return !ExactlyEquals(x1, x2);
736}
737
738
743ITKCommon_EXPORT bool
744IsPrime(unsigned short n);
745ITKCommon_EXPORT bool
746IsPrime(unsigned int n);
747ITKCommon_EXPORT bool
748IsPrime(unsigned long n);
749ITKCommon_EXPORT bool
750IsPrime(unsigned long long n);
755ITKCommon_EXPORT unsigned short
756GreatestPrimeFactor(unsigned short n);
757ITKCommon_EXPORT unsigned int
758GreatestPrimeFactor(unsigned int n);
759ITKCommon_EXPORT unsigned long
760GreatestPrimeFactor(unsigned long n);
761ITKCommon_EXPORT unsigned long long
762GreatestPrimeFactor(unsigned long long n);
769template <typename TReturnType = uintmax_t>
770constexpr TReturnType
771UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
772{
773 static_assert(std::is_unsigned_v<TReturnType>, "UnsignedProduct only supports unsigned return types");
774
775 // Note that numeric overflow is not "undefined behavior", for unsigned numbers.
776 // This function checks if the result of a*b is mathematically correct.
777 return (a == 0) || (b == 0) ||
778 (((static_cast<TReturnType>(a * b) / a) == b) && ((static_cast<TReturnType>(a * b) / b) == a))
779 ? static_cast<TReturnType>(a * b)
780 : (assert(!"UnsignedProduct overflow!"), 0);
781}
782
783
791template <typename TReturnType = uintmax_t>
792constexpr TReturnType
793UnsignedPower(const uintmax_t base, const uintmax_t exponent) noexcept
794{
795 static_assert(std::is_unsigned_v<TReturnType>, "UnsignedPower only supports unsigned return types");
796
797 // Uses recursive function calls because C++11 does not support other ways of
798 // iterations for a constexpr function.
799 return (exponent == 0)
800 ? (assert(base > 0), 1)
801 : (exponent == 1) ? base
802 : UnsignedProduct<TReturnType>(UnsignedPower<TReturnType>(base, exponent / 2),
803 UnsignedPower<TReturnType>(base, (exponent + 1) / 2));
804}
805
806
807/*==========================================
808 * Alias the vnl_math functions in the itk::Math
809 * namespace. If possible, use the std:: equivalents
810 */
811using std::isnan;
812using std::isinf;
813using std::isfinite;
814using std::isnormal;
815using std::cbrt;
816using std::hypot;
817using vnl_math::angle_0_to_2pi;
818using vnl_math::angle_minuspi_to_pi;
819using vnl_math::rnd_halfinttoeven;
820using vnl_math::rnd_halfintup;
821using vnl_math::rnd;
822using vnl_math::floor;
823using vnl_math::ceil;
824using vnl_math::sgn;
825using vnl_math::sgn0;
826using vnl_math::remainder_truncated;
827using vnl_math::remainder_floored;
828using vnl_math::sqr;
829using vnl_math::cube;
830using vnl_math::squared_magnitude;
831
832
833/*============================================
834Decouple dependence and exposure of vnl_math::abs operations
835in ITK. Placing this small amount of duplicate vnl_math
836code directly in ITK removes backward compatibility
837issues with system installed VXL versions.
838*/
839inline bool
840abs(bool x)
841{
842 return x;
843}
844inline unsigned char
845abs(unsigned char x)
846{
847 return x;
848}
849inline unsigned char
850abs(signed char x)
851{
852 return x < 0 ? static_cast<unsigned char>(-x) : x;
853}
854inline unsigned char
855abs(char x)
856{
857 return static_cast<unsigned char>(x);
858}
859inline unsigned short
860abs(short x)
861{
862 return x < 0 ? static_cast<unsigned short>(-x) : x;
863}
864inline unsigned short
865abs(unsigned short x)
866{
867 return x;
868}
869inline unsigned int
870abs(unsigned int x)
871{
872 return x;
873}
874inline unsigned long
875abs(unsigned long x)
876{
877 return x;
878}
879// long long - target type will have width of at least 64 bits. (since C++11)
880inline unsigned long long
881abs(unsigned long long x)
882{
883 return x;
884}
885
886using std::abs;
887
888} // end namespace Math
889} // end namespace itk
890
891#endif // end of itkMath.h
Define additional traits for native types such as int or float.
static bool IsPositive(T val)
static constexpr bool IsComplex
#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:255
bool AlmostEquals(T1 x1, T2 x2)
Provide consistent equality checks between values of potentially different scalar or complex types.
Definition: itkMath.h:684
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:722
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:692
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:793
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:840
static constexpr double sqrteps
Definition: itkMath.h:98
static constexpr double two_over_sqrtpi
Definition: itkMath.h:84
unsigned long long abs(unsigned long long x)
Definition: itkMath.h:881
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:271
constexpr TReturnType UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
Definition: itkMath.h:771
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:733
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:310
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:357
static bool AlmostEqualsFunction(float x1, double x2)
Definition: itkMath.h:371
static bool AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
Definition: itkMath.h:350
static bool AlmostEqualsFunction(double x1, float x2)
Definition: itkMath.h:364
static bool AlmostEqualsFunction(float x1, float x2)
Definition: itkMath.h:378
static bool AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
Definition: itkMath.h:388
AlmostEqualsPlainOldEquals SelectedVersion
Definition: itkMath.h:448
static bool AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
Definition: itkMath.h:398
static bool AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
Definition: itkMath.h:436
static bool AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
Definition: itkMath.h:408
static bool AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
Definition: itkMath.h:426
typename FloatIEEETraits< T >::IntType IntType