Skip to content

Commit d60bae3

Browse files
committed
Remove last bits of decimal support
1 parent e85d9c4 commit d60bae3

File tree

5 files changed

+2
-188
lines changed

5 files changed

+2
-188
lines changed

UnitsNet.Tests/AssertEx.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,5 @@ public static void EqualTolerance(double expected, double actual, double toleran
2525
Assert.True( areEqual, $"Values are not equal within absolute tolerance: {tolerance}\nExpected: {expected}\nActual: {actual}\nDiff: {actual - expected:e}" );
2626
}
2727
}
28-
29-
public static void EqualTolerance(decimal expected, decimal actual, decimal tolerance, ComparisonType comparisonType = ComparisonType.Relative)
30-
{
31-
if (comparisonType == ComparisonType.Relative)
32-
{
33-
bool areEqual = Comparison.EqualsRelative(expected, actual, tolerance);
34-
35-
decimal difference = Math.Abs(expected - actual);
36-
decimal relativeDifference = difference / expected;
37-
38-
Assert.True(areEqual, $"Values are not equal within relative tolerance: {tolerance:P4}\nExpected: {expected}\nActual: {actual}\nDiff: {relativeDifference:P4}");
39-
}
40-
else if (comparisonType == ComparisonType.Absolute)
41-
{
42-
bool areEqual = Comparison.EqualsAbsolute(expected, actual, tolerance);
43-
Assert.True(areEqual, $"Values are not equal within absolute tolerance: {tolerance}\nExpected: {expected}\nActual: {actual}\nDiff: {actual - expected:e}");
44-
}
45-
}
4628
}
4729
}

UnitsNet/Comparison.cs

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -65,61 +65,6 @@ public static bool Equals(double referenceValue, double otherValue, double toler
6565
}
6666
}
6767

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" />) &lt;= 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-
12368
/// <summary>
12469
/// Checks if two values are equal with a given relative tolerance.
12570
/// <para>
@@ -150,36 +95,6 @@ public static bool EqualsRelative(double referenceValue, double otherValue, doub
15095
return Math.Abs(referenceValue - otherValue) <= maxVariation;
15196
}
15297

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-
18398
/// <summary>
18499
/// Checks if two values are equal with a given absolute tolerance.
185100
/// <para>
@@ -206,32 +121,5 @@ public static bool EqualsAbsolute(double value1, double value2, double tolerance
206121

207122
return Math.Abs(value1 - value2) <= tolerance;
208123
}
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" />) &lt;= 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-
}
236124
}
237125
}

UnitsNet/GenericMath/DecimalGenericMathExtensions.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

UnitsNet/GenericMath/GenericMathExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ namespace UnitsNet.GenericMath;
1212
/// Provides generic math operations to test out the new generic math interfaces implemented in .NET7 for UnitsNet
1313
/// quantities using <see cref="double" /> as the internal value type, which is the majority of quantities.
1414
/// </summary>
15-
/// <remarks>
16-
/// See <see cref="DecimalGenericMathExtensions" /> for quantities using <see cref="decimal" /> as the internal value
17-
/// type.
18-
/// </remarks>
1915
public static class GenericMathExtensions
2016
{
2117
/// <summary>

UnitsNet/QuantityFormatter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ private static string FormatUntrimmed<TUnitType>(IQuantity<TUnitType> quantity,
180180

181181
private static string ToStringWithSignificantDigitsAfterRadix<TUnitType>(IQuantity<TUnitType> quantity, IFormatProvider formatProvider, int number) where TUnitType : Enum
182182
{
183-
// When a fixed number of digits after the dot is expected, double and decimal behave the same.
184-
var value = (double)quantity.Value;
185-
string formatForSignificantDigits = UnitFormatter.GetFormat(value, number);
186-
object[] formatArgs = UnitFormatter.GetFormatArgs(quantity.Unit, value, formatProvider, Enumerable.Empty<object>());
183+
string formatForSignificantDigits = UnitFormatter.GetFormat(quantity.Value, number);
184+
object[] formatArgs = UnitFormatter.GetFormatArgs(quantity.Unit, quantity.Value, formatProvider, Enumerable.Empty<object>());
187185
return string.Format(formatProvider, formatForSignificantDigits, formatArgs);
188186
}
189187
}

0 commit comments

Comments
 (0)