.pow()
Published Sep 6, 2022
Contribute to Docs
The Math.pow()
method returns a double value of the first argument raised to the power of the second argument.
Syntax
Math.pow(base, exponent)
The base
and exponent
arguments are both double
values.
It’s important to note that edge cases with special arguments such as 0.0
, infinity
, or NaN
will produce special results as shown in the example below.
Example
The following example uses Math.pow()
to return 3.0
raised to the power of 2.0
:
public class Main {public static void main(String[] args) {double base = 3.0;double exponent = 2.0;System.out.println(Math.pow(base, exponent));System.out.println(Math.pow(base, 0.0));System.out.println(Math.pow(0.0, exponent));double notANumber = Double.NaN;double negInfinity = Double.NEGATIVE_INFINITY;System.out.println(Math.pow(notANumber, exponent));System.out.println(Math.pow(0.0, negInfinity));}}
This will produce the following output:
9.01.00.0NaNInfinity
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.