src/NeinMath/IntegerFunctions.cs
/// <summary>
/// Returns the logarithm of a specified Integer in a specified base.
/// </summary>
/// <param name="value">
/// The Integer whose logarithm is to be found.
/// </param>
/// <param name="baseValue">The base of the logarithm.</param>
/// <returns>The result of finding the logarithm.</returns>
Returns the logarithm of a specified Integer in a specified base.
Returns the logarithm of a specified Integer in a specified base .
public static double Log(this Integer value, double baseValue = 2.7182818284590451)
        {
            if (value < 0)
                return double.NaN;
            if (baseValue < 0)
                return double.NaN;
#pragma warning disable RECS0018
            if (baseValue == 0)
                return value != 1 ? double.NaN : 0;
            if (double.IsPositiveInfinity(baseValue))
                return value != 1 ? double.NaN : 0;
            if (double.IsNaN(baseValue))
                return double.NaN;
            if (baseValue == 1)
                return double.NaN;
#pragma warning restore RECS0018
            if (value == 0)
                return baseValue < 1
                    ? double.PositiveInfinity
                    : double.NegativeInfinity;
            var h = (ulong)value.bits[value.length - 1];
            var m = (ulong)(value.length > 1
                ? value.bits[value.length - 2] : 0);
            var l = (ulong)(value.length > 2
                ? value.bits[value.length - 3] : 0);
            var z = Bits.LeadingZeros((uint)h);
            var y = value.length * 32 - z - 1.0;
            var x = (h << 32 + z) | (m << z) | (l >> 32 - z);
            return (y + Math.Log(x, 2) - 63) / Math.Log(baseValue, 2);
        }
public static double Log ( this Integer value , double baseValue = 2.7182818284590451 ) { if ( value < 0 ) return double . NaN ; if ( baseValue < 0 ) return double . NaN ; pragma warning disable RECS0018 if ( baseValue == 0 ) return value != 1 ? double . NaN : 0 ; if ( double . IsPositiveInfinity ( baseValue ) ) return value != 1 ? double . NaN : 0 ; if ( double . IsNaN ( baseValue ) ) return double . NaN ; if ( baseValue == 1 ) return double . NaN ; pragma warning restore RECS0018 if ( value == 0 ) return baseValue < 1 ? double . PositiveInfinity : double . NegativeInfinity ; var h = ( ulong ) value . bits [ value . length - 1 ] ; var m = ( ulong ) ( value . length > 1 ? value . bits [ value . length - 2 ] : 0 ) ; var l = ( ulong ) ( value . length > 2 ? value . bits [ value . length - 3 ] : 0 ) ; var z = Bits . LeadingZeros ( ( uint ) h ) ; var y = value . length * 32 - z - 1.0 ; var x = ( h << 32 + z ) | ( m << z ) | ( l >> 32 - z ) ; return ( y + Math . Log ( x , 2 ) - 63 ) / Math . Log ( baseValue , 2 ) ; }
Returns the logarithm of a specified Integer in a specified base.
Returns the logarithm of a specified Integer in a specified base .
// extract most significant bits // combine with bit count (log2)
The result of finding the logarithm.
The result of finding the logarithm .
Integer
this
baseValue
double
The base of the logarithm.
The base of the logarithm .
value
The Integer whose logarithm is to be found.
The Integer whose logarithm is to be found .