public static partial class ExtensionMethods_Arithmetic { // http://en.wikipedia.org/wiki/Modulo_operation //______________________________________________________________________ /// <summary> /// Performs a Remainder calculation where the result has the sign of dividend /// </summary> /// <param name="dividend"></param> /// <param name="divisor"></param> /// <returns></returns> public static Int32 Rem(this Int32 dividend, Int32 divisor) { return (dividend % divisor); } //______________________________________________________________________ /// <summary> /// Performs a Remainder calculation where the result has the sign of dividend /// </summary> /// <param name="dividend"></param> /// <param name="divisor"></param> /// <returns></returns> public static Int64 Rem(this Int64 dividend, Int64 divisor) { return (dividend % divisor); } //______________________________________________________________________ }and
public static partial class ExtensionMethods_Arithmetic { // http://en.wikipedia.org/wiki/Modulo_operation //______________________________________________________________________ /// <summary> /// Performs a Modulo calculation where the result has the sign of divisor /// </summary> /// <param name="dividend"></param> /// <param name="divisor"></param> /// <returns></returns> public static Int32 Mod(this Int32 dividend, Int32 divisor) { return dividend.Rem(divisor) + (Math.Sign(dividend) * Math.Sign(divisor) >= 0 ? 0 : divisor); } //______________________________________________________________________ /// <summary> /// Performs a Modulo calculation where the result has the sign of divisor /// </summary> /// <param name="dividend"></param> /// <param name="divisor"></param> /// <returns></returns> public static Int64 Mod(this Int64 dividend, Int64 divisor) { return dividend.Rem(divisor) + (Math.Sign(dividend) * Math.Sign(divisor) >= 0 ? 0 : divisor); } //______________________________________________________________________ }