Update Cryville.Common.

This commit is contained in:
2022-12-13 09:21:52 +08:00
parent 1470fa87dd
commit 815f48fe06
2 changed files with 27 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ namespace Cryville.Common.Buffers {
if (!_invalidated) return;
_invalidated = false;
var ev = OnUpdate;
if (ev != null) OnUpdate.Invoke();
if (ev != null) ev.Invoke();
}
IEnumerator IEnumerable.GetEnumerator() {

View File

@@ -48,5 +48,31 @@ namespace Cryville.Common.Math {
}
}
}
/// <summary>
/// Gets the greatest common divisor (GCD) of two integers.
/// </summary>
/// <param name="n">The first integer.</param>
/// <param name="d">The second integer.</param>
/// <returns>The greatest common divisor (GCD) of the two integers.</returns>
public static int GreatestCommonDivisor(int n, int d) {
while (d != 0) {
int t = d;
d = n % d;
n = t;
}
return n;
}
/// <summary>
/// Simplifies a fraction.
/// </summary>
/// <param name="n">The numerator.</param>
/// <param name="d">The denominator.</param>
public static void Simplify(ref int n, ref int d) {
var gcd = GreatestCommonDivisor(n, d);
n /= gcd;
d /= gcd;
}
}
}