Wednesday, June 10, 2026
HomeLanguagesJavaJava Math exp() method with Example

Java Math exp() method with Example

The java.lang.Math.exp() returns euler’s number e raised to the power of a double value.

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is positive zero.

Syntax :

public static double exp(double a)
Parameter : 
a : the exponent part which raises to e. 

Returns :
the value ea, where e is the base of the natural logarithms.

Example : To show working of java.lang.Math.exp() function




// Java program to demonstrate working
// of java.lang.Math.exp() method
import java.lang.Math;
  
class Gfg {
  
    // driver code
    public static void main(String args[])
    {
        double x = 3;
          
        // when both are not infinity
        double result = Math.exp(x);
        System.out.println(result);
  
        double positiveInfinity = 
               Double.POSITIVE_INFINITY;
        double negativeInfinity = 
               Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
  
        // when 1 is NAN
        result = Math.exp(nan);
        System.out.println(result);
  
        // when one argument is +INF
        result = Math.exp(positiveInfinity);
        System.out.println(result);
  
        result = Math.exp(negativeInfinity);
        System.out.println(result);
    }
}


Output:

20.085536923187668
NaN
Infinity
0.0
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS