From 24dff6bc602118f4f41a8c9667ebbe272ac2e10d Mon Sep 17 00:00:00 2001 From: "Liam M. Healy" Date: Mon, 20 Apr 2015 17:59:32 -0400 Subject: [PATCH] Optionally do not rationalize conversion factors Optionally do not rationalize conversion factors. This has been selected for angles that involve pi. --- physical-quantities/unit-definitions.lisp | 10 +++++----- physical-quantities/units.lisp | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/physical-quantities/unit-definitions.lisp b/physical-quantities/unit-definitions.lisp index a99bf97..059b634 100644 --- a/physical-quantities/unit-definitions.lisp +++ b/physical-quantities/unit-definitions.lisp @@ -1,6 +1,6 @@ ;; Definitions of units and dimensions. ;; Liam Healy Fri Mar 1 2002 - 15:34 -;; Time-stamp: <2011-01-30 18:34:56EST unit-definitions.lisp> +;; Time-stamp: <2015-04-20 12:45:08EDT unit-definitions.lisp> ;; Copyright 2011 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -211,10 +211,10 @@ `((radian 1.0 (rad radians) "rad") (steradian 1.0 (sr steradians)) (degree (/ ,pi 180) - (,(antik-symbol *degree-symbol*) deg degrees) (,*degree-symbol* "\\dgr")) - (arcminute (/ degree 60) (arcmin arcminutes arc-minute arc-minutes)) - (arcsecond (/ arcminute 60) (arcsec arcseconds arc-second arc-seconds)) - (revolution (* 2 ,pi) (rev orbit)))) + (,(antik-symbol *degree-symbol*) deg degrees) (,*degree-symbol* "\\dgr") nil) + (arcminute (/ degree 60) (arcmin arcminutes arc-minute arc-minutes) nil) + (arcsecond (/ arcminute 60) (arcsec arcseconds arc-second arc-seconds) nil) + (revolution (* 2 ,pi) (rev orbit) nil))) ;;;;**************************************************************************** ;;;; Derived units diff --git a/physical-quantities/units.lisp b/physical-quantities/units.lisp index e5276f0..cb9f5ca 100644 --- a/physical-quantities/units.lisp +++ b/physical-quantities/units.lisp @@ -1,6 +1,6 @@ ;; Define physical dimensions and units of measure and systems of units. ;; Liam Healy Wed Feb 27 2002 - 13:18 -;; Time-stamp: <2015-04-06 22:49:09EDT units.lisp> +;; Time-stamp: <2015-04-20 12:51:32EDT units.lisp> ;; Copyright 2011, 2013, 2015 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -509,7 +509,7 @@ (check-uname new new) (dolist (s names) (check-uname new s))) -(defun define-unit (unit definition &optional synonyms print-name dimension) +(defun define-unit (unit definition &optional synonyms print-name dimension (rationalize t)) "Define the unit. If the definition is a number then the dimension information will be extracted from dimension." ;; Check if name/synonym is already defined. @@ -522,7 +522,12 @@ (setf (dimension unit) ;; if dimension is given, use it; otherwise, derive from expression (if dimension (parse-unit-sexp dimension) derived-dim) - (siconversion unit) (if conversion (rationalize conversion) 1) + (siconversion unit) + (if conversion + (if rationalize + (rationalize conversion) + conversion) + 1) (synonyms unit) (pushnew (unit-remove-illegal-chars unit) synonyms) (print-name unit) print-name (canonical-name unit) unit) @@ -534,8 +539,9 @@ "Define the units given. The second argument is a list of lists, each consisting of a unit name, its definition, and a list of synonyms." (dolist (uda unit-def-syn-pnm) - (destructuring-bind (units definition &optional synonyms print-name) uda - (define-unit units definition synonyms print-name dimension)))) + (destructuring-bind (units definition &optional synonyms print-name (rationalize t)) + uda + (define-unit units definition synonyms print-name dimension rationalize)))) (defparameter *unit-symbol-macros* nil "Unit symbols that were defined with unit-symbol-macro.") -- GitLab