-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathFloatingNumberExtensions.cs
More file actions
60 lines (56 loc) · 2.97 KB
/
Copy pathFloatingNumberExtensions.cs
File metadata and controls
60 lines (56 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// FloatingNumberExtensions.cs, 07.11.2019
// Copyright (C) Dominic Beger 07.11.2019
namespace SharpMath
{
/// <summary>
/// Provides extensions for comparing floating numbers using approximations.
/// </summary>
public static class FloatingNumberExtensions
{
/// <summary>
/// Determines whether two floating numbers are approximately equal to each other using the
/// <see cref="FloatingNumber.Epsilon" /> value.
/// </summary>
/// <param name="number">The current <see cref="float" />.</param>
/// <param name="other">The other <see cref="float" />.</param>
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
public static bool IsApproximatelyEqualTo(this float number, float other)
{
return FloatingNumber.AreApproximatelyEqual(number, other);
}
/// <summary>
/// Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
/// </summary>
/// <param name="number">The current <see cref="float" />.</param>
/// <param name="other">The other <see cref="float" />.</param>
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
public static bool IsApproximatelyEqualTo(this float number, float other, double epsilon)
{
return FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
}
/// <summary>
/// Determines whether two floating numbers are approximately equal to each other using the
/// <see cref="FloatingNumber.Epsilon" />
/// value.
/// </summary>
/// <param name="number">The current <see cref="float" />.</param>
/// <param name="other">The other <see cref="float" />.</param>
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
public static bool IsApproximatelyEqualTo(this double number, double other)
{
return FloatingNumber.AreApproximatelyEqual(number, other);
}
/// <summary>
/// Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
/// </summary>
/// <param name="number">The current <see cref="float" />.</param>
/// <param name="other">The other <see cref="float" />.</param>
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
public static bool IsApproximatelyEqualTo(this double number, double other, double epsilon)
{
return FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
}
}
}