Index: numbers.scm =================================================================== --- numbers.scm (revision 25798) +++ numbers.scm (working copy) @@ -1359,15 +1359,17 @@ (define exp %exp) (define (%log x) - (cond - ((%> x 0.0 'log) ; avoid calling inexact->exact on X here (to avoid overflow?) - (##core#inline_allocate ("C_a_i_log" 4) (%exact->inexact x))) - ((%= x 0.0) - (if (%exact? x) - (log0 'log x) - (##core#inline_allocate ("C_a_i_log" 4) (%exact->inexact x)))) - (else ; negative - (%+ (%log (%magnitude x)) (* (make-complex 0 1) (%angle x)))))) + (let ((type (%check-number x))) + (cond + ;; avoid calling inexact->exact on X here (to avoid overflow?) + ((or (eq? type COMP) (%< x 0.0 'log)) ; General case + (%+ (%log (%magnitude x)) (* (make-complex 0 1) (%angle x)))) + ((eq? x 0) ; Exact zero? That's undefined + (log0 'log x)) + ((eq? type NONE) + (bad-number 'exp x)) + (else ; Simple real number case + (##core#inline_allocate ("C_a_i_log" 4) (%exact->inexact x)))))) (define log %log) Index: tests/numbers-test.scm =================================================================== --- tests/numbers-test.scm (revision 25798) +++ tests/numbers-test.scm (working copy) @@ -418,6 +418,13 @@ (test "log of exp = 1" 1.0 (log (exp 1))) (test "log of -1" (string->number "0.0+3.141592653589793i") (log -1)) + (test "log with complex number" + (string->number "0.0+1.5707963267948966i") + (log (string->number "+i"))) + + (test "exp(log(x)) = x" + (string->number "2.0-3.0i") (exp (log (string->number "2.0-3.0i")))) + (letrec ((fac (lambda (n) (if (zero? n) 1