Author: smokeink. Date 2018-03-01 09:00:36, views: 155, Raw

(defun log2 (x) "Use the fact that log2 x = n + log2 (x / 2^n) and choose n so that there are preserved as many significant digits as needed in x. In this case 100 digits, but it could be fewer according to the floating-point format used." (let ((n (- (integer-length x) 100))) (+ n (log (float (ash x (- n)) 1d0) 2))))