Issue #376 - Support for two-argument atan

This commit is contained in:
Justin Ethier 2020-05-20 22:26:07 -04:00
parent c760283bff
commit 8effbb64cd

View file

@ -75,5 +75,22 @@
(define-inexact-op tan "tan" "ctan")
(define-inexact-op asin "asin" "casin")
(define-inexact-op acos "acos" "cacos")
(define-inexact-op atan "atan" "catan")
(define-inexact-op atan1 "atan" "catan")
;; Support for two-argument atan, from Chibi Scheme
(define (atan y . o)
(define (inf? z) (if (= +inf.0 z) #t (= -inf.0 z)))
(if (null? o)
(atan1 y)
(let ((x (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 (or (negative? y) (eqv? y -0.0))
(- (atan1 (/ y x)) 3.141592653589793)
(- 3.141592653589793 (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))))))))
))