Skip to content

Instantly share code, notes, and snippets.

@Ashwinning
Created February 7, 2016 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashwinning/24986d9aeb01261e1420 to your computer and use it in GitHub Desktop.
Save Ashwinning/24986d9aeb01261e1420 to your computer and use it in GitHub Desktop.
IsBetween : C# extension method for `float` which checks whether that float is between a min and max value.
	/// <summary>
	/// Determines if is between the specified float is between two given floats.
	/// </summary>
	/// <returns><c>true</c> if the float is between the specified num lower upper inclusive; otherwise, <c>false</c>.</returns>
	/// <param name="num">Number.</param>
	/// <param name="lower">Lower.</param>
	/// <param name="upper">Upper.</param>
	/// <param name="inclusive">If set to <c>true</c> inclusive.</param>
	public static bool IsBetween (this float num, float lower, float upper, bool inclusive = false)
	{
		return inclusive
			? lower <= num && num <= upper
				: lower < num && num < upper;
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment