Comment 0 for bug 888410

Revision history for this message
Robert Smith (quadricode) wrote :

1. Lines 128-134 of `src/code/irrat.lisp` read
#!+win32
    (progn
      ;; FIXME: libc hypot "computes the sqrt(x*x+y*y) without undue overflow or underflow"
      ;; ...we just do the stupid simple thing.
      (declaim (inline %hypot))
      (defun %hypot (x y)
        (sqrt (+ (* x x) (* y y)))))

For more accuracy, this can be replaced with

    #!+win32
    (progn
      ;; This is written in a peculiar way to avoid overflow. Note that in
      ;; sqrt(x^2 + y^2), either square or the sum can overflow.
      ;;
      ;; Without loss of generality, assume |x| >= |y|. Then (y/x)^2 lays
      ;; in the unit interval [0,1], so 1 + (y/x)^2 lays in [1,2]. The
      ;; square root of that lays in [1,1.414] approximately.
      ;;
      ;; Factoring x^2 out of sqrt(x^2 + y^2) gives us the expression
      ;; |x|sqrt(1 + (y/x)^2), which can only overflow if |x| is
      ;; sufficiently large.
      (declaim (inline %hypot))
      (defun %hypot (x y)
        (when (<= (abs x) (abs y))
          (rotatef x y))
        (let ((y/x (/ y x)))
          (* (abs x)
             (sqrt (1+ (* y/x y/x)))))))

2. No real test cases.

3. SBCL 1.0.52

4. Darwin DiapentePomum.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh

5. (:SWANK :QUICKLISP :SB-BSD-SOCKETS-ADDRINFO :ASDF2 :ASDF :ASDF-UNIX :ANSI-CL
 :COMMON-LISP :SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE
 :SB-EVAL :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :PPC :UNIX :MACH-O :BSD
 :DARWIN :GENCGC :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-LISTS
 :LINKAGE-TABLE :RAW-INSTANCE-INIT-VOPS :MEMORY-BARRIER-VOPS
 :COMPARE-AND-SWAP-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-DLOPEN
 :ALIEN-CALLBACKS :OS-PROVIDES-DLOPEN :OS-PROVIDES-DLADDR :OS-PROVIDES-PUTWC
 :OS-PROVIDES-BLKSIZE-T :OS-PROVIDES-SUSECONDS-T)