dsedug8644 2014-06-16 02:06
浏览 57
已采纳

如何获得一个非常大的数字(PHP)的log()?

I've looked at php-big numbers, BC Math, and GMP for dealing with very big numbers in php. But none seem to have a function equivilent to php's log(). For example I want to do this:

$result = log($bigNumber, 2);

Would anyone know of an alternate way to get the log base 2 of a arbitray precision point number in php? Maybe Ive missed a function, or library, or formula.

edit: php-bignumbers seems to have a log base 10 function only log10()

  • 写回答

4条回答 默认 最新

  • douluo1330 2014-06-16 16:05
    关注

    One solution combining the suggestions so far would be to use this formula:

    log2($num) = log10($num) / log10(2)
    

    in conjunction with php-big numbers since it has a pre-made log10 function.

    eg, after installing the php-big numbers library, use:

    $log2 = log10($bigNum) / log10(2);
    

    Personally I've decided to use different math/logic so as to not need the log function, and just using bcmath for the big numbers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能