What's the best way to convert the quotient of two C# BigIntegers while retaining as much precision as possible? My current solution is:
Math.Exp(BigInteger.Log(dividend) - BigInteger.Log(divisor));
I'm guessing this is suboptimal.
First read this article. It contains what you want to do.
Then, work out the continued fraction expansion of dividend / divisor, and stop when you reached wanted accuracy. You won't need the full expensive division operation (I suppose it is O(n log^2 n) or something like that), you'll need only integer division / remainder.
Nevertheless, provided BigInteger.Log returns doubles, the exp(log a / log b) thing will work great, and I think it may be faster than the continued fraction expansion. You need two conversions to double (likely fast), and accuracy is preserved throughout the operation (even if log divisor and log dividend are very close to each other).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With