Jurassic.BigInteger.Log C# (CSharp) Method

Log() public static method

Returns the logarithm of a specified number in a specified base.
public static Log ( BigInteger value, double baseValue ) : double
value BigInteger A number whose logarithm is to be found.
baseValue double The base of the logarithm.
return double
        public static double Log(BigInteger value, double baseValue)
        {
            if (baseValue <= 1.0 || double.IsPositiveInfinity(baseValue) || double.IsNaN(baseValue))
                throw new ArgumentOutOfRangeException("baseValue", "Unsupported logarithmic base.");
            if (value.sign < 0)
                return double.NaN;
            if (value.sign == 0)
                return double.NegativeInfinity;
            if (value.wordCount == 1)
                return Math.Log((double)value.bits[0], baseValue);

            double d = 0.0;
            double residual = 0.5;
            int bitsInLastWord = 32 - CountLeadingZeroBits(value.bits[value.wordCount - 1]);
            int bitCount = ((value.wordCount - 1) * 32) + bitsInLastWord;
            uint highBit = ((uint)1) << (bitsInLastWord - 1);
            for (int i = value.wordCount - 1; i >= 0; i--)
            {
                while (highBit != 0)
                {
                    if ((value.bits[i] & highBit) != 0)
                        d += residual;
                    residual *= 0.5;
                    highBit = highBit >> 1;
                }
                highBit = 0x80000000;
            }
            return ((Math.Log(d) + (0.69314718055994529 * bitCount)) / Math.Log(baseValue));
        }