Commit 485b39e6 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Add two arguments to atan

New arguments default and zero-enough to handle case where arctangent
is undefined; if both numerator and denominator are essentially zero
(that is, absolute value less than zero-enough), then return default.
parent 4699de4b
;; Generic functions for generalized numbers
;; Liam Healy Tue Feb 9 1999 - 21:38
;; Time-stamp: <2011-03-27 16:37:17EDT generic.lisp>
;; Time-stamp: <2011-06-03 10:06:13EDT generic.lisp>
;; Copyright 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -263,16 +263,20 @@
(return-from acos (cl:acosh arg)))))
(make-radian (cl:acos arg))))
(defgeneric atan (num &optional den)
(:documentation "The arctangent of the generalized or regular number.")
(:method ((num number) &optional (den 1))
(defgeneric atan (num &optional den default zero-enough)
(:documentation "The arctangent of the generalized or regular number. If absolute value of the arguments are below zero-enough, default is returned.")
(:method ((num number)
&optional (den 1) (default 0) (zero-enough (* 64 double-float-epsilon)))
;; zero-enough should be keyed to epsilon of num type
(make-radian
(cl:atan (if (typep num 'rational)
(coerce num *read-default-float-format*)
num)
(if (zerop num)
(signum den)
den)))))
(if (and (< (cl:abs num) zero-enough) (< (cl:abs den) zero-enough))
default
(cl:atan (if (typep num 'rational)
(coerce num *read-default-float-format*)
num)
(if (zerop num)
(signum den)
den))))))
(defgeneric expt (num exponent)
(:documentation "Raise the number to the exponent.")
......
;; Arithmetic with physical quantities.
;; Liam Healy Fri Apr 22 2005 - 09:58
;; Time-stamp: <2011-05-31 18:04:09EDT arithmetic.lisp>
;; Time-stamp: <2011-06-03 10:05:42EDT arithmetic.lisp>
;; Copyright 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -183,10 +183,12 @@
;; This should always signal an error
(check-dimension x 'dimensionless))
(defmethod atan ((num physical-quantity) &optional (den 1))
(defmethod atan ((num physical-quantity)
&optional (den 1) (default 0)
(zero-enough (* 64 double-float-epsilon)))
(equal-dimension num den)
(make-pq
(cl:atan (pqval num) (pqval den))
(atan (pqval num) (pqval den) default zero-enough)
'radian))
(defmethod coerce ((num number) (pq physical-quantity))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment