Java Math expm1() method with Example
The java.lang.Math.expm1() returns ex -1. 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).
- 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.
Syntax:
public static double expm1(double x) Parameter: x-the exponent part which raises to e.
Returns:
The method returns the value ex-1, where e is the base of the natural logarithms.
Example : To show working of java.lang.Math.expm1() function
// Java program to demonstrate working // of java.lang.Math.expm1() 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.expm1(x); System.out.println(result); double positiveInfinity = Double.POSITIVE_INFINITY; double negativeInfinity = Double.NEGATIVE_INFINITY; double nan = Double.NaN; // when x is NAN result = Math.expm1(nan); System.out.println(result); // when argument is +INF result = Math.expm1(positiveInfinity); System.out.println(result); // when argument is -INF result = Math.expm1(negativeInfinity); System.out.println(result); x = -0; result = Math.expm1(x); // same sign as 0 System.out.println(result); } } |
chevron_right
filter_none
Output:
19.085536923187668 NaN Infinity -1.0 0.0
Recommended Posts:
- StrictMath expm1() Method in Java With Examples
- Java.math.BigInteger.modInverse() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java Math exp() method with Example
- Java Math log() method with example
- Java Math decrementExact() method
- Java Math round() method with Example
- Math floorMod() Method in Java
- Java Math getExponent() method with Example
- Math floorDiv() method in Java
- Math fma() method in Java with Examples
- Java Math min() method with Examples
- Java Math abs() method with Examples
- Java Math getExponent() method with Example
- Java Math incrementExact(int x) method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



