@@ -65,61 +65,6 @@ public static bool Equals(double referenceValue, double otherValue, double toler
65
65
}
66
66
}
67
67
68
- /// <summary>
69
- /// <para>
70
- /// Checks if two values are equal with a given relative or absolute tolerance.
71
- /// </para>
72
- /// <para>
73
- /// Relative tolerance is defined as the maximum allowable absolute difference between
74
- /// <paramref name="referenceValue" /> and
75
- /// <paramref name="otherValue" /> as a percentage of <paramref name="referenceValue" />. A relative tolerance of
76
- /// 0.01 means the
77
- /// absolute difference of <paramref name="referenceValue" /> and <paramref name="otherValue" /> must be within +/-
78
- /// 1%.
79
- /// <example>
80
- /// In this example, the two values will be equal if the value of b is within +/- 1% of a.
81
- /// <code>
82
- /// Equals(a, b, 0.01, ComparisonType.Relative);
83
- /// </code>
84
- /// </example>
85
- /// </para>
86
- /// <para>
87
- /// Absolute tolerance is defined as the maximum allowable absolute difference between
88
- /// <paramref name="referenceValue" /> and
89
- /// <paramref name="otherValue" /> as a fixed number.
90
- /// <example>
91
- /// In this example, the two values will be equal if abs(<paramref name="referenceValue" /> -
92
- /// <paramref name="otherValue" />) <= 0.01
93
- /// <code>
94
- /// Equals(a, b, 0.01, ComparisonType.Absolute);
95
- /// </code>
96
- /// </example>
97
- /// </para>
98
- /// </summary>
99
- /// <param name="referenceValue">
100
- /// The reference value. If using relative tolerance, it is the value which the relative
101
- /// tolerance will be calculated against.
102
- /// </param>
103
- /// <param name="otherValue">The value to compare to.</param>
104
- /// <param name="tolerance">The absolute or relative tolerance value. Must be greater than or equal to 0.</param>
105
- /// <param name="comparisonType">Whether the tolerance is absolute or relative.</param>
106
- /// <returns></returns>
107
- public static bool Equals ( decimal referenceValue , decimal otherValue , decimal tolerance , ComparisonType comparisonType )
108
- {
109
- if ( tolerance < 0 )
110
- throw new ArgumentOutOfRangeException ( nameof ( tolerance ) , "Tolerance must be greater than or equal to 0" ) ;
111
-
112
- switch ( comparisonType )
113
- {
114
- case ComparisonType . Relative :
115
- return EqualsRelative ( referenceValue , otherValue , tolerance ) ;
116
- case ComparisonType . Absolute :
117
- return EqualsAbsolute ( referenceValue , otherValue , tolerance ) ;
118
- default :
119
- throw new InvalidOperationException ( "The given ComparisonType is not supported." ) ;
120
- }
121
- }
122
-
123
68
/// <summary>
124
69
/// Checks if two values are equal with a given relative tolerance.
125
70
/// <para>
@@ -150,36 +95,6 @@ public static bool EqualsRelative(double referenceValue, double otherValue, doub
150
95
return Math . Abs ( referenceValue - otherValue ) <= maxVariation ;
151
96
}
152
97
153
- /// <summary>
154
- /// Checks if two values are equal with a given relative tolerance.
155
- /// <para>
156
- /// Relative tolerance is defined as the maximum allowable absolute difference between
157
- /// <paramref name="referenceValue" /> and
158
- /// <paramref name="otherValue" /> as a percentage of <paramref name="referenceValue" />. A relative tolerance of
159
- /// 0.01 means the
160
- /// absolute difference of <paramref name="referenceValue" /> and <paramref name="otherValue" /> must be within +/-
161
- /// 1%.
162
- /// <example>
163
- /// In this example, the two values will be equal if the value of b is within +/- 1% of a.
164
- /// <code>
165
- /// EqualsRelative(a, b, 0.01);
166
- /// </code>
167
- /// </example>
168
- /// </para>
169
- /// </summary>
170
- /// <param name="referenceValue">The reference value which the tolerance will be calculated against.</param>
171
- /// <param name="otherValue">The value to compare to.</param>
172
- /// <param name="tolerance">The relative tolerance. Must be greater than or equal to 0.</param>
173
- /// <returns>True if the two values are equal within the given relative tolerance, otherwise false.</returns>
174
- public static bool EqualsRelative ( decimal referenceValue , decimal otherValue , decimal tolerance )
175
- {
176
- if ( tolerance < 0 )
177
- throw new ArgumentOutOfRangeException ( nameof ( tolerance ) , "Tolerance must be greater than or equal to 0" ) ;
178
-
179
- var maxVariation = Math . Abs ( referenceValue * tolerance ) ;
180
- return Math . Abs ( referenceValue - otherValue ) <= maxVariation ;
181
- }
182
-
183
98
/// <summary>
184
99
/// Checks if two values are equal with a given absolute tolerance.
185
100
/// <para>
@@ -206,32 +121,5 @@ public static bool EqualsAbsolute(double value1, double value2, double tolerance
206
121
207
122
return Math . Abs ( value1 - value2 ) <= tolerance ;
208
123
}
209
-
210
- /// <summary>
211
- /// Checks if two values are equal with a given absolute tolerance.
212
- /// <para>
213
- /// Absolute tolerance is defined as the maximum allowable absolute difference between <paramref name="value1" />
214
- /// and
215
- /// <paramref name="value2" /> as a fixed number.
216
- /// <example>
217
- /// In this example, the two values will be equal if abs(<paramref name="value1" /> -
218
- /// <paramref name="value2" />) <= 0.01
219
- /// <code>
220
- /// Equals(a, b, 0.01, ComparisonType.Absolute);
221
- /// </code>
222
- /// </example>
223
- /// </para>
224
- /// </summary>
225
- /// <param name="value1">The first value.</param>
226
- /// <param name="value2">The second value.</param>
227
- /// <param name="tolerance">The absolute tolerance. Must be greater than or equal to 0.</param>
228
- /// <returns>True if the two values are equal within the given absolute tolerance, otherwise false.</returns>
229
- public static bool EqualsAbsolute ( decimal value1 , decimal value2 , decimal tolerance )
230
- {
231
- if ( tolerance < 0 )
232
- throw new ArgumentOutOfRangeException ( nameof ( tolerance ) , "Tolerance must be greater than or equal to 0" ) ;
233
-
234
- return Math . Abs ( value1 - value2 ) <= tolerance ;
235
- }
236
124
}
237
125
}
0 commit comments