Uh oh!
There was an error while loading. Please reload this page.
Optimize BigInteger.ToString for large decimal string - #104676
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics |
| // The Ratio is calculated as: log_{10^9}(2^32) | ||
| const double digitRatio = 1.0703288734719332; | ||
| Debug.Assert(BigInteger.MaxLength * digitRatio + 1 < Array.MaxLength); // won't overflow |
There was a problem hiding this comment.
If the length doesn't need to be exact, you can use integer estimation instead, similar to what I did in NumberToBigInteger.
There was a problem hiding this comment.
Which part are you referring to? NumberToBigInteger also used
runtime/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs
Lines 562 to 573 in 264e39c
I rewrote it to use
runtime/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs
Lines 372 to 379 in 0d426df
| return (MaxPartialDigits * (1 << index)) >> 5; | ||
| } | ||
| public static void FloorBufferSize(int size, out int bufferSize, out int maxIndex) |
There was a problem hiding this comment.
Is it required to calculate exact buffer length? Can it be relaxed, and let the algorithm to strip unnecessary zeros?
There was a problem hiding this comment.
Is there a concise way to calculate the inexact buffer length? It would be most concise to find out from the predefined buffer length.
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
This PR is a counterpart to #55121. divide-and-conquer algorithm
Number.FormatBigInteger() can run in$D(n)log(N)$ time using the Divide and Conquer algorithm, where $D(n)$ represents the computational complexity of BigInteger division.
The computational complexity of division will be improved by #96895. Once 96895 is merged, I will add a benchmark and set the PR to "ready for review."