Learn and Learn

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

Java – Find e Raise to Power x – 1 – expm1() Method with Examples

java.lang.Math.expm1() method is used to find the e^x -1 of a double value in Java for the given input (x – parameter).
Note that for values of x near 0, the exact sum of expm1(x) + 1 is much closer to the true result of ex than exp(x).
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic. The result of expm1 for any finite input must be greater than or equal to -1.0. Note that once the exact result of ex – 1 is within 1/2 ulp of the limit value -1, -1.0 should be returned.
Search on Google about function notaion

expm1() method exists in Math class of java.lang package.
Since: JDK1.5

 

Declaration of expm1() Method

The declaration of expm1() method is:

 

Syntax of expm1() Method

The syntax of expm1() method in Java is:

Example

Output:

8102.083927575384

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

Output:

7.200489933638588E10

 

Parameters of expm1() 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 expm1() 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 expm1() Method in Java

expm1() method returns the computed value of e^x -1 of a double value for the given input (x – parameter).the value ex – 1.

 

Java expm1() Method Example 1


Output:

ex -1 of a Negative Value: -0.9999999936129925
ex -1 of a Positive Value: 1.1680887709814473E12
ex -1 of Zero: 0.0

 

Java expm1() Method Example 2


Output:

Infinity
4.9E-324
NaN
-1.0
4.2867000000918794E-11
2.083198183463838E7
0.0
-0.9242259959771545
-1.0

 

Special Cases of expm1() 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 -1.0.
If the argument is zero, then the result is a zero with the same sign as the argument.
Example

Output:

0.0
0.0
Infinity
-1.0
NaN

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved