Double - Log

Returns the logarithm of a specified number in a specified base.

Try it

public static void Main()
{
    Console.WriteLine("  Evaluate this identity with selected values for X:");
    Console.WriteLine("                              ln(x) = 1 / log[X](B)");
    Console.WriteLine();

    double[] values = { 1.2, 4.9, 9.9, 0.1 };

    foreach (double value in values)
    {		
		// C# Extension Method: Double - Log
        Console.WriteLine("                      Log({0}) = {1:E16}", value, value.Log());

        // C# Extension Method: Double - Log
        double e = Math.E;
        Console.WriteLine("             1.0 / Log(e, {0}) = {1:E16}", value, 1.0 / e.Log(value));
        Console.WriteLine();
    }
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Returns the natural (base e) logarithm of a specified number.
    /// </summary>
    /// <param name="d">The number whose logarithm is to be found.</param>
    /// <returns>
    ///     One of the values in the following table.  parameterReturn value Positive The natural logarithm of ; that is,
    ///     ln , or log eZero Negative Equal to Equal to.
    /// </returns>
    public static Double Log(this Double d)
    {
        return Math.Log(d);
    }

    /// <summary>
    ///     Returns the logarithm of a specified number in a specified base.
    /// </summary>
    /// <param name="d">The number whose logarithm is to be found.</param>
    /// <param name="newBase">The base of the logarithm.</param>
    /// <returns>
    ///     One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .)Return
    ///     value&gt; 0(0 &lt;&lt; 1) -or-(&gt; 1)lognewBase(a)&lt; 0(any value)NaN(any value)&lt; 0NaN != 1 = 0NaN != 1
    ///     = +InfinityNaN = NaN(any value)NaN(any value) = NaNNaN(any value) = 1NaN = 00 &lt;&lt; 1 +Infinity = 0&gt; 1-
    ///     Infinity =  +Infinity0 &lt;&lt; 1-Infinity =  +Infinity&gt; 1+Infinity = 1 = 00 = 1 = +Infinity0.
    /// </returns>
    /// ###
    /// <param name="a">The number whose logarithm is to be found.</param>
    public static Double Log(this Double d, Double newBase)
    {
        return Math.Log(d, newBase);
    }
}