ionComparison.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "ionTypes.h"
11 
12 
13 namespace ion
14 {
15 
17  // Rounding Error //
19 
22  float const RoundingError32 = 0.00001f;
23 
26  double const RoundingError64 = 0.00000001;
27 
31  template <typename T>
33  {
34  static T const Value()
35  {
36  return 0;
37  }
38  };
39 
42  template <>
43  struct RoundingError<float>
44  {
45  static float Value()
46  {
47  return RoundingError32;
48  }
49  };
50 
53  template <>
54  struct RoundingError<double>
55  {
56  static double Value()
57  {
58  return RoundingError64;
59  }
60  };
61 
62 
64  // Equality //
66 
69  template <typename T>
70  static inline bool Equals(T const a, T const b, T const epsilon = RoundingError<T>::Value())
71  {
72  return (a + epsilon >= b) && (a - epsilon <= b);
73  }
74 
75 
77  // Comparison //
79 
82  template <typename T>
83  static inline T Minimum(T const & a, T const & b)
84  {
85  return a < b ? a : b;
86  }
87 
90  template <typename T>
91  static inline T Maximum(T const & a, T const & b)
92  {
93  return b < a ? a : b;
94  }
95 
98  template <typename T>
99  static inline T Minimum(T const & a, T const & b, T const & c)
100  {
101  return Minimum(a, Minimum(b, c));
102  }
103 
106  template <typename T>
107  static inline T Maximum(T const & a, T const & b, T const & c)
108  {
109  return Maximum(a, Maximum(b, c));
110  }
111 
114  template <typename T>
115  static inline T Minimum(T const & a, T const & b, T const & c, T const & d)
116  {
117  return Minimum(a, Minimum(b, c, d));
118  }
119 
122  template <typename T>
123  static inline T Maximum(T const & a, T const & b, T const & c, T const & d)
124  {
125  return Maximum(a, Maximum(b, c, d));
126  }
127 
128 
131  template <typename T>
132  static inline T Min(T const & a, T const & b)
133  {
134  return a < b ? a : b;
135  }
136 
139  template <typename T>
140  static inline T Max(T const & a, T const & b)
141  {
142  return b < a ? a : b;
143  }
144 
147  template <typename T>
148  static inline T Min(T const & a, T const & b, T const & c)
149  {
150  return Min(a, Min(b, c));
151  }
152 
155  template <typename T>
156  static inline T Max(T const & a, T const & b, T const & c)
157  {
158  return Max(a, Max(b, c));
159  }
160 
163  template <typename T>
164  static inline T Min(T const & a, T const & b, T const & c, T const & d)
165  {
166  return Min(a, Min(b, c, d));
167  }
168 
171  template <typename T>
172  static inline T Max(T const & a, T const & b, T const & c, T const & d)
173  {
174  return Max(a, Max(b, c, d));
175  }
176 
177 }
static double Value()
Definition: ionComparison.h:56
static T const Value()
Definition: ionComparison.h:34
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
double const RoundingError64
Global constant for 64bit floating-point epsilon.
Definition: ionComparison.h:26
Helper template to enable template-dependant epsilon values.
Definition: ionComparison.h:32
Defines typedefs for integer and floating point types.
static float Value()
Definition: ionComparison.h:45
float const RoundingError32
Global constant for 32bit floating-point epsilon.
Definition: ionComparison.h:22