Math.Pow(Double, Double) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回指定数字的指定次幂。
public:
static double Pow(double x, double y);
public static double Pow (double x, double y);
static member Pow : double * double -> double
Public Shared Function Pow (x As Double, y As Double) As Double
参数
- x
- Double
要乘幂的双精度浮点数。
- y
- Double
指定幂的双精度浮点数。
返回
数字 x
的 y
次幂。
示例
以下示例使用 Pow 方法计算将 2 提高到 0 到 32 的幂产生的值。
int value = 2;
for (int power = 0; power <= 32; power++)
Console.WriteLine($"{value}^{power} = {(long)Math.Pow(value, power):N0} (0x{(long)Math.Pow(value, power):X})");
// The example displays the following output:
// 2^0 = 1 (0x1)
// 2^1 = 2 (0x2)
// 2^2 = 4 (0x4)
// 2^3 = 8 (0x8)
// 2^4 = 16 (0x10)
// 2^5 = 32 (0x20)
// 2^6 = 64 (0x40)
// 2^7 = 128 (0x80)
// 2^8 = 256 (0x100)
// 2^9 = 512 (0x200)
// 2^10 = 1,024 (0x400)
// 2^11 = 2,048 (0x800)
// 2^12 = 4,096 (0x1000)
// 2^13 = 8,192 (0x2000)
// 2^14 = 16,384 (0x4000)
// 2^15 = 32,768 (0x8000)
// 2^16 = 65,536 (0x10000)
// 2^17 = 131,072 (0x20000)
// 2^18 = 262,144 (0x40000)
// 2^19 = 524,288 (0x80000)
// 2^20 = 1,048,576 (0x100000)
// 2^21 = 2,097,152 (0x200000)
// 2^22 = 4,194,304 (0x400000)
// 2^23 = 8,388,608 (0x800000)
// 2^24 = 16,777,216 (0x1000000)
// 2^25 = 33,554,432 (0x2000000)
// 2^26 = 67,108,864 (0x4000000)
// 2^27 = 134,217,728 (0x8000000)
// 2^28 = 268,435,456 (0x10000000)
// 2^29 = 536,870,912 (0x20000000)
// 2^30 = 1,073,741,824 (0x40000000)
// 2^31 = 2,147,483,648 (0x80000000)
// 2^32 = 4,294,967,296 (0x100000000)
open System
let value = 2
for power = 0 to 32 do
printfn $"{value}^{power} = {Math.Pow(value, power) |> int64:N0} (0x{Math.Pow(value, power) |> int64:X})"
// The example displays the following output:
// 2^0 = 1 (0x1)
// 2^1 = 2 (0x2)
// 2^2 = 4 (0x4)
// 2^3 = 8 (0x8)
// 2^4 = 16 (0x10)
// 2^5 = 32 (0x20)
// 2^6 = 64 (0x40)
// 2^7 = 128 (0x80)
// 2^8 = 256 (0x100)
// 2^9 = 512 (0x200)
// 2^10 = 1,024 (0x400)
// 2^11 = 2,048 (0x800)
// 2^12 = 4,096 (0x1000)
// 2^13 = 8,192 (0x2000)
// 2^14 = 16,384 (0x4000)
// 2^15 = 32,768 (0x8000)
// 2^16 = 65,536 (0x10000)
// 2^17 = 131,072 (0x20000)
// 2^18 = 262,144 (0x40000)
// 2^19 = 524,288 (0x80000)
// 2^20 = 1,048,576 (0x100000)
// 2^21 = 2,097,152 (0x200000)
// 2^22 = 4,194,304 (0x400000)
// 2^23 = 8,388,608 (0x800000)
// 2^24 = 16,777,216 (0x1000000)
// 2^25 = 33,554,432 (0x2000000)
// 2^26 = 67,108,864 (0x4000000)
// 2^27 = 134,217,728 (0x8000000)
// 2^28 = 268,435,456 (0x10000000)
// 2^29 = 536,870,912 (0x20000000)
// 2^30 = 1,073,741,824 (0x40000000)
// 2^31 = 2,147,483,648 (0x80000000)
// 2^32 = 4,294,967,296 (0x100000000)
Public Module Example
Public Sub Main
Dim value As Integer = 2
For power As Integer = 0 To 32
Console.WriteLine("{0}^{1} = {2:N0} (0x{2:X})", _
value, power, CLng(Math.Pow(value, power)))
Next
End Sub
End Module
' The example displays the following output:
' 2^0 = 1 (0x1)
' 2^1 = 2 (0x2)
' 2^2 = 4 (0x4)
' 2^3 = 8 (0x8)
' 2^4 = 16 (0x10)
' 2^5 = 32 (0x20)
' 2^6 = 64 (0x40)
' 2^7 = 128 (0x80)
' 2^8 = 256 (0x100)
' 2^9 = 512 (0x200)
' 2^10 = 1,024 (0x400)
' 2^11 = 2,048 (0x800)
' 2^12 = 4,096 (0x1000)
' 2^13 = 8,192 (0x2000)
' 2^14 = 16,384 (0x4000)
' 2^15 = 32,768 (0x8000)
' 2^16 = 65,536 (0x10000)
' 2^17 = 131,072 (0x20000)
' 2^18 = 262,144 (0x40000)
' 2^19 = 524,288 (0x80000)
' 2^20 = 1,048,576 (0x100000)
' 2^21 = 2,097,152 (0x200000)
' 2^22 = 4,194,304 (0x400000)
' 2^23 = 8,388,608 (0x800000)
' 2^24 = 16,777,216 (0x1000000)
' 2^25 = 33,554,432 (0x2000000)
' 2^26 = 67,108,864 (0x4000000)
' 2^27 = 134,217,728 (0x8000000)
' 2^28 = 268,435,456 (0x10000000)
' 2^29 = 536,870,912 (0x20000000)
' 2^30 = 1,073,741,824 (0x40000000)
' 2^31 = 2,147,483,648 (0x80000000)
' 2^32 = 4,294,967,296 (0x100000000)
注解
下表指示为 x
和 y
参数指定各种值或值范围时的返回值。 有关详细信息,请参阅Double.PositiveInfinity、Double.NegativeInfinity和Double.NaN。
x | y | 返回值 |
---|---|---|
除 NaN |
±0 | 1 |
NaN |
±0 | .NET Framework) NaN 上的 1 个 (* |
NaN |
除 0 之外的任何值 | NaN * |
±0 | < 0 和奇数整数 |
NegativeInfinity 或 PositiveInfinity |
±0 | NegativeInfinity |
PositiveInfinity |
±0 | PositiveInfinity |
+0 |
±0 | > 0 和奇数整数 | ±0 |
-1 |
NegativeInfinity 或 PositiveInfinity |
1 |
+1 | 除 NaN |
1 |
+1 | NaN |
.NET Framework) NaN 上的 1 个 (* |
1 以外的任何值 | NaN |
NaN * |
-1 < x < 1 | PositiveInfinity |
+0 |
< -1 或 > 1 | PositiveInfinity |
PositiveInfinity |
-1 < x < 1 | NegativeInfinity |
PositiveInfinity |
< -1 或 > 1 | NegativeInfinity |
+0 |
PositiveInfinity |
< 0 | +0 |
PositiveInfinity |
> 0 | PositiveInfinity |
NegativeInfinity |
< 0 和有限和奇数整数 | -0 |
NegativeInfinity |
> 0 和有限和奇数整数 | NegativeInfinity |
NegativeInfinity |
< 0 和有限整数,而不是奇数 | +0 |
NegativeInfinity |
> 0 和有限整数,而不是奇数 | PositiveInfinity |
±0 | < 0 和有限整数,而不是奇数 | PositiveInfinity |
±0 | > 0 和有限整数,而不是奇数 | +0 |
< 0 但不是 NegativeInfinity |
有限非整数 | NaN |
* 这些行不显示在 IEEE Standard for Floating-Point 算术定义的完整规则pow
集中。 之所以将其包含在内,是因为 .NET 禁用 IEEE 754 浮点异常,因此不区分 qNaN
(安静的 NaN) 和 sNaN
(向 NaN 发出信号) 。
IEEE 754 规范允许禁用此异常。
此方法调用基础 C 运行时,不同的操作系统或体系结构之间的确切结果或有效输入范围可能会有所不同。