mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
feat: Added mod method to MathUtils
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
/// <returns></returns>
|
||||
public static int To12Hour(int hour)
|
||||
{
|
||||
return ((hour + 11) % 12) + 1;
|
||||
return MathUtils.Mod(hour + 11, 12) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,5 +209,17 @@ namespace ICD.Common.Utils
|
||||
|
||||
return nearest.Aggregate((x, y) => Math.Abs(x - number) < Math.Abs(y - number) ? x : y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the modulus of the given number.
|
||||
/// </summary>
|
||||
/// <param name="number"></param>
|
||||
/// <param name="mod"></param>
|
||||
/// <returns></returns>
|
||||
public static int Mod(int number, int mod)
|
||||
{
|
||||
int remainder = number % mod;
|
||||
return remainder < 0 ? remainder + mod : remainder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user