Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - exp() method



The exp() method returns the base of the natural logarithms, e, to the power of the argument.

Syntax

double exp(double value)
double exp(float value) 
double exp(int value) 
double max(long value)

Parameters

  • value − A primitive data type.

Return Value

This method returns the base of the natural logarithms, e, to the power of the argument.

Example - Usage of exp() method for double value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      double x = 11.635; 
	  
      printf("The value of e is %.4f%n", Math.E); 
      printf("exp(%.3f) is %.3f%n", x, Math.exp(x));
   } 
}

Output

When we run the above program, we will get the following result −

The value of e is 2.7183
exp(11.635) is 112983.831

Example - Usage of exp() method for int value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      int d = 12; 
		
      println(Math.exp(d)); 
   } 
}

Output

When we run the above program, we will get the following result −

162754.79141900392

Example - Usage of exp() method for float value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      float d = 12.123f;
		
      println(Math.exp(d)); 
   } 
}

Output

When we run the above program, we will get the following result −

184056.88473091694
groovy_numbers.htm
Advertisements