BigInteger.Log 方法

定義

傳回指定數字的對數。

多載

Log(BigInteger)

傳回指定數字的自然 (底數為 e) 對數。

Log(BigInteger, Double)

傳回指定底數中指定數字的對數。

Log(BigInteger)

傳回指定數字的自然 (底數為 e) 對數。

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

要找出其對數的數字。

傳回

value 的 (以 e 為底數) 自然對數,如<備註>一節中的表格所示。

例外狀況

value 的自然對數超出 Double 資料型別範圍。

備註

參數 value 會指定為基底 10 個數字。

這個方法的精確傳回值取決於 的 value 正負號,如下表所示。

參數的 value 符號 傳回值
的自然對數 value ;也就是 ln value 或 log e value
NegativeInfinity.
NaN.

若要計算值的基底 10 對數 BigInteger ,請呼叫 Log10 方法。 若要計算另一個基底中數位的對數,請呼叫 Log(BigInteger, Double) 方法。

您可以藉由呼叫 Log 方法以及 Math.Exp 方法來尋找數位的平方根。 請注意,如果結果大於 Double.MaxValue ,則結果為 Double.PositiveInfinity 。 下列範例會計算值陣列 BigInteger 中每個專案的平方根。

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) 基本數數值型別的 方法。

另請參閱

適用於

Log(BigInteger, Double)

傳回指定底數中指定數字的對數。

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

要找出其對數的數字。

baseValue
Double

對數的底數。

傳回

baseValue 的以 value 為底數的對數,如<備註>一節中的表格所示。

例外狀況

value 的對數超出 Double 資料型別範圍。

備註

valuebaseValue 參數會指定為 10 個數字的基底。

方法的精確傳回值取決於 的 value 正負號和 的正負號和值 baseValue ,如下表所示。

value 參數 baseValue 參數 傳回值
value> 0 (0 <baseValue< 1) -或-(baseValue> 1) logbaseValue (value)
value< 0 (任意值) Double.NaN
(任意值) baseValue< 0 Double.NaN
value != 1 baseValue = 0 Double.NaN
value != 1 baseValue = Double.PositiveInfinity Double.NaN
(任意值) baseValue = Double.NaN Double.NaN
(任意值) 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

若要計算值的基底 10 對數 BigInteger ,請呼叫 Log10 方法。 若要計算數位的自然對數,請呼叫 Log(BigInteger) 方法。

這個方法會對應至 Math.Log 基本數數值型別的 方法。

另請參閱

適用於