feat: Added mod method to MathUtils

This commit is contained in:
Chris Cameron
2019-09-09 10:06:08 -04:00
parent b09f614ef5
commit 45ee3e70b0
4 changed files with 29 additions and 7 deletions

View File

@@ -9,7 +9,7 @@
/// <returns></returns>
public static int To12Hour(int hour)
{
return ((hour + 11) % 12) + 1;
return MathUtils.Mod(hour + 11, 12) + 1;
}
}
}

View File

@@ -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;
}
}
}