Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Java – Find Euler’s Number e – exp() Method – Examples & Explanation

java.lang.Math.exp() method is used to find the Euler’s number e raised to the power of a double value in Java for the given input (x – parameter).
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
The value of constant e = 2.71828 approximately.

exp() method exists in Math class of java.lang package.
Since: JDK1.0

 

Declaration of exp() Method

The declaration of exp() method is:

 

Syntax of exp() Method

The syntax of exp() method in Java is:

Example

Output:

3.317400098335743E39

Example
By importing java.lang package the syntax of exp() method can be used as:

Output:

Infinity

 

Parameters of exp() Method in Java

x – Where x is any valid double input value. This parameter is required.

 

Error Handling

If the x parameter is not a number exp() method returns an error.
If there is no argument (x – input value) passes to the method, the compiler will produce an error.Example

Output:
Error

 

Return Value of exp() Method in Java

exp() method returns the Euler’s number e raised to the power of a double value for the given input (x – parameter).The value e, where e is the base of the natural logarithms.

 

Java exp() Method Example 1


Output:

Euler's number e raised to the power of a double value of a Negative Value: 6.387007424042083E-9
Euler's number e raised to the power of a double value of a Positive Value: 1.1680887709824473E12
Euler's number e raised to the power of a double value of Zero: 1.0

 

Java exp() Method Example 2


Output:

Infinity
1.0
NaN
0.0
1.000000000042867
2.0831982834638383E7
1.0
0.07577400402284548
0.0

 

Special Cases of exp() Method in Java

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.
Example

Output:

Infinity
0.0
NaN

 

LearnAndLearn.com © 2018 - All rights reserved