Skip to content

Commit

Permalink
NumberUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixill committed Dec 4, 2022
1 parent ea50997 commit 23502a8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CSharp.Nixill/src/Utils/NumberUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,14 @@ public static string IntToLeadingZeroString(int input, int bs) {

return ret;
}

/// <summary>
/// Returns the non-negative modulus of division of n by d.
/// </summary>
public static int NNMod(int n, int d) => ((n %= d) < 0) ? n+d : n;
public static long NNMod(long n, long d) => ((n %= d) < 0) ? n+d : n;
public static float NNMod(float n, float d) => ((n %= d) < 0) ? n+d : n;
public static double NNMod(double n, double d) => ((n %= d) < 0) ? n+d : n;
public static decimal NNMod(decimal n, decimal d) => ((n %= d) < 0) ? n+d : n;
}
}

0 comments on commit 23502a8

Please sign in to comment.