LogIn
I don't have account.

Math.exp() method in Java

DevSniper
199 Views

public static double exp(double x)  

In Programming, accurate handling of numerical data especially when dealing with floating-point numbers. Java offers a variety of methods in its standard library to manage numeric operations effectively. One such method is Java Math.exp. Java Math.exp() is a in-build static method that is present in Java.lang.Math class. Java Math.exp() is used to get the exponential value of a specified double argument, which is Euler's number raised to the power of the given argument.

  • If the parameter is positive or negative decimal value, this method will return Euler's number raised to the power of the given parameter.
  • Euler's number approximately equal to 2.718281828459045.
  • If the parameter is positive Infinity this method will return positive Infinity
  • If the parameter is negative Infinity this method will return Positive Zero.
  • If the parameter is NaN this method will return NaN.

Math.exp With Positive Number

public class Program 
{
    public static void main(String []args) 
    {
        System.out.println("Math.exp(10) =  "+ Math.exp(10));
        System.out.println("Math.exp(10L) =  "+ Math.exp(10L));
        System.out.println("Math.exp(10f) =  "+ Math.exp(10f));
        System.out.println("Math.exp(10.0) =  "+ Math.exp(10.0));
    }
}
Math.exp(10) =  22026.465794806718
Math.exp(10L) =  22026.465794806718
Math.exp(10f) =  22026.465794806718
Math.exp(10.0) =  22026.465794806718

Math.exp With Negative Number

public class Program 
{
    public static void main(String []args) 
    {
        System.out.println("Math.exp(-10) =  "+ Math.exp(-10));
        System.out.println("Math.exp(-10L) =  "+ Math.exp(-10L));
        System.out.println("Math.exp(-10f) =  "+ Math.exp(-10f));
        System.out.println("Math.exp(-10.0) =  "+ Math.exp(-10.0));
    }
}
Math.exp(-10) =  4.5399929762484854E-5
Math.exp(-10L) =  4.5399929762484854E-5
Math.exp(-10f) =  4.5399929762484854E-5
Math.exp(-10.0) =  4.5399929762484854E-5

Java Math.exp With Positive Infinity

Math.exp return Euler's number raised to the power of the given parameter. but If the parameter is positive Infinity this method will return positive Infinity.

public class Program
{
    public static void main(String []args)
    {
        System.out.println("Math.exp(10/0.0) =  "+ Math.exp(10/0.0) );
        System.out.println("Math.exp(10L/0.0) =  "+ Math.exp(10L/0.0) );
        System.out.println("Math.exp(10f/0.0) =  "+ Math.exp(10/0.0) );
        System.out.println("Math.exp(10.1/0.0) =  "+ Math.exp(10.1/0.0) );
        System.out.println("Math.exp(10f/0) =  "+ Math.exp(10f/0) );
        System.out.println("Math.exp(10f/-0) =  "+ Math.exp(10f/-0) );
        System.out.println("Math.exp(-10/-0f) =  "+ Math.exp(-10/-0f) );
        System.out.println("Math.exp(10.1/0) =  "+ Math.exp(10.1/0) );
        System.out.println("Math.exp(10.1/-0) =  "+ Math.exp(10.1/-0) );
        System.out.println("Math.exp(-10.1/-0.0) =  "+ Math.exp(-10/-0.0) );
    }
}
Math.exp(10/0.0) =  Infinity
Math.exp(10L/0.0) =  Infinity
Math.exp(10f/0.0) =  Infinity
Math.exp(10.1/0.0) =  Infinity
Math.exp(10f/0) =  Infinity
Math.exp(10f/-0) =  Infinity
Math.exp(-10/-0f) =  Infinity
Math.exp(10.1/0) =  Infinity
Math.exp(10.1/-0) =  Infinity
Math.exp(-10.1/-0.0) =  Infinity

Java Math.exp With Negative Infinity

Java Math.exp method return Euler's number raised to the power of the given parameter. but If the parameter is negative Infinity this method will return positive zero.

public class Program 
{
    public static void main(String []args)
    {
        System.out.println("Math.exp(10/-0.0) =  "+ Math.exp(10/-0.0) );
        System.out.println("Math.exp(10L/-0.0) =  "+ Math.exp(10L/-0.0) );
        System.out.println("Math.exp(10f/-0.0) =  "+ Math.exp(10f/-0.0) );
        System.out.println("Math.exp(-10f/0.0) =  "+ Math.exp(-10f/0.0) );
        System.out.println("Math.exp(-10f/0) =  "+ Math.exp(-10f/0) );
        System.out.println("Math.exp(10.1/-0.0) =  "+ Math.exp(10.1/-0.0) );
        System.out.println("Math.exp(-10.1/0.0) =  "+ Math.exp(-10.1/0.0) );
        System.out.println("Math.exp(-10.1/0) =  "+ Math.exp(-10.1/0) );
    }
}
Math.exp(10/-0.0) =  0.0
Math.exp(10L/-0.0) =  0.0
Math.exp(10f/-0.0) =  0.0
Math.exp(-10f/0.0) =  0.0
Math.exp(-10f/0) =  0.0
Math.exp(10.1/-0.0) =  0.0
Math.exp(-10.1/0.0) =  0.0
Math.exp(-10.1/0) =  0.0

Java Math.exp With NaN

Math.exp() used to get Euler's number (e) raised to the power of the given parameter. but If the parameter is NaN ( Not a Number) this method will return NaN.

public class Program 
{
    public static void main(String []args) 
    {
        System.out.println("Math.exp(0/0.0) =  "+ Math.exp(0/0.0) );
        System.out.println("Math.exp(0/-0.0) =  "+ Math.exp(0/-0.0) );
        System.out.println("Math.exp(-0/0.0) =  "+ Math.exp(-0/0.0) );
        System.out.println("Math.exp(-0/-0.0) =  "+ Math.exp(-0/-0.0) );
        System.out.println("Math.exp(0/0f) =  "+ Math.exp(0/0f) );
        System.out.println("Math.exp(0/-0f) =  "+ Math.exp(0/-0f) );
        System.out.println("Math.exp(-0/0f) =  "+ Math.exp(-0/0f) );
        System.out.println("Math.exp(-0/-0f) =  "+ Math.exp(-0/-0f) );
    }
}
Math.exp(0/0.0) =  NaN
Math.exp(0/-0.0) =  NaN
Math.exp(-0/0.0) =  NaN
Math.exp(-0/-0.0) =  NaN
Math.exp(0/0f) =  NaN
Math.exp(0/-0f) =  NaN
Math.exp(-0/0f) =  NaN
Math.exp(-0/-0f) =  NaN