Add `Log10(int)` helper

This commit is contained in:
YoshiRulz 2025-02-13 08:38:45 +10:00
parent 6049d5e4f5
commit fbd45915cb
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 12 additions and 1 deletions

View File

@ -296,7 +296,7 @@ namespace BizHawk.Client.EmuHawk
/// <returns><paramref name="index"/> with leading zeroes such that every frame in the movie will be printed with the same number of digits</returns>
private string FrameToStringPadded(int index)
=> index.ToString(_formatCache[(int)Math.Log10(Math.Max(CurrentTasMovie.InputLogLength, 1))]);
=> index.ToString(_formatCache[NumberExtensions.Log10(Math.Max(CurrentTasMovie.InputLogLength, 1))]);
private void TasView_QueryItemText(int index, RollColumn column, out string text, ref int offsetX, ref int offsetY)
{

View File

@ -127,6 +127,17 @@ namespace BizHawk.Common.NumberExtensions
}
}
public static int Log10(int i)
{
var toReturn = 0;
while (i > 100)
{
i /= 100;
toReturn += 2;
}
return i > 10 ? toReturn + 1 : toReturn;
}
/// <summary>
/// Receives a number and returns the number of hexadecimal digits it is
/// Note: currently only returns 2, 4, 6, or 8