Close

Java - Math.log() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Method:

public static double log(double a)

Returns the natural logarithm (base e) of a double value.


Examples


package com.logicbig.example.math;

public class LogExample {

public static void main(String... args) {
findLog(9);
findLog(245.75);
findLog(1);
findLog(-18.31);
findLog(0);
findLog(Double.POSITIVE_INFINITY);
findLog(Double.NEGATIVE_INFINITY);
}

private static void findLog(double x) {
double result = Math.log(x);
System.out.printf("Math.log(%s) = %s%n", x, result);
}
}

Output

Math.log(9.0) = 2.1972245773362196
Math.log(245.75) = 5.504314759027276
Math.log(1.0) = 0.0
Math.log(-18.31) = NaN
Math.log(0.0) = -Infinity
Math.log(Infinity) = Infinity
Math.log(-Infinity) = NaN




See Also