From 179e05df049f705f95eea224d1248ba5e979ce18 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Sat, 8 Mar 2014 13:32:08 -0800
Subject: [PATCH] Return the correct values for (log -0w0) and (log 0w0). 
 Previously we returned something like #c(-715 pi) and -715.

 * src/code/irrat-dd.lisp:
   * Handle -0w0 and 0w0 specially in dd-%log.

 * tests/trac.lisp:
   * Add a test for this in trac.lisp.
---
 src/code/irrat-dd.lisp | 9 ++++++++-
 tests/trac.lisp        | 5 ++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/code/irrat-dd.lisp b/src/code/irrat-dd.lisp
index 29627b551..438339fa8 100644
--- a/src/code/irrat-dd.lisp
+++ b/src/code/irrat-dd.lisp
@@ -368,10 +368,17 @@
 	     (optimize (speed 3) (space 0)
 		       (inhibit-warnings 3)))
     ;; Separate mantissa from exponent
-    (multiple-value-bind (x e)
+    (multiple-value-bind (x e sign)
 	(decode-float x)
       (declare (type double-double-float x)
 	       (type double-float-exponent e))
+      (when (zerop x)
+	;; Handle log(+/-0).  Return -inf or -inf + i*pi, but signal a
+	;; division by zero.
+	(return-from dd-%log
+	  (if (minusp sign)
+	      (complex (/ (- x)) dd-pi)
+	      (/ (- x)))))
       (let ((z 0w0)
 	    (y 0w0))
 	(declare (type double-double-float z y))
diff --git a/tests/trac.lisp b/tests/trac.lisp
index f8b425826..9a02189f9 100644
--- a/tests/trac.lisp
+++ b/tests/trac.lisp
@@ -342,7 +342,10 @@
      (ext:with-float-traps-masked (:divide-by-zero) (log -0d0)))
     (assert-equal
      (complex ext:single-float-negative-infinity (float pi 1f0))
-     (ext:with-float-traps-masked (:divide-by-zero) (log -0f0)))))
+     (ext:with-float-traps-masked (:divide-by-zero) (log -0f0)))
+    (assert-equal
+     (complex ext:double-double-float-negative-infinity kernel:dd-pi)
+     (ext:with-float-traps-masked (:divide-by-zero) (log -0w0)))))
 
 (define-test trac.93
   (:tag :trac)
-- 
GitLab