Skip to content

Commit 7f4f0f7

Browse files
author
Dominic Beger
committed
Make FloatingNumber static and implement relating extensions
1 parent 6377efb commit 7f4f0f7

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

SharpMath/FloatingNumber.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SharpMath
77
/// <summary>
88
/// Provides functions for comparing floating numbers using approximations.
99
/// </summary>
10-
public class FloatingNumber
10+
public static class FloatingNumber
1111
{
1212
/// <summary>
1313
/// Gets the default tolerance value for comparing floating numbers.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace SharpMath
2+
{
3+
/// <summary>
4+
/// Provides extensions for comparing floating numbers using approximations.
5+
/// </summary>
6+
public static class FloatingNumberExtensions
7+
{
8+
/// <summary>
9+
/// Determines whether two floating numbers are approximately equal to each other using the <see cref="FloatingNumber.Epsilon" /> value.
10+
/// </summary>
11+
/// <param name="number">The current <see cref="float" />.</param>
12+
/// <param name="other">The other <see cref="float" />.</param>
13+
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
14+
public static bool AreApproximatelyEqual(this float number, float other)
15+
=> FloatingNumber.AreApproximatelyEqual(number, other);
16+
17+
/// <summary>
18+
/// Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
19+
/// </summary>
20+
/// <param name="number">The current <see cref="float" />.</param>
21+
/// <param name="other">The other <see cref="float" />.</param>
22+
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
23+
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
24+
public static bool AreApproximatelyEqual(this float number, float other, double epsilon)
25+
=> FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
26+
27+
/// <summary>
28+
/// Determines whether two floating numbers are approximately equal to each other using the <see cref="Epsilon" />
29+
/// value.
30+
/// </summary>
31+
/// <param name="number">The current <see cref="float" />.</param>
32+
/// <param name="other">The other <see cref="float" />.</param>
33+
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
34+
public static bool AreApproximatelyEqual(double number, double other)
35+
=> FloatingNumber.AreApproximatelyEqual(number, other);
36+
37+
/// <summary>
38+
/// Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
39+
/// </summary>
40+
/// <param name="number">The current <see cref="float" />.</param>
41+
/// <param name="other">The other <see cref="float" />.</param>
42+
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
43+
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
44+
public static bool AreApproximatelyEqual(double number, double other, double epsilon)
45+
=> FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
46+
}
47+
}

SharpMath/SharpMath.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Compile Include="Extensions.cs" />
5757
<Compile Include="Algorithm.cs" />
5858
<Compile Include="FloatingNumber.cs" />
59+
<Compile Include="FloatingNumberExtensions.cs" />
5960
<Compile Include="Geometry\Exceptions\DimensionException.cs" />
6061
<Compile Include="Geometry\Line2D.cs" />
6162
<Compile Include="Geometry\Line3D.cs" />

0 commit comments

Comments
 (0)