/// <summary> /// Returns the position of the current <see cref="UInt16" /> within the specified range, expressed as a percentage where /// zero is equal to the lower boundary and one is equal to the upper boundary. /// </summary> /// <param name="target"> /// The current <see cref="UInt16" />. /// </param> /// <param name="lowerBoundary"> /// The inclusive lower boundary of the range to evaluate. /// </param> /// <param name="upperBoundary"> /// The inclusive upper boundary of the range to evaluate. /// </param> /// <returns> /// The position of the current <see cref="UInt16" /> within the specified range. /// </returns> /// <exception cref="ArgumentOutOfRangeException"> /// The current value is less than <paramref name="lowerBoundary" /> -or- the current value is greater than /// <paramref name="upperBoundary" /> -or- <paramref name="lowerBoundary" /> is greater than /// <paramref name="upperBoundary" /> -or- <paramref name="upperBoundary" /> is equal to <paramref name="lowerBoundary" />. /// </exception> public static Double PositionInRange(this UInt16 target, UInt16 lowerBoundary, UInt16 upperBoundary) { target = target.RejectIf().IsLessThan(lowerBoundary, nameof(lowerBoundary)).OrIf().IsGreaterThan(upperBoundary, nameof(upperBoundary)); lowerBoundary = lowerBoundary.RejectIf().IsGreaterThan(upperBoundary, nameof(lowerBoundary)); upperBoundary = upperBoundary.RejectIf().IsEqualToValue(lowerBoundary, nameof(upperBoundary)); return(Convert.ToDouble(target - lowerBoundary) / Convert.ToDouble(upperBoundary - lowerBoundary)); }