Changeset 15407


Ignore:
Timestamp:
Jun 5, 2012, 10:37:59 PM (7 years ago)
Author:
gb
Message:

SQRT: handle COMPLEX arguments whose imaginary part is zero.

Fixes ticket:981 in the trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-0/l0-float.lisp

    r14670 r15407  
    849849
    850850
    851 
     851       
    852852(defun sqrt (x &aux a b)
    853853  "Return the square root of NUMBER."
    854854  (cond ((zerop x) x)
    855         ((complexp x) (* (sqrt (abs x)) (cis (/ (phase x) 2))))         
     855        ((complexp x)
     856         (let* ((i (imagpart x)))
     857           (if (zerop i)                ; has to be a float
     858             (let* ((zero (if (typep i 'double-float) 0.0d0 0.0f0))
     859                    (r (realpart x)))
     860               (if (< r zero)
     861                 (%make-complex zero (float-sign i (sqrt (- r))))
     862                 (%make-complex (abs (sqrt r)) (float-sign i zero))))
     863             (* (sqrt (abs x)) (cis (/ (phase x) 2))))))
    856864        ((minusp x) (complex 0 (sqrt (- x))))
    857865        ((floatp x)
Note: See TracChangeset for help on using the changeset viewer.