In this Java code example common exponential and logarithmic math functions are applied to the datatype double.
public class ExpLogFunctions {
public static void main(String[] args) {
double exp, exp1, log, log10, log1p;
// Returns Euler's number e raised to the power of a double value
exp = Math.exp(1);
// Returns ex -1.
// Note that for values of x near 0, the exact sum of expm1(x) + 1
// is much closer to the true result of ex than exp(x)
exp1 = Math.expm1(1);
// Returns the natural logarithm (base e) of a double value
log = Math.log(10);
// Returns the base 10 logarithm of a double value
log10 = Math.log10(100);
// Returns the natural logarithm of the sum of the argument and 1.
// Note that for small values x, the result of log1p(x) is much closer to
// the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x)
log1p = Math.log1p(10);
System.out.println("Exp: " + exp);
System.out.println("Exp1: " + exp1);
System.out.println("Log: " + log);
System.out.println("Log10: " + log10);
System.out.println("Log1p: " + log1p);
}
}
Exp: 2.718281828459045
Exp1: 1.718281828459045
Log: 2.302585092994046
Log10: 2.0
Log1p: 2.3978952727983707