From 508b6594cf003d6a9d400d59d4ec32255728d0e9 Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Sat, 8 Mar 2014 11:27:06 -0800 Subject: [PATCH] Revert change for ticket 92. It's incorrect. We really want log(-0) to be -inf + i*pi. It's needed to get the correct values on the branch cuts of the special functions from the definitions. Update trac test to test for this. --- src/compiler/float-tran.lisp | 12 ++++-------- tests/trac.lisp | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/compiler/float-tran.lisp b/src/compiler/float-tran.lisp index b856a6c32..08ce90bdf 100644 --- a/src/compiler/float-tran.lisp +++ b/src/compiler/float-tran.lisp @@ -1494,15 +1494,11 @@ (two-arg-derive-type x y #'expt-derive-type-aux #'expt)) +;;; Note must assume that a type including 0.0 may also include -0.0 +;;; and thus the result may be complex -infinity + i*pi. +;;; (defun log-derive-type-aux-1 (x) - (elfun-derive-type-simple x - #'(lambda (z) - ;; log(0) and log(-0) is -infinity. - ;; Return NIL to indicate that. - (if (zerop z) - nil - (log z))) - -0d0 nil nil nil)) + (elfun-derive-type-simple x #'log 0d0 nil nil nil)) (defun log-derive-type-aux-2 (x y same-arg) (let ((log-x (log-derive-type-aux-1 x)) diff --git a/tests/trac.lisp b/tests/trac.lisp index 7fd940821..f8b425826 100644 --- a/tests/trac.lisp +++ b/tests/trac.lisp @@ -329,8 +329,20 @@ (declare (type (double-float 0d0) x)) (log x))))) (assert-equal - 'double-float - (third (kernel:%function-type f))))) + '(or double-float (complex double-float)) + (third (kernel:%function-type f))) + ;; It is important that log(-0) = -inf + i*pi. This is needed to + ;; ensure that all of the special functions have the right values + ;; on the branch cuts. (Although the implementation of the special + ;; function may not use log internally, the definition might and + ;; this property is needed to derive the correct value from the + ;; definition.) + (assert-equal + (complex ext:double-float-negative-infinity pi) + (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))))) (define-test trac.93 (:tag :trac) -- GitLab