BigInteger.Log Method (BigInteger)

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

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

Syntax

'Declaration
Public Shared Function Log ( _
    value As BigInteger _
) As Double
public static double Log(
    BigInteger value
)

Parameters

Return Value

Type: System.Double
The natural (base e) logarithm of value, as shown in the table in the Remarks section.

Exceptions

Exception Condition
ArgumentOutOfRangeException

The natural log of value is out of range of the Double data type.

Remarks

The value parameter is specified as a base 10 number.

The precise return value of this method depends on the sign of value, as the following table shows.

Sign of value parameter

Return value

Positive

The natural logarithm of value; that is, ln value, or log evalue.

Zero

NegativeInfinity.

Negative

NaN.

To calculate the base 10 logarithm of a BigInteger value, call the Log10 method. To calculate the logarithm of a number in another base, call the Log(BigInteger, Double) method.

You can find the square root of a number by calling the Log method along with the Math.Exp method. Note that the result is Double.PositiveInfinity if the result is greater than Double.MaxValue. The following example calculates the square root of each element in an array of BigInteger values.

Imports System.Numerics

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim values() As BigInteger = { 2, 100, BigInteger.Pow(1000, 100), 
                                     BigInteger.Pow(2, 64) }
      For Each value In values
         outputBlock.Text += String.Format("The square root of {0} is {1}", value,  
                           Math.Exp(BigInteger.Log(value) / 2)) + vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'    The square root of 2 is 1.41421356237309
'    The square root of 100 is 10
'    The square root of 1000000000000000000000000000000000000000000000000000000000000
'    00000000000000000000000000000000000000000000000000000000000000000000000000000000
'    00000000000000000000000000000000000000000000000000000000000000000000000000000000
'    00000000000000000000000000000000000000000000000000000000000000000000000000000000
'     is 9.99999999999988E+149
'    The square root of 18446744073709551616 is 4294967296
using System;
using System.Numerics;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      BigInteger[] values = { 2, 100, BigInteger.Pow(1000, 100), 
                              BigInteger.Pow(2, 64) };
      foreach (var value in values)
         outputBlock.Text += String.Format("The square root of {0} is {1}", value,
                           Math.Exp(BigInteger.Log(value) / 2)) + "\n";
   }
}
// The example displays the following output:
//    The square root of 2 is 1.41421356237309
//    The square root of 100 is 10
//    The square root of 1000000000000000000000000000000000000000000000000000000000000
//    00000000000000000000000000000000000000000000000000000000000000000000000000000000
//    00000000000000000000000000000000000000000000000000000000000000000000000000000000
//    00000000000000000000000000000000000000000000000000000000000000000000000000000000
//     is 9.99999999999988E+149
//    The square root of 18446744073709551616 is 4294967296

This method corresponds to the Math.Log(Double) method for the primitive numeric types.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.