Leer en inglés

Compartir a través de


Math.Pow(Double, Double) Método

Definición

Devuelve un número especificado elevado a la potencia especificada.

C#
public static double Pow(double x, double y);

Parámetros

x
Double

Número de punto flotante de precisión doble que se desea elevar a una potencia.

y
Double

Número de punto flotante de precisión doble que especifica una potencia.

Devoluciones

Número x elevado a la potencia y.

Ejemplos

En el ejemplo siguiente se usa el Pow método para calcular el valor resultante de elevar 2 a una potencia que va de 0 a 32.

C#
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)

Comentarios

En la tabla siguiente se indica el valor devuelto cuando se especifican varios valores o intervalos de valores para los x parámetros y y . Para obtener más información, vea Double.PositiveInfinity, Double.NegativeInfinity y Double.NaN.

x y Valor devuelto
Cualquier valor excepto NaN ±0 1
NaN ±0 1 (NaN en .NET Framework)*
NaN Cualquier valor excepto 0 NaN*
±0 < 0 y un entero impar NegativeInfinity o PositiveInfinity
±0 NegativeInfinity PositiveInfinity
±0 PositiveInfinity +0
±0 > 0 y un entero impar ±0
-1 NegativeInfinity o PositiveInfinity 1
+1 Cualquier valor excepto NaN 1
+1 NaN 1 (NaN en .NET Framework)*
Cualquier valor excepto 1 NaN NaN*
-1 < x < 1 PositiveInfinity +0
< -1 o > 1 PositiveInfinity PositiveInfinity
-1 < x < 1 NegativeInfinity PositiveInfinity
< -1 o > 1 NegativeInfinity +0
PositiveInfinity < 0 +0
PositiveInfinity > 0 PositiveInfinity
NegativeInfinity < 0 e entero finito e impar -0
NegativeInfinity > 0 e entero finito e impar NegativeInfinity
NegativeInfinity < 0 y finito y no un entero impar +0
NegativeInfinity > 0 y finito y no un entero impar PositiveInfinity
±0 < 0 y finito y no un entero impar PositiveInfinity
±0 > 0 y finito y no un entero impar +0
< 0, pero no NegativeInfinity Entero no entero finito NaN

* Estas filas no aparecen en el conjunto completo de reglas para pow según lo definido por el estándar IEEE para Floating-Point aritmética. Se incluyen aquí porque .NET deshabilita las excepciones de punto flotante IEEE 754 y, por tanto, no diferencia entre qNaN (NaN silencioso) y sNaN (naN de señalización). La especificación IEEE 754 permite esta deshabilitación de excepciones.

Este método llama al entorno de ejecución de C subyacente y el resultado exacto o el intervalo de entrada válido pueden diferir entre diferentes sistemas operativos o arquitecturas.

Se aplica a

Producto Versiones
.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, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 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.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Consulte también