What is Math.Pow() in C#?
C# has a built-in Math class that provides useful mathematical functions and operations. The Math class has the Pow() function, which is used to compute the power of a specified number.
Syntax
public static double Pow (double value, double power);
Parameters
value:valueis a double-precision floating-point number of typeDoubleand represents the number to be raised with power. Its range is all double numbers.power:poweris a double-precision floating-point number of typeDoubleand represents the power value. Its range is all double numbers.
Return value
-
Double:Pow()returns a number,value, raised to the power,power, and its type isDouble. -
NaN:Pow()returnsNaNif:valueorpowerisNaN.value= -1;power=NegativeInfinityorPositiveInfinity.value< 0 but notNegativeInfinity;poweris not an integer,NegativeInfinity, orPositiveInfinity.
-
PositiveInfinity:Pow()returnsPositiveInfinityif:value=NegativeInfinity;poweris positive but not an odd integer.- -1 <
value< 1;power=NegativeInfinity. value< -1 orvalue> 1;power=PositiveInfinityvalue= 0;power< 0.value=PositiveInfinity;power> 0
-
NegativeInfinity:Pow()returnsNegativeInfinityif:value=NegativeInfinity;poweris a positive odd integer.
Example
using System;class Educative{static void Main(){Double result = Math.Pow(-0.16, 2);System.Console.WriteLine("Pow(-0.16,2) = "+ result);Double result1 = Math.Pow(0, 0);System.Console.WriteLine("Pow(0,0) = "+ result1);Double result2 = Math.Pow(2,4);System.Console.WriteLine("Pow(2,4) = "+ result2);Double result3 = Math.Pow(-2,-4);System.Console.WriteLine("Pow(-2,-4) = "+ result3);}}