Verified Commit ad6432e3 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Signal error in equal-dimension when errorp=T

If equal-dimension is called with errorp=T and two grids that do not
have the same dimension and at least one had non-scalar-dimension,
signal an error. Previously, this would just return NIL NIL even though
errorp is T.

References
[[id:a456e075-1746-454d-b68c-ad6fa21fb293][Zero in matrix-from-columns can't be added]]
[[id:39fe9321-7260-4335-bb3e-735ba1d00e43][Alternative approach to mixed/scalar pq-grid]]
parent 86a54307
Loading
Loading
Loading
Loading
+28 −20
Original line number Diff line number Diff line
;; Objects that represent physical measurements.                             
;; Liam Healy Wed Mar  6 2002 - 09:04
;; Time-stamp: <2015-01-01 12:19:05EST physical-quantities.lisp>
;; Time-stamp: <2015-11-28 22:24:53EST physical-quantities.lisp>

;; Copyright 2011, 2012, 2013, 2014, 2015 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
@@ -107,26 +107,34 @@
   dimension.  If y represents a dimensionless quantity,
   and match-dimensionless is true, return the dimel of x.
   Return two values: the dimel and whether it is scalar dimension."
  (flet ((err-return ()
	   (when errorp (error "The quantities ~a and ~a are not both physical ~
               quantities with the same physical dimension." x y))))
    (cond ((and zeros-have-any-dimension (zerop x))
	   (values (dimel-or-not y) (scalar-dimension y)))
	  ((and zeros-have-any-dimension (zerop y))
	   (values (dimel-or-not x) (scalar-dimension x)))
	((equalp (dimel-or-not x) (dimel-or-not y))
	  ((and (eql (scalar-dimension x) (scalar-dimension y))
		(equalp (dimel-or-not x) (dimel-or-not y)))
	   ;; Covers the case of both having non-scalar units or both having scalar units
	   (values (dimel-or-not x) (scalar-dimension x)))
	;; If one or both has scalar units, break out the individual dimensions.
	  ((and match-dimensionless (equal (dimel-or-not y) (dimel-or-not nil)))
	   (dimel-or-not x))
	  ;; If only one has non-scalar units, break out the individual dimensions.
	  ((and (grid:gridp x) (grid:gridp y)
		(or (not (scalar-dimension y)) (not (scalar-dimension x))))
	   ;; All same units, possibly one has scalar dimension
	   (multiple-value-bind (they-are value)
	       (all-same	       ; repurposing 2nd return value 
		(concatenate
		 'list
		 (if (scalar-dimension x) (list (pq-dimension x)) (pq-dimension x))
		 (if (scalar-dimension y) (list (pq-dimension y)) (pq-dimension y)))
	  :test #'cl:equal))
	((and match-dimensionless (equal (dimel-or-not y) (dimel-or-not nil)))
	 (dimel-or-not x))
	(errorp (error "The quantities ~a and ~a are not both physical ~
               quantities with the same physical dimension." x y))))
		:test #'cl:equal)
	     (if they-are
		 (values they-are value)
		 (err-return))))
	  (t (err-return)))))

(defun dimel-or-not (object)
  "Find the dimel for this object (a physical dimension quantity or a dimel), or