using System; using System.Runtime.CompilerServices; namespace RGB.NET.Core { /// /// Offers some extensions and helper-methods for the work with doubles /// public static class DoubleExtensions { #region Constants /// /// Defines the precision RGB.NET processes floating point comparisons in. /// public const double TOLERANCE = 1E-10; #endregion #region Methods /// /// Checks if two values are equal respecting the . /// /// The first value to compare. /// The first value to compare. /// true if the difference is smaller than the ; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EqualsInTolerance(this double value1, double value2) { return Math.Abs(value1 - value2) < TOLERANCE; } /// /// Camps the provided value to be bigger or equal min and smaller or equal max. /// /// The value to clamp. /// The lower value of the range the value is clamped to. /// The higher value of the range the value is clamped to. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Clamp(this double value, double min, double max) { return Math.Max(min, Math.Min(max, value)); } #endregion } }