Java Match pow method example shows how to find the exponential number using the pow method of the Java Math class.
How to find exponential value in Java using the pow method?
Use the pow
static method of the Java Math class to find an exponential number.
1 |
public static double pow(double x, double y) |
Where x is the base value and y is the exponent.
This method returns the value of the base raised to the power of the exponent.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
package com.javacodeexamples.mathexamples; public class FindExponentialExample { public static void main(String[] args){ double x1 = 2; double y1 = 4; System.out.println( Math.pow(x1, y1) ); double x2 = 2; double y2 = 0; System.out.println( Math.pow(x2, y2) ); double x3 = 0; double y3 = 2; System.out.println( Math.pow(x3, y3) ); double x4 = Double.NaN; double y4 = 2; System.out.println( Math.pow(x4, y4) ); double x5 = 2; double y5 = Double.NaN; System.out.println( Math.pow(x5, y5) ); double x6 = Double.NEGATIVE_INFINITY; double y6 = 2; System.out.println( Math.pow(x6, y6) ); double x7 = 2; double y7 = Double.NEGATIVE_INFINITY; System.out.println( Math.pow(x7, y7) ); double x8 = 0; double y8 = -1; System.out.println( Math.pow(x8, y8) ); } } |
Output
1 2 3 4 5 6 7 8 |
16.0 1.0 0.0 NaN NaN Infinity 0.0 Infinity |
Below given table shows some of the special case base and exponent values and their respective results.
Base | Exponent | Result |
Any | 0 or -0 | 1.0 |
Any | 1.0 | Same as base value |
Any | NaN | NaN |
NaN | Non Zero | NaN |
abs(base) > 1 | Double.POSITIVE_INFINITY | Double.POSITIVE_INFINITY |
abs(base) < 1 | Double.NEGATIVE_INFINITY | Double.POSITIVE_INFINITY |
abs(base) > 1 | Double.NEGATIVE_INFINITY | 0 |
abs(base) < 1 | Double.POSITIVE_INFINITY | 0 |
1 | Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY |
NaN |
0 | >0 | 0 |
Double.POSITIVE_INFINITY | < 0 | 0 |
0 | < 0 | Double.POSITIVE_INFINITY |
Double.POSITIVE_INFINITY | > 0 | Double.POSITIVE_INFINITY |
0 | > 0 and != finite odd integer | 0 |
Double.NEGATIVE_INFINITY | < 0 and != finite odd integer | 0 |
-0 | positive finite odd integer | -0 |
Double.NEGATIVE_INFINITY | negative finite odd integer | -0 |
-0 | < 0 and != finite odd integer | Double.POSITIVE_INFINITY |
Double.NEGATIVE_INFINITY | > 0 and != finite odd integer | Double.POSITIVE_INFINITY |
-0 | negative finite odd integer | Double.NEGATIVE_INFINITY |
Double.NEGATIVE_INFINITY | positive finite odd integer | Double.NEGATIVE_INFINITY |
This example is a part of the Java Math class tutorial with examples.
Please let me know your views in the comments section below.