Added Utils class.
This commit is contained in:
parent
c6675bb051
commit
79fe8638af
1 changed files with 28 additions and 0 deletions
28
utils/Utils.cs
Normal file
28
utils/Utils.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Common utilities throughout the library.
|
||||||
|
/// </summary>
|
||||||
|
internal static class Utils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Default precision for double equality comparison.
|
||||||
|
/// </summary>
|
||||||
|
private const double DOUBLEPRECISION = 1E-5;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests whether the difference between two doubles is within a given limit.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First value to test.</param>
|
||||||
|
/// <param name="b">Second value to test.</param>
|
||||||
|
/// <param name="prec">Maximum allowed difference.</param>
|
||||||
|
/// <returns>Do the values almost equal each other.</returns>
|
||||||
|
public static bool DoubleEquals(double a, double b, double prec = DOUBLEPRECISION) => Math.Abs(a - b) <= prec;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue