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: value is a double-precision floating-point number of type Double and represents the number to be raised with power. Its range is all double numbers.
  • power: power is a double-precision floating-point number of type Double and 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 is Double.

  • NaN: Pow() returns NaN if:

    • value or power is NaN.
    • value = -1; power = NegativeInfinity or PositiveInfinity.
    • value < 0 but not NegativeInfinity; power is not an integer, NegativeInfinity, or PositiveInfinity.
  • PositiveInfinity: Pow() returns PositiveInfinity if:

    • value = NegativeInfinity; power is positive but not an odd integer.
    • -1 < value < 1; power = NegativeInfinity.
    • value < -1 or value > 1; power = PositiveInfinity
    • value = 0; power < 0.
    • value = PositiveInfinity; power > 0
  • NegativeInfinity: Pow() returns NegativeInfinity if:

    • value = NegativeInfinity; power is 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);
}
}

Free Resources