Commit 27d65bc2 authored by Liam Healy's avatar Liam Healy

Make atan work with args (number pdq)

Because atan has only one mandatory (specializible) argument, the
numerator, the denominator cannot be specialized, so (number
physical-quantity) caused an error. This is fixed with an :around method
loaded with physical-quantities that will coerce the numerator to the
same dimensions as the denominator (units will be the system of units
for that dimension).
parent 82605b18
;; Conditions and handlers for arithmetic.
;; Liam Healy Tue May 17 2005 - 16:29
;; Time-stamp: <2014-01-05 14:05:35EST conditions.lisp>
;; Time-stamp: <2015-12-17 15:42:30EST conditions.lisp>
;; Copyright 2011, 2014 Liam M. Healy
;; Copyright 2011, 2014, 2015 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -20,7 +20,7 @@
(in-package :antik)
(export '(coerce-undefined coerce-nil making-complex-number
(export '(coerce-undefined coerce-nil making-complex-number accept-coerce
handling-complex-number arithmetic-errors-return-nan))
;;;;****************************************************************************
......@@ -93,6 +93,14 @@
,@body)
(return (&optional v) v)))
(defmacro accept-coerce (&body body)
"A handler to accept coerced object."
`(handler-bind
((error #'(lambda (c)
(let ((r (find-restart 'continue c)))
(when r (invoke-restart r))))))
,@body))
#+global-handler
(setf *debugger-hook*
(lambda (condition old-hook)
......
;; Arithmetic with physical dimension quantities.
;; Liam Healy Fri Apr 22 2005 - 09:58
;; Time-stamp: <2015-09-07 09:39:33EDT arithmetic.lisp>
;; Time-stamp: <2015-12-17 15:49:44EST arithmetic.lisp>
;; Copyright 2011, 2013, 2015 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -195,11 +195,20 @@
(atan (pqval num) (pqval den) default zero-enough)
'radian))
(defmethod atan :around ((num number)
&optional (den 1) (default 0)
(zero-enough (* 64 double-float-epsilon)))
(if (physical-quantity-p den)
(atan
(let ((*zero-is-dimensionless* nil)) (accept-coerce (coerce num den)))
den default zero-enough)
(call-next-method)))
(defmethod coerce ((num number) (pq physical-quantity))
(cerror "Accept"
"Coercing number ~a to physical dimension quantity ~a"
num (nth-value 1 (pqval pq)))
(make-pq-object num (pq-dimension pq) t))
num (nth-value 1 (pqval pq)))
(make-pq num (nth-value 1 (pqval pq))))
(defmethod expt ((x physical-quantity) expon)
(undimensioned-should-not-be-here)
......
;; Physical dimension quantity with a magnitude that is a scalar
;; Liam Healy 2011-01-01 12:05:37EST grid.lisp
;; Time-stamp: <2015-04-25 10:18:08EDT scalar.lisp>
;; Time-stamp: <2015-12-17 14:59:02EST scalar.lisp>
;; Copyright 2011, 2013 Liam M. Healy
;; Copyright 2011, 2013, 2015 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......
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