Skip to content
BASA DSA

Pow(x, n)

MediumMath & Geometry

Return x raised to integer power n. Negative powers mean reciprocals; exponent zero yields one.

Example 1

Input
x = 2
n = -3
Output
0.125

Explanation

2^-3 is the reciprocal of 222, or 1/8.

Example 2

Input
x = -2
n = 3
Output
-8

Explanation

An odd power preserves the negative sign, giving -8.

Example 3

Input
x = 3
n = 0
Output
1

Explanation

Any nonzero base to exponent zero equals one.

Example 4

Input
x = 1
n = -2147483648
Output
1

Explanation

Every integer power of one is one, including the minimum signed 32-bit exponent.

Constraints

  • -100 < x < 100
  • n is a signed 32-bit integer
  • x is nonzero when n <= 0
  • The result is finite and its absolute value <= 10000

Function contractmyPowArguments: json, json
Loading draft…
SolutionRuns on your device
Loading draft…