Double - Log
Returns the logarithm of a specified number in a specified base.
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> 0(0 << 1) -or-(> 1)lognewBase(a)< 0(any value)NaN(any value)< 0NaN != 1 = 0NaN != 1 /// = +InfinityNaN = NaN(any value)NaN(any value) = NaNNaN(any value) = 1NaN = 00 << 1 +Infinity = 0> 1- /// Infinity = +Infinity0 << 1-Infinity = +Infinity> 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); } }