Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use ln in Java

I'm trying to use this formula in JAVA : (-ln(1-L))/L
I'm not sure how to use ln in java.

like image 545
fang_dejavu Avatar asked Apr 02 '10 17:04

fang_dejavu


People also ask

What is the use of Ln in Java?

Ln stands for "new line" essentially. The difference between System. out. print() and System.

How do you do natural log in Java?

log() method returns the natural logarithm (base e) of a double value as a parameter. There are various cases : If the argument is NaN or less than zero, then the result is NaN. If the argument is positive infinity, then the result is positive infinity.

How do you use log in Java?

You can use Math. log(value) to get log of specific value where value is considered to be in double . You can also use Math. log10(value) to get base 10 log.


2 Answers

Math.log(d) returns the natural logarithm (base e) of a double value.

So the java code will be,

double result = (-Math.log(1-L))/L;

(but note that it's better to have variable names in lower-case - i.e. l instead of L)

like image 146
Bozho Avatar answered Sep 29 '22 05:09

Bozho


I also had no idea, but since it's a common math function, I checked the Math class in the API.

Here you go: the log method

EDIT: Sorry for broken link, Markdown is fixed now. Also I realized right after I posted this answer that it sounds snarky, which was not my intent; re-wordings just make it seems snarky AND sarcastic, though. I just wanted to make the point that the API really is useful for methods that could be reasonably expected to come up a lot.

like image 37
Pops Avatar answered Sep 29 '22 05:09

Pops