- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Math exp() Method
Description
The Java Math exp(double a) returns Euler's number e raised to the power of a double value. Special cases:
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.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
Syntax
public static double exp(double d)
Parameters
Here is the detail of parameters −
d − Any primitive data type.
Return Value
This method returns the base of the natural logarithms, e, to the power of the argument.
Example 1
In this example, we're showing the usage of Math.exp() method to get the exponent of a double number. We've created two double variables x, y and initialized them with different values. Then using Math.exp() method we're printing the exponent of a double value.
public class Test { public static void main(String args[]) { double x = 11.635; double y = 2.76; System.out.printf("The value of e is %.4f%n", Math.E); System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x)); } }
This will produce the following result −
Output
The value of e is 2.7183 exp(11.635) is 112983.831
Example 2
In this example, we're showing the usage of Math.exp() method to get the exponent of a float number. We've created two float variables x, y and initialized them with different values. Then using Math.exp() method we're printing the exponent of a float value.
public class Test { public static void main(String args[]) { float x = (float)11.635; float y = (float)2.76; System.out.printf("The value of e is %.4f%n", Math.E); System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x)); } }
This will produce the following result −
Output
The value of e is 2.7183 exp(11.635) is 112983.831
Example 3
In this example, we're showing the usage of Math.exp() method to get the exponent of zero. We've created a double variable and initialized it with 0.0. Then using Math.exp() method we're printing the exponent of a zero value.
public class Test { public static void main(String args[]) { double x = 0.0; System.out.printf("The value of e is %.4f%n", Math.E); System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x)); } }
This will produce the following result −
Output
The value of e is 2.7183 exp(0.000) is 1.000
To Continue Learning Please Login
Login with Google