This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMU Common Lisp".
The branch, master has been updated via 2e182540e895f16b26224ba11b2f38de93ab2672 (commit) from d03e178481b3be542e4a2519890ed2772d081fb6 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 2e182540e895f16b26224ba11b2f38de93ab2672 Author: Raymond Toy toy.raymond@gmail.com Date: Sat Sep 20 11:55:27 2014 -0700
Make (log (scale-float 1d0 k) 2) = k
* src/code/irrat.lisp * Improve accuracy of log2 for the case when x=2^k. There might be some loss in accuracy for other values of x, however. * tests/float.lisp * Add test for log2(2^k) = k.
diff --git a/src/code/irrat.lisp b/src/code/irrat.lisp index 5f24bf9..2591907 100644 --- a/src/code/irrat.lisp +++ b/src/code/irrat.lisp @@ -598,7 +598,17 @@ (float 2 float-type))))))))) (etypecase x (float - (/ (log (float x float-type)) (log-of-2 float-type))) + (multiple-value-bind (f e s) + (decode-float x) + ;; If x = 2^e*f then log2(x) = e + log2(f) = e + + ;; log(f)/log(2). Accuracy could be improved some since this + ;; has 2 rounding operations instead of just 1 for + ;; log(x)/log(2). + (let ((log2 (+ e (/ (log (float f float-type)) + (log-of-2 float-type))))) + (if (minusp s) + (complex log2 (log-2-pi float-type)) + log2)))) (ratio (let ((top (numerator x)) (bot (denominator x))) diff --git a/tests/float.lisp b/tests/float.lisp index 6fe1f50..ff07270 100644 --- a/tests/float.lisp +++ b/tests/float.lisp @@ -10,3 +10,8 @@ (declare (type (double-float (0d0)) x)) (decode-float x))) 1d0))) + +(define-test log2 + (loop for k from -1074 to 1023 do + (let ((x (scale-float 1d0 k))) + (assert-equal k (log x 2)))))
-----------------------------------------------------------------------
Summary of changes: src/code/irrat.lisp | 12 +++++++++++- tests/float.lisp | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-)
hooks/post-receive