如何在 Java 中使用 ln
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2568142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use ln in Java
提问by fang_dejavu
I'm trying to use this formula in JAVA :(-ln(1-L))/L
I'm not sure how to use ln in java.
我试图在 JAVA 中使用这个公式:(-
ln (1-L))/L我不知道如何在 Java 中使用 ln。
采纳答案by Bozho
Math.log(d)
returns the natural logarithm (base e) of a double value.
Math.log(d)
返回双精度值的自然对数(以 e 为底)。
So the java code will be,
所以java代码将是,
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
)
(但请注意,最好使用小写的变量名称 - 即l
而不是L
)
回答by Pops
I also had no idea, but since it's a common math function, I checked the Math classin the API.
我也不知道,但由于它是一个常见的数学函数,我检查了API 中的Math 类。
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.
编辑:抱歉链接断开,Markdown 现在已修复。我也在发布这个答案后立即意识到这听起来很尖刻,这不是我的本意;不过,重新措辞只会让它看起来尖刻和讽刺。我只是想说明这一点,API 对于可以合理预期会出现很多的方法确实很有用。