BigInteger.Log 方法

定义

返回指定数字的对数。Returns the logarithm of a specified number.

重载

Log(BigInteger)

返回指定数字的自然对数(底为 e)。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)

返回指定数字的自然对数(底为 e)。Returns the natural (base e) logarithm of a specified number.

public:
 static double Log(System::Numerics::BigInteger value);
public static double Log (System.Numerics.BigInteger value);
static member Log : System.Numerics.BigInteger -> double
Public Shared Function Log (value As BigInteger) As Double

参数

value
BigInteger

要查找其对数的数字。The number whose logarithm is to be found.

返回

e 的自然对数(底为 value),如“备注”部分中的表所示。The natural (base e) logarithm of value, as shown in the table in the Remarks section.

例外

value 的自然对数超出了 Double 数据类型的范围。The natural log of value is out of range of the Double data type.

注解

value 参数指定为以10为基数的数字。The value parameter is specified as a base 10 number.

此方法的准确返回值取决于 value的符号,如下表所示。The precise return value of this method depends on the sign of value, as the following table shows.

value 参数的符号Sign of value parameter 返回值Return value
Positive value的自然对数;即 ln value或 log evalueThe natural logarithm of value; that is, ln value, or log evalue.
Zero NegativeInfinityNegativeInfinity.
负数Negative NaNNaN.

若要计算 BigInteger 值以10为底的对数,请调用 Log10 方法。To calculate the base 10 logarithm of a BigInteger value, call the Log10 method. 若要计算某个数在另一个基中的对数,请调用 Log(BigInteger, Double) 方法。To calculate the logarithm of a number in another base, call the Log(BigInteger, Double) method.

可以通过调用 Log 方法以及 Math.Exp 方法来查找数字的平方根。You can find the square root of a number by calling the Log method along with the Math.Exp method. 请注意,如果结果大于 Double.MaxValue,则结果 Double.PositiveInfinityNote that the result is Double.PositiveInfinity if the result is greater than Double.MaxValue. 下面的示例计算 BigInteger 值的数组中每个元素的平方根。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
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim values() As BigInteger = { 2, 100, BigInteger.Pow(1000, 100), 
                                     BigInteger.Pow(2, 64) }
      For Each value In values                                    
         Console.WriteLine("The square root of {0} is {1}", value, 
                           Math.Exp(BigInteger.Log(value) / 2))
      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

此方法对应于基元数值类型的 Math.Log(Double) 方法。This method corresponds to the Math.Log(Double) method for the primitive numeric types.

另请参阅

Log(BigInteger, Double)

返回指定数字在使用指定底时的对数。Returns the logarithm of a specified number in a specified base.

public:
 static double Log(System::Numerics::BigInteger value, double baseValue);
public static double Log (System.Numerics.BigInteger value, double baseValue);
static member Log : System.Numerics.BigInteger * double -> double
Public Shared Function Log (value As BigInteger, baseValue As Double) As Double

参数

value
BigInteger

要查找其对数的数字。A number whose logarithm is to be found.

baseValue
Double

对数的底。The base of the logarithm.

返回

baseValue 的以 value 为底的对数,如“备注”部分中的表所示。The base baseValue logarithm of value, as shown in the table in the Remarks section.

例外

value 的对数超出了 Double 数据类型的范围。The log of value is out of range of the Double data type.

注解

valuebaseValue 参数指定为以10为基数的数字。The value and baseValue parameters are specified as base 10 numbers.

此方法的准确返回值取决于 baseValue的符号和值上的 value 和的符号,如下表所示。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 参数value parameter baseValue 参数baseValue parameter 返回值Return value
value > 0value > 0 (0 < baseValue < 1)-或-(baseValue > 1)(0 < baseValue < 1) -or-(baseValue > 1) logbaseValue (valuelogbaseValue(value)
value < 0value < 0 (任意值)(any value) Double.NaN
(任意值)(any value) baseValue < 0baseValue < 0 Double.NaN
value != 1value != 1 baseValue = 0baseValue = 0 Double.NaN
value != 1value != 1 baseValue = Double.PositiveInfinity Double.NaN
(任意值)(any value) baseValue = Double.NaN Double.NaN
(任意值)(any value) baseValue = 1baseValue = 1 Double.NaN
value = 0value = 0 0 < baseValue < 10 < baseValue < 1 Double.PositiveInfinity
value = 0value = 0 baseValue > 1baseValue > 1 Double.PositiveInfinity
value = 1value = 1 baseValue = 0baseValue = 0 00
value = 1value = 1 baseValue = Double.PositiveInfinity 00

若要计算 BigInteger 值以10为底的对数,请调用 Log10 方法。To calculate the base 10 logarithm of a BigInteger value, call the Log10 method. 若要计算某个数的自然对数,请调用 Log(BigInteger) 方法。To calculate the natural logarithm of a number, call the Log(BigInteger) method.

此方法对应于基元数值类型的 Math.Log 方法。This method corresponds to the Math.Log method for the primitive numeric types.

另请参阅

适用于