Handling zeros and infinities in 2-arg atan.

This commit is contained in:
Alex Shinn 2012-12-27 00:17:17 +09:00
parent e701c63762
commit cdc9465b1b

View file

@ -1114,14 +1114,20 @@
(if (pair? o) (/ (ln x) (ln (car o))) (ln x)))
(define (atan y . o)
(define (inf? z) (if (= +inf.0 z) #t (= -inf.0 z)))
(if (null? o)
(atan1 y)
(let ((x (exact->inexact (car o))))
(if (and (inf? x) (inf? y))
(* (if (< y 0) -1 1) (if (= x -inf.0) 3 1) 0.7853981633974483)
(if (negative? x)
(if (negative? y)
(- (atan1 (/ y x)) 3.141592653589793)
(- 3.141592653589793 (atan1 (/ y (- x)))))
(atan1 (/ y x))))))
(if (and (zero? x) (zero? y))
(* (if (eqv? y -0.0) -1 1)
(if (eqv? x -0.0) 3.141592653589793 x))
(atan1 (/ y x))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; string cursors