Getting the relationship of two BigIntegers as doubles

What is the best way to convert the quotient of two C # BigIntegers while maintaining the greatest possible accuracy? My current solution:

Math.Exp(BigInteger.Log(dividend) - BigInteger.Log(divisor)); 

I assume this is not optimal.

+6
math c #
source share
1 answer

Read this article first . It contains what you want to do.

Then, work out the continuation of the dividend / dividend decomposition, and stop when you reach the required accuracy. You won’t need a complete expensive division operation (I suppose it is O (n log ^ 2 n) or something like that), you only need integer division / remainder.

However, if BigInteger.Log returns a doubling, the exp (log a / log b) thing will work fine, and I think it might be faster than continuing the beat. You need two conversions to double (probably quickly), and accuracy is maintained throughout the operation (even if the logarithmic divider and the logarithmic dividend are very close to each other).

+3
source share

All Articles