Logarithm function of an arbitrary integer base in C

早过忘川 提交于 2019-11-30 08:40:16

C doesn't provide functions to compute logarithms of any bases other than e or 10.

So just use math:

logarithm of x base b = log(x)/log(b)

If you'll be doing the logarithms over the same base repeatedly, you can precompute 1/log(b).
I wouldn't rely on the compiler being able to do this optimization for you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!