Skip to content

Instantly share code, notes, and snippets.

@curegit
Last active September 5, 2020 07:16
Show Gist options
  • Save curegit/62978ae76108d189103a07269799807e to your computer and use it in GitHub Desktop.
Save curegit/62978ae76108d189103a07269799807e to your computer and use it in GitHub Desktop.
C# 3種の剰余演算
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