Си шарп возведение степень

C# Math.Pow() – Syntax & Examples

In this tutorial, we will learn about the C# Math.Pow() method, and learn how to use this method to find the result of a number raised to a specified power, with the help of examples.

Pow(Double, Double)

Math.Pow(x, y) returns the value of specified number x raised to the specified power y .

Syntax

The syntax of Pow() method is

Parameter Description
x A double-precision floating-point number to be raised to a power.
y A double-precision floating-point number that specifies a power.

Return Value

The method returns Double value.

Example 1 – Pow(x, y)

In this example, we will take different values for x and y, and compute the value of x raised to the power y using Math.Pow() method.

using System; class Example < static void Main(string[] args) < Double x, y, result; x = 2; y = 3; result = Math.Pow(x, y); Console.WriteLine($"Pow(,) = "); x = -1; y = 3; result = Math.Pow(x, y); Console.WriteLine($"Pow(,) = "); x = 4; y = 2; result = Math.Pow(x, y); Console.WriteLine($"Pow(,) = "); x = 9; y = 0.5; result = Math.Pow(x, y); Console.WriteLine($"Pow(,) = "); x = 1; y = 0; result = Math.Pow(x, y); Console.WriteLine($"Pow(,) = "); > >
Pow(2,3) = 8 Pow(-1,3) = -1 Pow(4,2) = 16 Pow(9,0.5) = 3 Pow(1,0) = 1

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Pow() method, and also learnt how to use this method with the help of C# example programs.

Источник

Math. Pow(Double, Double) Метод

Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.

Возвращает указанное число, возведенное в указанную степень.

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 , возведенное в степень y .

Примеры

В следующем примере метод используется Pow для вычисления значения, которое возникает при повышении значения 2 в степень в диапазоне от 0 до 32.

int value = 2; for (int power = 0; 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 $"^ = int64:N0> (0x 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("^ = (0x)", _ 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) 

Комментарии

В следующей таблице указано возвращаемое значение, если для параметров и y заданы различные значения или диапазоны значений x . Дополнительные сведения см. в разделах Double.PositiveInfinity, Double.NegativeInfinity и Double.NaN.

Параметры Возвращаемое значение
x или y = NaN . NaN
x = Любое значение, кроме NaN ; y = 0. 1
x = NegativeInfinity ; y < 0. 0
x = NegativeInfinity ; y — положительное нечетное целое число. NegativeInfinity
x = NegativeInfinity ; y является положительным, но не является нечетным целым числом. PositiveInfinity
x < 0, но не NegativeInfinity ; y не является целым числом, NegativeInfinity или PositiveInfinity . NaN
x = -1; y = NegativeInfinity или PositiveInfinity . NaN
-1 < x < 1; . y = NegativeInfinity PositiveInfinity
-1 < x < 1; . y = PositiveInfinity 0
x 0
x PositiveInfinity
x = 0; y < 0. PositiveInfinity
x = 0; y > 0. 0
x = 1; y — это любое значение, кроме NaN . 1
x = PositiveInfinity ; y < 0. 0
x = PositiveInfinity ; y > 0. PositiveInfinity

Этот метод вызывает базовую среду выполнения C, и точный результат или допустимый диапазон входных данных могут отличаться в разных операционных системах или архитектурах.

Источник

Math. Pow(Double, Double) Method

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Returns a specified number raised to the specified power.

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

Parameters

A double-precision floating-point number to be raised to a power.

A double-precision floating-point number that specifies a power.

Returns

The number x raised to the power y .

Examples

The following example uses the Pow method to calculate the value that results from raising 2 to a power ranging from 0 to 32.

int value = 2; for (int power = 0; 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 $"^ = int64:N0> (0x 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("^ = (0x)", _ 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) 

Remarks

The following table indicates the return value when various values or ranges of values are specified for the x and y parameters. For more information, see Double.PositiveInfinity, Double.NegativeInfinity, and Double.NaN.

Parameters Return value
x or y = NaN . NaN
x = Any value except NaN ; y = 0. 1
x = NegativeInfinity ; y < 0. 0
x = NegativeInfinity ; y is a positive odd integer. NegativeInfinity
x = NegativeInfinity ; y is positive but not an odd integer. PositiveInfinity
x < 0 but not NegativeInfinity ; y is not an integer, NegativeInfinity , or PositiveInfinity . NaN
x = -1; y = NegativeInfinity or PositiveInfinity . NaN
-1 < x < 1; y = NegativeInfinity . PositiveInfinity
-1 < x < 1; y = PositiveInfinity . 0
x < -1 or x >1; y = NegativeInfinity . 0
x < -1 or x >1; y = PositiveInfinity . PositiveInfinity
x = 0; y < 0. PositiveInfinity
x = 0; y > 0. 0
x = 1; y is any value except NaN . 1
x = PositiveInfinity ; y < 0. 0
x = PositiveInfinity ; y > 0. PositiveInfinity

This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures.

Источник

MathF. Pow(Single, Single) Метод

Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.

Возвращает указанное число, возведенное в указанную степень.

public: static float Pow(float x, float y);
public static float Pow (float x, float y);
static member Pow : single * single -> single
Public Shared Function Pow (x As Single, y As Single) As Single

Параметры

Число одиночной точности с плавающей запятой, возводимое в степень.

Число одиночной точности с плавающей запятой, задающее степень.

Возвращаемое значение

Число x , возведенное в степень y .

Комментарии

В следующей таблице указано возвращаемое значение, если для параметров и y заданы различные значения или диапазоны значений x . Дополнительные сведения см. в разделах Single.PositiveInfinity, Single.NegativeInfinity и Single.NaN.

Параметры Возвращаемое значение
x или y = NaN . NaN
x = Любое значение, кроме NaN ; y = 0. 1
x = NegativeInfinity ; y < 0. 0
x = NegativeInfinity ; y — положительное нечетное целое число. NegativeInfinity
x = NegativeInfinity ; y является положительным, но не нечетным целым числом. PositiveInfinity
x < 0, но не NegativeInfinity ; y не является целым числом, NegativeInfinity или PositiveInfinity . NaN
x = -1; y = NegativeInfinity или PositiveInfinity . NaN
-1 < x < 1; . y = NegativeInfinity PositiveInfinity
-1 < x < 1; . y = PositiveInfinity 0
x 0
x PositiveInfinity
x = 0; y < 0. PositiveInfinity
x = 0; y > 0. 0
x = 1; y — это любое значение, кроме NaN . 1
x = PositiveInfinity ; y < 0. 0
x = PositiveInfinity ; y > 0. PositiveInfinity

Этот метод вызывает базовую среду выполнения C, и точный результат или допустимый диапазон входных данных может отличаться в разных операционных системах или архитектурах.

Источник

Читайте также:  Native javascript or jquery
Оцените статью