Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - log() method



The log() method returns the natural logarithm of the argument.

Syntax

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

Parameters

  • value − A primitive data type.

Return Value

This method returns the natural logarithm of the argument.

Example - Usage of log() 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("log(%.3f) is %.3f%n", x, Math.log(x));
   } 
}

Output

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

The value of e is 2.7183
log(11.635) is 2.454

Example - Usage of log() 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.log(d)); 
   } 
}

Output

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

2.4849066497880004

Example - Usage of log() 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.log(d)); 
   } 
}

Output

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

2.4951044867217584
groovy_numbers.htm
Advertisements