Export (0) Print
Expand All

Math.Log Method (Double)

Returns the natural (base e) logarithm of a specified number.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static double Log(
	double d
)

Parameters

d
Type: System.Double

The number whose logarithm is to be found.

Return Value

Type: System.Double
One of the values in the following table.

d parameter

Return value

Positive

The natural logarithm of d; that is, ln d, or log e d

Zero

NegativeInfinity

Negative

NaN

Equal to NaN

NaN

Equal to PositiveInfinity

PositiveInfinity

Parameter d is specified as a base 10 number.

The following example illustrates the Log method.

using System;
public class Example
{
   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[] XArgs = { 1.2, 4.9, 9.9, 0.1 };

      foreach (double argX in XArgs)
      {
         // Find natural log of argX.
         Console.WriteLine("                      Math.Log({0}) = {1:E16}",
                           argX, Math.Log(argX));

         // Evaluate 1 / log[X](e).
         Console.WriteLine("             1.0 / Math.Log(e, {0}) = {1:E16}",
                           argX, 1.0 / Math.Log(Math.E, argX));
         Console.WriteLine();
      }
   }   
}
// This example displays the following output: 
//         Evaluate this identity with selected values for X: 
//                                     ln(x) = 1 / log[X](B) 
//        
//                             Math.Log(1.2) = 1.8232155679395459E-001 
//                    1.0 / Math.Log(e, 1.2) = 1.8232155679395459E-001 
//        
//                             Math.Log(4.9) = 1.5892352051165810E+000 
//                    1.0 / Math.Log(e, 4.9) = 1.5892352051165810E+000 
//        
//                             Math.Log(9.9) = 2.2925347571405443E+000 
//                    1.0 / Math.Log(e, 9.9) = 2.2925347571405443E+000 
//        
//                             Math.Log(0.1) = -2.3025850929940455E+000 
//                    1.0 / Math.Log(e, 0.1) = -2.3025850929940455E+000

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft