Skip to content

Commit

Permalink
Revert changes to TimeSpanParse.Pow10
Browse files Browse the repository at this point in the history
  • Loading branch information
lilinus committed Apr 27, 2024
1 parent decf099 commit 267d5e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private static void FormatCustomized<TChar>(
if (tokenLen <= MaxSecondsFractionDigits)
{
int fraction = (int)(dateTime.Ticks % Calendar.TicksPerSecond);
fraction /= TimeSpanParse.Pow10(MaxSecondsFractionDigits - tokenLen);
fraction /= (int)TimeSpanParse.Pow10(MaxSecondsFractionDigits - tokenLen);
if (ch == 'f')
{
FormatFraction(ref result, fraction, fixedNumberFormats[tokenLen - 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private static void FormatCustomized<TChar>(TimeSpan value, scoped ReadOnlySpan<
}

tmp = fraction;
tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
tmp /= (int)TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
DateTimeFormat.FormatFraction(ref result, tmp, DateTimeFormat.fixedNumberFormats[tokenLen - 1]);
break;
case 'F':
Expand All @@ -370,7 +370,7 @@ private static void FormatCustomized<TChar>(TimeSpan value, scoped ReadOnlySpan<
}

tmp = fraction;
tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
tmp /= (int)TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
int effectiveDigits = tokenLen;
while (effectiveDigits > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public bool NormalizeAndValidateFraction()
// .000001 normalize to 10 ticks
// .1 normalize to 1,000,000 ticks

_num *= Pow10(MaxFractionDigits - totalDigitsCount);
_num *= (int)Pow10(MaxFractionDigits - totalDigitsCount);
return true;
}

Expand Down Expand Up @@ -564,22 +564,20 @@ internal bool SetBadFormatSpecifierFailure(char? formatSpecifierCharacter = null
}
}

internal static int Pow10(int pow)
internal static long Pow10(int pow)
{
Debug.Assert(pow >= 0);
Debug.Assert(pow <= MaxFractionDigits);
ReadOnlySpan<int> powersOfTen = [
1,
10,
100,
1000,
10000,
100000,
1000000,
10000000,
];
Debug.Assert(powersOfTen.Length == MaxFractionDigits + 1);
return powersOfTen[pow];
return pow switch
{
0 => 1,
1 => 10,
2 => 100,
3 => 1000,
4 => 10000,
5 => 100000,
6 => 1000000,
7 => 10000000,
_ => (long)Math.Pow(10, pow),
};
}

private static bool TryTimeToTicks(bool positive, TimeSpanToken days, TimeSpanToken hours, TimeSpanToken minutes, TimeSpanToken seconds, TimeSpanToken fraction, out long result)
Expand Down

0 comments on commit 267d5e8

Please sign in to comment.