Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Math.Log Method (Double)

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

Namespace:  System
Assemblies:   mscorlib (in mscorlib.dll)
  System.Runtime.Extensions (in System.Runtime.Extensions.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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

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

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft