BigInteger.Log Method

Definition

Returns the logarithm of a specified number.

Overloads

Log(BigInteger)

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

Log(BigInteger, Double)

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

Log(BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public static double Log (System.Numerics.BigInteger value);

Parameters

value
BigInteger

The number whose logarithm is to be found.

Returns

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

Exceptions

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.

using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      BigInteger[] values = { 2, 100, BigInteger.Pow(1000, 100), 
                              BigInteger.Pow(2, 64) };
      foreach (var value in values)                                    
         Console.WriteLine("The square root of {0} is {1}", value, 
                           Math.Exp(BigInteger.Log(value) / 2));
   }
}
// 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.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Log(BigInteger, Double)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public static double Log (System.Numerics.BigInteger value, double baseValue);

Parameters

value
BigInteger

A number whose logarithm is to be found.

baseValue
Double

The base of the logarithm.

Returns

The base baseValue logarithm of value, as shown in the table in the Remarks section.

Exceptions

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

Remarks

The value and baseValue parameters are specified as base 10 numbers.

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

value parameter baseValue parameter Return value
value > 0 (0 < baseValue < 1) -or-(baseValue > 1) logbaseValue(value)
value < 0 (any value) Double.NaN
(any value) baseValue < 0 Double.NaN
value != 1 baseValue = 0 Double.NaN
value != 1 baseValue = Double.PositiveInfinity Double.NaN
(any value) baseValue = Double.NaN Double.NaN
(any value) baseValue = 1 Double.NaN
value = 0 0 < baseValue < 1 Double.PositiveInfinity
value = 0 baseValue > 1 Double.PositiveInfinity
value = 1 baseValue = 0 0
value = 1 baseValue = Double.PositiveInfinity 0

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

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

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0