Fix implementation of `NumberExtensions.Log10` and add docs

fixes fbd45915c
This commit is contained in:
YoshiRulz 2025-02-13 22:19:49 +10:00
parent cf70cc9ef4
commit 7568a29912
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 7 additions and 2 deletions

View File

@ -127,15 +127,20 @@ namespace BizHawk.Common.NumberExtensions
}
}
/// <returns>
/// <c>-1</c> when <paramref name="i"/> when is negative or <c>0</c>,
/// otherwise the (floor of the) base-10 logarithm of that value i.e. 1 less than the number of decimal digits
/// </returns>
public static int Log10(int i)
{
if (i <= 0) return -1;
var toReturn = 0;
while (i > 100)
while (i >= 100)
{
i /= 100;
toReturn += 2;
}
return i > 10 ? toReturn + 1 : toReturn;
return i >= 10 ? toReturn + 1 : toReturn;
}
/// <summary>