2011-03-15 22 views
1

可能重複的對數:
How to find a binary logarithm very fast? (O(1) at best)算法找到一些

如何做日誌功能的工作。 如何計算基數爲b的日誌。

+0

http://en.wikipedia.org/wiki/Logarithm#Calculation – Tim 2011-03-15 06:00:21

+2

可能的[重複1](http://stackoverflow.com/questions/2169641/where-to-find-algorithms-for-standard-math - 功能)和[重複2](http://stackoverflow.com/questions/2668248/how-to-find-a-binary-logarithm-very-fast-o1-at-best) – 2011-03-15 06:01:58

+0

讓你的手髒:http ://repo.or.cz/w/glibc.git/blob/HEAD:/sysdeps/ieee754/dbl-64/e_log.c – 2011-03-15 06:03:04

回答

0

有很多這樣做的算法。我的最愛之一(警告:無恥的插件)是this one based on the Fibonacci numbers.該代碼包含一個非常詳細的評論,進入數學如何工作。給定a和b,它在時間O(lg b)和O(1)空間中運行。

希望這會有所幫助!