对数算法 [英] Logarithm Algorithm

查看:122
本文介绍了对数算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以任何精度评估任何底数的对数。是否有针对此的算法?我使用Java编程,所以我对Java代码很好。

I need to evaluate a logarithm of any base, it does not matter, to some precision. Is there an algorithm for this? I program in Java, so I'm fine with Java code.

如何快速找到二进制对数? (最多O(1))也许可以回答我的问题,但我不理解。可以弄清楚吗?

How to find a binary logarithm very fast? (O(1) at best) might be able to answer my question, but I don't understand it. Can it be clarified?

推荐答案

使用此身份:


log b (n)= log e (n)/ log e (b)

logb(n) = loge(n) / loge(b)

其中 log 可以是任何底数的对数函数, n 是数字, b 是基数。例如,在Java中,这将找到以2为底的对数256:

Where log can be a logarithm function in any base, n is the number and b is the base. For example, in Java this will find the base-2 logarithm of 256:

Math.log(256) / Math.log(2)
=> 8.0

Math.log() 使用基数 e 。还有 Math.log10() ,它使用基数 10

这篇关于对数算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆