x的对数底数n [英] Log base n of x

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

问题描述

我有一个小问题. 谁知道我们如何计算日志 以Shift_L或Shift_R为底数n?

I have a little problem. Who knows how we can calculate the log base n with Shift_L or Shift_R?

例如:对于n = 2,我们有以下解决方案:

for example: for n=2 we had this solution:

int log(int n){
int res = 0;
while((n>>=1))
    res++;
return res;
}

推荐答案

您似乎不希望基数b的对数,但想要最大的整数n以便使n <= log_b(x).在这种情况下,以下功能应该可以满足您的需求:

You don't seem to want the logarithm for a base b, but the largest integer n so that n <= log_b(x). If that's the case, the following function should serve your needs:

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}

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

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