Skip to content

Commit

Permalink
Update src/libraries/System.Private.CoreLib/src/System/UInt128.cs
Browse files Browse the repository at this point in the history
Co-authored-by: Günther Foidl <gue@korporal.at>
  • Loading branch information
Daniel-Svensson and gfoidl committed Mar 14, 2024
1 parent a032637 commit f236089
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/UInt128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,10 @@ public static UInt128 Log2(UInt128 value)
ulong highRes = 0ul;
ulong remainder = left._upper;

// We might need 2 division to avoid overflow
if (remainder >= right._lower)
(highRes, remainder) = X86Base.X64.DivRem(remainder, 0, right._lower);
{
(highRes, remainder) = X86Base.X64.DivRem(left._upper, 0, right._lower);
}

return new UInt128(highRes, X86Base.X64.DivRem(left._lower, remainder, right._lower).Quotient);
}
Expand Down

0 comments on commit f236089

Please sign in to comment.