ionComparison.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "ionConfig.h"
11 #include "ionTypes.h"
12 
13 
15 // Rounding Error //
17 
20 f32 const RoundingError32 = 0.00001f;
21 
24 f64 const RoundingError64 = 0.00000001;
25 
29 template <typename T>
31 {
32  static T const Value()
33  {
34  return 0;
35  }
36 };
37 
40 template <>
42 {
43  static f32 Value()
44  {
45  return RoundingError32;
46  }
47 };
48 
51 template <>
53 {
54  static f64 Value()
55  {
56  return RoundingError64;
57  }
58 };
59 
60 
62 // Equality //
64 
67 template <typename T>
68 static inline bool Equals(T const a, T const b, T const epsilon = RoundingError<T>::Value())
69 {
70  return (a + epsilon >= b) && (a - epsilon <= b);
71 }
72 
73 
75 // Comparison //
77 
80 template <typename T>
81 static inline T Minimum(T const & a, T const & b)
82 {
83  return a < b ? a : b;
84 }
85 
88 template <typename T>
89 static inline T Maximum(T const & a, T const & b)
90 {
91  return b < a ? a : b;
92 }
93 
96 template <typename T>
97 static inline T Minimum(T const & a, T const & b, T const & c)
98 {
99  return Minimum(a, Minimum(b, c));
100 }
101 
104 template <typename T>
105 static inline T Maximum(T const & a, T const & b, T const & c)
106 {
107  return Maximum(a, Maximum(b, c));
108 }
109 
112 template <typename T>
113 static inline T Minimum(T const & a, T const & b, T const & c, T const & d)
114 {
115  return Minimum(a, Minimum(b, c, d));
116 }
117 
120 template <typename T>
121 static inline T Maximum(T const & a, T const & b, T const & c, T const & d)
122 {
123  return Maximum(a, Maximum(b, c, d));
124 }
125 
126 
129 template <typename T>
130 static inline T Min(T const & a, T const & b)
131 {
132  return a < b ? a : b;
133 }
134 
137 template <typename T>
138 static inline T Max(T const & a, T const & b)
139 {
140  return b < a ? a : b;
141 }
142 
145 template <typename T>
146 static inline T Min(T const & a, T const & b, T const & c)
147 {
148  return Min(a, Min(b, c));
149 }
150 
153 template <typename T>
154 static inline T Max(T const & a, T const & b, T const & c)
155 {
156  return Max(a, Max(b, c));
157 }
158 
161 template <typename T>
162 static inline T Min(T const & a, T const & b, T const & c, T const & d)
163 {
164  return Min(a, Min(b, c, d));
165 }
166 
169 template <typename T>
170 static inline T Max(T const & a, T const & b, T const & c, T const & d)
171 {
172  return Max(a, Max(b, c, d));
173 }
f32 const RoundingError32
Global constant for 32bit floating-point epsilon.
Definition: ionComparison.h:20
float f32
Definition: ionTypes.h:94
static f32 Value()
Definition: ionComparison.h:43
static f64 Value()
Definition: ionComparison.h:54
Defines typedefs for integer and floating point types.
static T const Value()
Definition: ionComparison.h:32
f64 const RoundingError64
Global constant for 64bit floating-point epsilon.
Definition: ionComparison.h:24
double f64
Definition: ionTypes.h:95
Helper template to enable template-dependant epsilon values.
Definition: ionComparison.h:30