Last active
September 5, 2020 07:16
-
-
Save curegit/62978ae76108d189103a07269799807e to your computer and use it in GitHub Desktop.
C# 3種の剰余演算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class MyIntegerExtensions | |
{ | |
public static int TruncatedMod(this int dividend, int divisor) | |
{ | |
return dividend % divisor; | |
} | |
public static int FlooredMod(this int dividend, int divisor) | |
{ | |
return (dividend % divisor + divisor) % divisor; | |
} | |
public static int Mod(this int dividend, int divisor) | |
{ | |
return (dividend % divisor + Math.Abs(divisor)) % divisor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment