This documentation is archived and is not being maintained.

# Math.Log Method (Double, Double)

.NET Framework 2.0

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

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

## Syntax

```public static double Log (
double a,
double newBase
)
```
```public static double Log (
double a,
double newBase
)
```
```public static function Log (
a : double,
newBase : double
) : double
```

#### Parameters

a

A number whose logarithm is to be found.

newBase

The base of the logarithm.

#### Return Value

In the following table +Infinity denotes PositiveInfinity, -Infinity denotes NegativeInfinity, and NaN denotes NaN.

a

newBase

Return Value

a > 0

(0 <newBase< 1) -or-(newBase> 1)

lognewBase(a)

a < 0

(any value)

NaN

(any value)

newBase < 0

NaN

a != 1

newBase = 0

NaN

a != 1

newBase = +Infinity

NaN

a = NaN

(any value)

NaN

(any value)

newBase = NaN

NaN

(any value)

newBase = 1

NaN

a = 0

0 <newBase< 1

+Infinity

a = 0

newBase > 1

-Infinity

a = +Infinity

0 <newBase< 1

-Infinity

a = +Infinity

newBase > 1

+Infinity

a = 1

newBase = 0

0

a = 1

newBase = +Infinity

0

## Remarks

Parameters a and newBase are specified as base 10 numbers.

## Example

The following example uses Log to evaluate certain logarithmic identities for selected values.

```// Example for the Math.Log( double ) and Math.Log( double, double ) methods.
using System;

class LogDLogDD
{
public static void Main()
{
Console.WriteLine(
"This example of Math.Log( double ) and " +
"Math.Log( double, double )\n" +
"generates the following output.\n" );
Console.WriteLine(
"Evaluate these identities with " +
"selected values for X and B (base):" );
Console.WriteLine( "   log(B)[X] == 1 / log(X)[B]" );
Console.WriteLine( "   log(B)[X] == ln[X] / ln[B]" );
Console.WriteLine( "   log(B)[X] == log(B)[e] * ln[X]" );

UseBaseAndArg(0.1, 1.2);
UseBaseAndArg(1.2, 4.9);
UseBaseAndArg(4.9, 9.9);
UseBaseAndArg(9.9, 0.1);
}

// Evaluate logarithmic identities that are functions of two arguments.
static void UseBaseAndArg(double argB, double argX)
{
// Evaluate log(B)[X] == 1 / log(X)[B].
Console.WriteLine(
"\n                   Math.Log({1}, {0}) == {2:E16}" +
"\n             1.0 / Math.Log({0}, {1}) == {3:E16}",
argB, argX, Math.Log(argX, argB),
1.0 / Math.Log(argB, argX) );

// Evaluate log(B)[X] == ln[X] / ln[B].
Console.WriteLine(
"        Math.Log({1}) / Math.Log({0}) == {2:E16}",
argB, argX, Math.Log(argX) / Math.Log(argB) );

// Evaluate log(B)[X] == log(B)[e] * ln[X].
Console.WriteLine(
"Math.Log(Math.E, {0}) * Math.Log({1}) == {2:E16}",
argB, argX, Math.Log(Math.E, argB) * Math.Log(argX) );
}
}

/*
This example of Math.Log( double ) and Math.Log( double, double )
generates the following output.

Evaluate these identities with selected values for X and B (base):
log(B)[X] == 1 / log(X)[B]
log(B)[X] == ln[X] / ln[B]
log(B)[X] == log(B)[e] * ln[X]

Math.Log(1.2, 0.1) == -7.9181246047624818E-002
1.0 / Math.Log(0.1, 1.2) == -7.9181246047624818E-002
Math.Log(1.2) / Math.Log(0.1) == -7.9181246047624818E-002
Math.Log(Math.E, 0.1) * Math.Log(1.2) == -7.9181246047624804E-002

Math.Log(4.9, 1.2) == 8.7166610085093179E+000
1.0 / Math.Log(1.2, 4.9) == 8.7166610085093161E+000
Math.Log(4.9) / Math.Log(1.2) == 8.7166610085093179E+000
Math.Log(Math.E, 1.2) * Math.Log(4.9) == 8.7166610085093179E+000

Math.Log(9.9, 4.9) == 1.4425396251981288E+000
1.0 / Math.Log(4.9, 9.9) == 1.4425396251981288E+000
Math.Log(9.9) / Math.Log(4.9) == 1.4425396251981288E+000
Math.Log(Math.E, 4.9) * Math.Log(9.9) == 1.4425396251981288E+000

Math.Log(0.1, 9.9) == -1.0043839404494075E+000
1.0 / Math.Log(9.9, 0.1) == -1.0043839404494075E+000
Math.Log(0.1) / Math.Log(9.9) == -1.0043839404494075E+000
Math.Log(Math.E, 9.9) * Math.Log(0.1) == -1.0043839404494077E+000
*/

```
```// Example for the Math.Log( double ) and Math.Log( double, double ) methods.
import System.*;

class LogDLogDD
{

public static void main(String[] args)
{
Console.WriteLine(("This example of Math.Log( double ) and "
+ "Math.Log( double, double )\n"
+ "generates the following output.\n"));
Console.WriteLine(("Evaluate these identities with "
+ "selected values for X and B (base):"));
Console.WriteLine("   log(B)[X] == 1 / log(X)[B]");
Console.WriteLine("   log(B)[X] == ln[X] / ln[B]");
Console.WriteLine("   log(B)[X] == log(B)[e] * ln[X]");
UseBaseAndArg(0.1, 1.2);
UseBaseAndArg(1.2, 4.9);
UseBaseAndArg(4.9, 9.9);
UseBaseAndArg(9.9, 0.1);
} //main

// Evaluate logarithmic identities that are functions of two arguments.
static void UseBaseAndArg(double argB, double argX)
{
// Evaluate log(B)[X] == 1 / log(X)[B].
Console.WriteLine("\n                   Math.Log({1}, {0}) == {2}"
+ "\n             1.0 / Math.Log({0}, {1}) == {3}", new Object[] {
System.Convert.ToString(argB), System.Convert.ToString(argX),
((System.Double)(System.Math.Log(argX, argB))).ToString("E16"),
((System.Double)(1.0 / System.Math.Log(argB, argX))).ToString
("E16")});

// Evaluate log(B)[X] == ln[X] / ln[B].
Console.WriteLine("        Math.Log({1}) / Math.Log({0}) == {2}",
System.Convert.ToString(argB), System.Convert.ToString(argX),
((System.Double)
(System.Math.Log(argX) / System.Math.Log(argB))).ToString("E16"));

// Evaluate log(B)[X] == log(B)[e] * ln[X].
Console.WriteLine("Math.Log(Math.E, {0}) * Math.Log({1}) == {2}",
System.Convert.ToString(argB), System.Convert.ToString(argX),
((System.Double)(System.Math.Log(Math.E, argB)
* System.Math.Log(argX))).ToString("E16"));
} //UseBaseAndArg
} //LogDLogDD

/*
This example of Math.Log( double ) and Math.Log( double, double )
generates the following output.

Evaluate these identities with selected values for X and B (base):
log(B)[X] == 1 / log(X)[B]
log(B)[X] == ln[X] / ln[B]
log(B)[X] == log(B)[e] * ln[X]

Math.Log(1.2, 0.1) == -7.9181246047624818E-002
1.0 / Math.Log(0.1, 1.2) == -7.9181246047624818E-002
Math.Log(1.2) / Math.Log(0.1) == -7.9181246047624818E-002
Math.Log(Math.E, 0.1) * Math.Log(1.2) == -7.9181246047624804E-002

Math.Log(4.9, 1.2) == 8.7166610085093179E+000
1.0 / Math.Log(1.2, 4.9) == 8.7166610085093161E+000
Math.Log(4.9) / Math.Log(1.2) == 8.7166610085093179E+000
Math.Log(Math.E, 1.2) * Math.Log(4.9) == 8.7166610085093179E+000

Math.Log(9.9, 4.9) == 1.4425396251981288E+000
1.0 / Math.Log(4.9, 9.9) == 1.4425396251981288E+000
Math.Log(9.9) / Math.Log(4.9) == 1.4425396251981288E+000
Math.Log(Math.E, 4.9) * Math.Log(9.9) == 1.4425396251981288E+000

Math.Log(0.1, 9.9) == -1.0043839404494075E+000
1.0 / Math.Log(9.9, 0.1) == -1.0043839404494075E+000
Math.Log(0.1) / Math.Log(9.9) == -1.0043839404494075E+000
Math.Log(Math.E, 9.9) * Math.Log(0.1) == -1.0043839404494077E+000
*/

```

## Platforms

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

## Version Information

#### .NET Framework

Supported in: 2.0, 1.1, 1.0

Math Class
Math Members
System Namespace
Show: