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 <complex>
33#include <cmath>
34#include <limits>
35#include <type_traits>
36#include "itkMathDetail.h"
37#include "itkConceptChecking.h"
38#include <vnl/vnl_math.h>
39
40/* Only maintain backwards compatibility with old versions
41 * of VXL back to the point where vnl_math:: was introduced
42 * versions of VXL where only vnl_math_ was available are not
43 * supported.
44 */
45#include <vxl_version.h>
46
47namespace itk::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 constexpr auto 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
144
145
168
176template <typename TReturn, typename TInput>
177inline constexpr auto
178Round(TInput x)
179{
181}
182
196
197
208
209#undef itkTemplateFloatingToIntegerMacro
210
211template <typename TReturn, typename TInput>
212inline auto
214{
215 itkConceptMacro(OnlyDefinedForIntegerTypes1, (itk::Concept::IsInteger<TReturn>));
216 itkConceptMacro(OnlyDefinedForIntegerTypes2, (itk::Concept::IsInteger<TInput>));
217
218 auto ret = static_cast<TReturn>(x);
219 if constexpr (sizeof(TReturn) > sizeof(TInput) &&
221 {
222 // if the output type is bigger and we are not converting a signed
223 // integer to an unsigned integer then we have no problems
224 return ret;
225 }
226 else if constexpr (sizeof(TReturn) >= sizeof(TInput))
227 {
229 {
230 itk::RangeError _e(__FILE__, __LINE__);
231 throw _e;
232 }
233 }
234 else if (static_cast<TInput>(ret) != x ||
236 {
237 itk::RangeError _e(__FILE__, __LINE__);
238 throw _e;
239 }
240 return ret;
241}
242
250template <typename T>
251inline constexpr typename Detail::FloatIEEE<T>::IntType
253{
254 const Detail::FloatIEEE<T> x1f(x1);
255 const Detail::FloatIEEE<T> x2f(x2);
256 return x1f.AsULP() - x2f.AsULP();
257}
258
266template <typename T>
267inline constexpr T
269{
270 const Detail::FloatIEEE<T> representInput(x);
271 const Detail::FloatIEEE<T> representOutput(representInput.asInt + ulps);
272 return representOutput.asFloat;
273}
274
305template <typename T>
306inline bool
308 T x2,
309 typename Detail::FloatIEEE<T>::IntType maxUlps = 4,
310 typename Detail::FloatIEEE<T>::FloatType maxAbsoluteDifference = 0.1 *
312{
313 // Check if the numbers are really close -- needed
314 // when comparing numbers near zero.
315 const T absDifference = std::abs(x1 - x2);
316 if (absDifference <= maxAbsoluteDifference)
317 {
318 return true;
319 }
320
321 // This check for different signs is necessary for several reasons, see the blog link above.
322 // Subtracting the signed-magnitude representation of floats using twos-complement
323 // math isn't particularly meaningful, and the subtraction would produce a 33-bit
324 // result and overflow an int.
325 if (std::signbit(x1) != std::signbit(x2))
326 {
327 return false;
328 }
329
330 const typename Detail::FloatIEEE<T>::IntType ulps = std::abs(FloatDifferenceULP(x1, x2));
331 return ulps <= maxUlps;
332}
333
334// The following code cannot be moved to the itkMathDetail.h file without introducing circular dependencies
335namespace Detail // The Detail namespace holds the templates used by AlmostEquals
336{
337// The following structs and templates are used to choose
338// which version of the AlmostEquals function
339// should be implemented base on input parameter types
340
341// Structs for choosing AlmostEquals function
342
344{
345 template <typename TFloatType1, typename TFloatType2>
346 static bool
347 AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
348 {
349 return FloatAlmostEqual<double>(x1, x2);
350 }
351
352 template <typename TFloatType1, typename TFloatType2>
353 static bool
354 AlmostEqualsFunction(double x1, double x2)
355 {
356 return FloatAlmostEqual<double>(x1, x2);
357 }
358
359 template <typename TFloatType1, typename TFloatType2>
360 static bool
361 AlmostEqualsFunction(double x1, float x2)
362 {
363 return FloatAlmostEqual<float>(x1, x2);
364 }
365
366 template <typename TFloatType1, typename TFloatType2>
367 static bool
368 AlmostEqualsFunction(float x1, double x2)
369 {
370 return FloatAlmostEqual<float>(x1, x2);
371 }
372
373 template <typename TFloatType1, typename TFloatType2>
374 static bool
375 AlmostEqualsFunction(float x1, float x2)
376 {
377 return FloatAlmostEqual<float>(x1, x2);
378 }
379};
380
382{
383 template <typename TFloatType, typename TIntType>
384 static bool
385 AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
386 {
387 return FloatAlmostEqual<TFloatType>(floatingVariable, integerVariable);
388 }
389};
390
392{
393 template <typename TIntType, typename TFloatType>
394 static bool
395 AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
396 {
397 return AlmostEqualsFloatVsInteger::AlmostEqualsFunction(floatingVariable, integerVariable);
398 }
399};
400
402{
403 template <typename TSignedInt, typename TUnsignedInt>
404 static bool
405 AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
406 {
407 if (signedVariable < 0)
408 {
409 return false;
410 }
411 if (unsignedVariable > static_cast<size_t>(itk::NumericTraits<TSignedInt>::max()))
412 {
413 return false;
414 }
415 return signedVariable == static_cast<TSignedInt>(unsignedVariable);
416 }
417};
418
420{
421 template <typename TUnsignedInt, typename TSignedInt>
422 static bool
423 AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
424 {
425 return AlmostEqualsSignedVsUnsigned::AlmostEqualsFunction(signedVariable, unsignedVariable);
426 }
427};
428
430{
431 template <typename TIntegerType1, typename TIntegerType2>
432 static bool
433 AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
434 {
435 return x1 == x2;
436 }
437};
438// end of structs that choose the specific AlmostEquals function
439
440// Selector structs, these select the correct case based on its types
441// input1 is int? input 1 is signed? input2 is int? input 2 is signed?
442template <bool TInput1IsIntger, bool TInput1IsSigned, bool TInput2IsInteger, bool TInput2IsSigned>
447
449template <>
450struct AlmostEqualsFunctionSelector<false, true, false, true>
451// floating type v floating type
452{
454};
455
456template <>
457struct AlmostEqualsFunctionSelector<false, true, true, true>
458// float vs int
459{
460 using SelectedVersion = AlmostEqualsFloatVsInteger;
461};
462
463template <>
464struct AlmostEqualsFunctionSelector<false, true, true, false>
465// float vs unsigned int
466{
467 using SelectedVersion = AlmostEqualsFloatVsInteger;
468};
469
470template <>
471struct AlmostEqualsFunctionSelector<true, false, false, true>
472// unsigned int vs float
473{
474 using SelectedVersion = AlmostEqualsIntegerVsFloat;
475};
476
477template <>
478struct AlmostEqualsFunctionSelector<true, true, false, true>
479// int vs float
480{
481 using SelectedVersion = AlmostEqualsIntegerVsFloat;
482};
483
484template <>
485struct AlmostEqualsFunctionSelector<true, true, true, false>
486// signed vs unsigned
487{
488 using SelectedVersion = AlmostEqualsSignedVsUnsigned;
489};
490
491template <>
492struct AlmostEqualsFunctionSelector<true, false, true, true>
493// unsigned vs signed
494{
495 using SelectedVersion = AlmostEqualsUnsignedVsSigned;
496};
497
498template <>
499struct AlmostEqualsFunctionSelector<true, true, true, true>
500// signed vs signed
501{
502 using SelectedVersion = AlmostEqualsPlainOldEquals;
503};
504
505template <>
506struct AlmostEqualsFunctionSelector<true, false, true, false>
507// unsigned vs unsigned
508{
509 using SelectedVersion = AlmostEqualsPlainOldEquals;
510};
511// end of AlmostEqualsFunctionSelector structs
512
513// The implementor tells the selector what to do
514template <typename TInputType1, typename TInputType2>
515struct AlmostEqualsScalarImplementer
516{
517 static constexpr bool TInputType1IsInteger = std::is_integral_v<TInputType1>;
518 static constexpr bool TInputType1IsSigned = std::is_signed_v<TInputType1>;
519 static constexpr bool TInputType2IsInteger = std::is_integral_v<TInputType2>;
520 static constexpr bool TInputType2IsSigned = std::is_signed_v<TInputType2>;
521
522 using SelectedVersion = typename AlmostEqualsFunctionSelector<TInputType1IsInteger,
523 TInputType1IsSigned,
524 TInputType2IsInteger,
525 TInputType2IsSigned>::SelectedVersion;
526};
527
528// The AlmostEqualsScalarComparer returns the result of an
529// approximate comparison between two scalar values of
530// potentially different data types.
531template <typename TScalarType1, typename TScalarType2>
532inline bool
533AlmostEqualsScalarComparer(TScalarType1 x1, TScalarType2 x2)
534{
535 return AlmostEqualsScalarImplementer<TScalarType1, TScalarType2>::SelectedVersion::
536 template AlmostEqualsFunction<TScalarType1, TScalarType2>(x1, x2);
537}
538
539// The following structs are used to evaluate approximate comparisons between
540// complex and scalar values of potentially different types.
541
542// Comparisons between scalar types use the AlmostEqualsScalarComparer function.
543struct AlmostEqualsScalarVsScalar
544{
545 template <typename TScalarType1, typename TScalarType2>
546 static bool
547 AlmostEqualsFunction(TScalarType1 x1, TScalarType2 x2)
548 {
549 return AlmostEqualsScalarComparer(x1, x2);
550 }
551};
552
553// Comparisons between two complex values compare the real and imaginary components
554// separately with the AlmostEqualsScalarComparer function.
555struct AlmostEqualsComplexVsComplex
556{
557 template <typename TComplexType1, typename TComplexType2>
558 static bool
559 AlmostEqualsFunction(TComplexType1 x1, TComplexType2 x2)
560 {
561 return AlmostEqualsScalarComparer(x1.real(), x2.real()) && AlmostEqualsScalarComparer(x1.imag(), x2.imag());
562 }
563};
564
565// Comparisons between complex and scalar values first check to see if the imaginary component
566// of the complex value is approximately 0. Then a ScalarComparison is done between the real
567// part of the complex number and the scalar value.
568struct AlmostEqualsScalarVsComplex
569{
570 template <typename TScalarType, typename TComplexType>
571 static bool
572 AlmostEqualsFunction(TScalarType scalarVariable, TComplexType complexVariable)
573 {
574 if (!AlmostEqualsScalarComparer(complexVariable.imag(), typename itk::NumericTraits<TComplexType>::ValueType{}))
575 {
576 return false;
577 }
578 return AlmostEqualsScalarComparer(scalarVariable, complexVariable.real());
579 }
580};
581
582struct AlmostEqualsComplexVsScalar
583{
584 template <typename TComplexType, typename TScalarType>
585 static bool
586 AlmostEqualsFunction(TComplexType complexVariable, TScalarType scalarVariable)
587 {
588 return AlmostEqualsScalarVsComplex::AlmostEqualsFunction(scalarVariable, complexVariable);
589 }
590};
591
592// The AlmostEqualsComplexChooser structs choose the correct case
593// from the input parameter types' IsComplex property
594// The default case is scalar vs scalar
595template <bool T1IsComplex, bool T2IsComplex> // Default is false, false
596struct AlmostEqualsComplexChooser
597{
598 using ChosenVersion = AlmostEqualsScalarVsScalar;
599};
600
601template <>
602struct AlmostEqualsComplexChooser<true, true>
603{
604 using ChosenVersion = AlmostEqualsComplexVsComplex;
605};
606
607template <>
608struct AlmostEqualsComplexChooser<false, true>
609{
610 using ChosenVersion = AlmostEqualsScalarVsComplex;
611};
612
613template <>
614struct AlmostEqualsComplexChooser<true, false>
615{
616 using ChosenVersion = AlmostEqualsComplexVsScalar;
617};
618// End of AlmostEqualsComplexChooser structs.
619
620// The AlmostEqualsComplexImplementer determines which of the input
621// parameters are complex and which are real, and sends that information
622// to the AlmostEqualsComplexChooser structs to determine the proper
623// type of evaluation.
624template <typename T1, typename T2>
625struct AlmostEqualsComplexImplementer
626{
627 static constexpr bool T1IsComplex = NumericTraits<T1>::IsComplex;
628 static constexpr bool T2IsComplex = NumericTraits<T2>::IsComplex;
629
630 using ChosenVersion = typename AlmostEqualsComplexChooser<T1IsComplex, T2IsComplex>::ChosenVersion;
631};
633
634} // end namespace Detail
635
677
678// The AlmostEquals function
679template <typename T1, typename T2>
680inline bool
681AlmostEquals(T1 x1, T2 x2)
682{
683 return Detail::AlmostEqualsComplexImplementer<T1, T2>::ChosenVersion::AlmostEqualsFunction(x1, x2);
684}
685
686// The NotAlmostEquals function
687template <typename T1, typename T2>
688inline bool
689NotAlmostEquals(T1 x1, T2 x2)
690{
691 return !AlmostEquals(x1, x2);
692}
693
694
715
716// The ExactlyEquals function
717template <typename TInput1, typename TInput2>
718inline constexpr bool
719ExactlyEquals(const TInput1 & x1, const TInput2 & x2)
720{
721 ITK_GCC_PRAGMA_PUSH
722 ITK_GCC_SUPPRESS_Wfloat_equal
723 return x1 == x2;
724 ITK_GCC_PRAGMA_POP
725}
726
727// The NotExactlyEquals function
728template <typename TInput1, typename TInput2>
729inline constexpr bool
730NotExactlyEquals(const TInput1 & x1, const TInput2 & x2)
731{
732 return !ExactlyEquals(x1, x2);
733}
734
735
741template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
742constexpr bool
744{
745 // An Introduction to the Theory of Numbers — G.H. Hardy & E.M. Wright, 6th ed., Oxford University Press.
746 // See Chapter 1 (Elementary Results on Primes). The observation that primes > 3 lie in residue classes
747 // +/1 mod 6 follows directly from eliminating multiples of 2 and 3.
748 if (n <= 1)
749 {
750 return false;
751 }
752 if (n == 2 || n == 3)
753 {
754 return true;
755 }
756 if (n % 2 == 0 || n % 3 == 0)
757 {
758 return false;
759 }
760 // 6k +/- 1, and avoid overflow via i <= n / i
761 for (T x = 5; x <= n / x; x += 6)
762 {
763 if (n % x == 0 || n % (x + 2) == 0)
764 {
765 return false;
766 }
767 }
768 return true;
769}
770
771
774template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
775constexpr T
777{
778 T v = 2;
779 while (v <= n)
780 {
781 if (n % v == 0 && IsPrime(v))
782 {
783 n /= v;
784 }
785 else
786 {
787 v += 1;
788 }
789 }
790 return v;
791}
792
793
797template <typename TReturnType = uintmax_t>
798constexpr auto
799UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
800{
801 static_assert(std::is_unsigned_v<TReturnType>, "UnsignedProduct only supports unsigned return types");
802
803 // Note that numeric overflow is not "undefined behavior", for unsigned numbers.
804 // This function checks if the result of a*b is mathematically correct.
805 return (a == 0) || (b == 0) ||
806 (((static_cast<TReturnType>(a * b) / a) == b) && ((static_cast<TReturnType>(a * b) / b) == a))
807 ? static_cast<TReturnType>(a * b)
808 : (assert(!"UnsignedProduct overflow!"), 0);
809}
810
811
819template <typename TReturnType = uintmax_t>
820constexpr auto
821UnsignedPower(const uintmax_t base, const uintmax_t exponent) noexcept -> TReturnType
822{
823 static_assert(std::is_unsigned_v<TReturnType>, "UnsignedPower only supports unsigned return types");
824
825 // Uses recursive function calls because C++11 does not support other ways of
826 // iterations for a constexpr function.
827 return (exponent == 0) ? (assert(base > 0), 1)
828 : (exponent == 1) ? base
830 UnsignedPower<TReturnType>(base, (exponent + 1) / 2));
831}
832
833
834/*==========================================
835 * Alias the vnl_math functions in the itk::Math
836 * namespace. If possible, use the std:: equivalents
837 */
838using std::isnan;
839using std::isinf;
840using std::isfinite;
841using std::isnormal;
842using std::cbrt;
843using std::hypot;
844using vnl_math::angle_0_to_2pi;
845using vnl_math::angle_minuspi_to_pi;
846using vnl_math::rnd_halfinttoeven;
847using vnl_math::rnd_halfintup;
848using vnl_math::rnd;
849using vnl_math::floor;
850using vnl_math::ceil;
851using vnl_math::sgn;
852using vnl_math::sgn0;
853using vnl_math::remainder_truncated;
854using vnl_math::remainder_floored;
855using vnl_math::sqr;
856using vnl_math::cube;
857using vnl_math::squared_magnitude;
858
859
880template <typename T>
881constexpr auto
882Absolute(T x) noexcept
883{
884 if constexpr (std::is_same_v<T, bool>)
885 {
886 // std::abs does not provide abs for bool, but ITK depends on bool support for abs.
887 return x;
888 }
889 else if constexpr (std::is_integral_v<T>)
890 {
891 if constexpr (std::is_signed_v<T>)
892 {
893 using UnsignedType = std::make_unsigned_t<T>;
894 using Limits = std::numeric_limits<T>;
895
896 // The absolute value of the minimum integer value, having a two's complement signed integer representation.
897 constexpr UnsignedType absoluteValueOfMin{ UnsignedType{ Limits::max() } + UnsignedType{ 1 } };
898
899 return static_cast<UnsignedType>((x < 0) ? (x == Limits::min()) ? absoluteValueOfMin : -x : x);
900 }
901 else
902 { // In C++17, the std::abs() integer overloads are only for : int, long, and long long.
903 // unsigned type values std::abs() are supported through implicit type conversions to
904 // the next larger sized integer type. The 'unsigned long long' failed due to an
905 // lack of larger sized signed integer type to be promoted to.
906 // type of x | default std::abs() called
907 // uint8_t | std::abs( (int32_t) x)
908 // uint16_t | std::abs( (int32_t) x)
909 // uint32_t | std::abs( (int64_t) x)
910 // uint64_t | // compiler error
911 // This explicit override provides direct support for all unsigned integer types with type promotion.
912 return x;
913 }
914 }
915 else if constexpr (std::is_floating_point_v<T>) // floating point or complex<> types
916 { // floating point std::abs is constexpr in c++23 and later
917 // Note: +0.0 and -0.0 are considered equal, according to ExactlyEquals. They are both considered equal to T{}.
918 // And they both have the same absolute value: +0.0.
919 return ExactlyEquals(x, T{}) ? T{} : (x < 0) ? -x : x;
920 }
921}
922template <typename T>
923auto
924Absolute(const std::complex<T> & x) noexcept
925{
926 // std::abs<T>(std::complex<T>) is not constexpr in in any proposed c++ standard
927 return std::abs<T>(x);
928}
929
930#if !defined(ITK_FUTURE_LEGACY_REMOVE)
931// itk::Math::Absolute has different behavior than std::abs. The use of
932// abs() in the ITK context without namespace resolution can be confusing
933// The abs() version is provided for backwards compatibility.
934template <typename T>
935auto
936abs(T x) noexcept
937{
938 return Absolute(x);
939}
940#endif
941
942} // namespace itk::Math
943
944#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.
constexpr T GreatestPrimeFactor(T n)
Definition itkMath.h:776
bool AlmostEquals(T1 x1, T2 x2)
Provide consistent equality checks between values of potentially different scalar or complex types.
Definition itkMath.h:681
static constexpr double sqrt2pi
Definition itkMath.h:82
constexpr auto UnsignedPower(const uintmax_t base, const uintmax_t exponent) noexcept -> TReturnType
Definition itkMath.h:821
static constexpr double sqrt1_2
Definition itkMath.h:90
static constexpr double eps
Definition itkMath.h:97
constexpr auto Absolute(T x) noexcept
Returns the absolute value of a number.
Definition itkMath.h:882
TInput TInput auto CastWithRangeCheck(TInput x)
Definition itkMath.h:213
bool NotAlmostEquals(T1 x1, T2 x2)
Definition itkMath.h:689
TInput Ceil(TInput x) template< typename TReturn
static constexpr double pi_over_2
Definition itkMath.h:70
constexpr bool IsPrime(T n)
Definition itkMath.h:743
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)
constexpr 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:719
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
constexpr auto UnsignedProduct(const uintmax_t a, const uintmax_t b) noexcept
Definition itkMath.h:799
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
TInput TInput constexpr auto Round(TInput x)
Definition itkMath.h:178
static constexpr float float_sqrteps
Definition itkMath.h:101
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
static constexpr double sqrt2
Definition itkMath.h:88
constexpr bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition itkMath.h:730
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:307
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
constexpr 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:252
constexpr 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:268
static constexpr double log10e
Definition itkMath.h:60
static constexpr double log2e
Definition itkMath.h:58
static bool AlmostEqualsFunction(double x1, double x2)
Definition itkMath.h:354
static bool AlmostEqualsFunction(float x1, double x2)
Definition itkMath.h:368
static bool AlmostEqualsFunction(TFloatType1 x1, TFloatType2 x2)
Definition itkMath.h:347
static bool AlmostEqualsFunction(double x1, float x2)
Definition itkMath.h:361
static bool AlmostEqualsFunction(float x1, float x2)
Definition itkMath.h:375
static bool AlmostEqualsFunction(TFloatType floatingVariable, TIntType integerVariable)
Definition itkMath.h:385
AlmostEqualsPlainOldEquals SelectedVersion
Definition itkMath.h:445
static bool AlmostEqualsFunction(TIntType integerVariable, TFloatType floatingVariable)
Definition itkMath.h:395
static bool AlmostEqualsFunction(TIntegerType1 x1, TIntegerType2 x2)
Definition itkMath.h:433
static bool AlmostEqualsFunction(TSignedInt signedVariable, TUnsignedInt unsignedVariable)
Definition itkMath.h:405
static bool AlmostEqualsFunction(TUnsignedInt unsignedVariable, TSignedInt signedVariable)
Definition itkMath.h:423
constexpr IntType AsULP() const
typename FloatIEEETraits< T >::IntType IntType