emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111627: calc-units.el (math-default-


From: Jay Belanger
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111627: calc-units.el (math-default-units-table): Remove initial value.
Date: Wed, 30 Jan 2013 08:14:27 -0600
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111627
committer: Jay Belanger <address@hidden>
branch nick: trunk
timestamp: Wed 2013-01-30 08:14:27 -0600
message:
  calc-units.el (math-default-units-table): Remove initial value.
  
  (calc-convert-units): Treat expressions where all the units cancel as
  if they didn't have units.
modified:
  lisp/ChangeLog
  lisp/calc/calc-units.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-01-30 09:16:16 +0000
+++ b/lisp/ChangeLog    2013-01-30 14:14:27 +0000
@@ -1,3 +1,9 @@
+2013-01-30  Jay Belanger  <address@hidden>
+
+       * calc-units.el (math-default-units-table): Remove initial value.
+       (calc-convert-units): Treat expressions where all the units cancel as
+       if they didn't have units.
+
 2013-01-30  Michael Albinus  <address@hidden>
 
        * net/tramp.el (tramp-process-connection-type): Fix docstring.

=== modified file 'lisp/calc/calc-units.el'
--- a/lisp/calc/calc-units.el   2013-01-01 09:11:05 +0000
+++ b/lisp/calc/calc-units.el   2013-01-30 14:14:27 +0000
@@ -404,7 +404,7 @@
            (math-composition-to-string cexpr))))))
 
 (defvar math-default-units-table
-  #s(hash-table test equal data (1 (1)))
+  (make-hash-table :test 'equal)
   "A table storing previously converted units.")
 
 (defun math-get-default-units (expr)
@@ -442,13 +442,19 @@
   (calc-slow-wrapper
    (let ((expr (calc-top-n 1))
         (uoldname nil)
+         (unitscancel nil)
         unew
          units
          defunits)
-     (unless (math-units-in-expr-p expr t)
+     (if (or (not (math-units-in-expr-p expr t))
+             (setq unitscancel (eq (math-get-standard-units expr) 1)))
        (let ((uold (or old-units
                       (progn
-                        (setq uoldname (read-string "Old units: "))
+                        (setq uoldname 
+                               (if unitscancel
+                                   (read-string 
+                                    "(The expression is unitless when 
simplified) Old Units: ")
+                                 (read-string "Old units: ")))
                         (if (equal uoldname "")
                             (progn
                               (setq uoldname "1")
@@ -460,47 +466,43 @@
           (error "Bad format in units expression: %s" (nth 1 uold)))
         (setq expr (math-mul expr uold))))
      (setq defunits (math-get-default-units expr))
-     (if (equal defunits "1")
-         (progn
-           (calc-enter-result 1 "cvun" (math-simplify-units expr))
-           (message "All units in expression cancel"))
-       (unless new-units
-         (setq new-units
-               (read-string (concat
-                             (if uoldname
-                                 (concat "Old units: "
-                                         uoldname
-                                         ", new units")
-                               "New units")
-                             (if defunits
-                                 (concat
-                                  " (default "
-                                  defunits
-                                  "): ")
-                               ": "))))
-         (if (and
-              (string= new-units "")
-              defunits)
-             (setq new-units defunits)))
-       (when (string-match "\\` */" new-units)
-         (setq new-units (concat "1" new-units)))
-       (setq units (math-read-expr new-units))
-       (when (eq (car-safe units) 'error)
-         (error "Bad format in units expression: %s" (nth 2 units)))
-       (if calc-ensure-consistent-units
-           (math-check-unit-consistency expr units))
-       (let ((unew (math-units-in-expr-p units t))
-             (std (and (eq (car-safe units) 'var)
-                       (assq (nth 1 units) math-standard-units-systems)))
-             (comp (eq (car-safe units) '+)))
-        (unless (or unew std)
-          (error "No units specified"))
-         (let ((res
-                (if std
-                    (math-simplify-units (math-to-standard-units expr (nth 1 
std)))
-                  (math-convert-units expr units (and uoldname (not (equal 
uoldname "1")))))))
-           (math-put-default-units res (if comp units))
-           (calc-enter-result 1 "cvun" res)))))))
+     (unless new-units
+       (setq new-units
+             (read-string (concat
+                           (if uoldname
+                               (concat "Old units: "
+                                       uoldname
+                                       ", new units")
+                             "New units")
+                           (if defunits
+                               (concat
+                                " (default "
+                                defunits
+                                "): ")
+                             ": "))))
+       (if (and
+            (string= new-units "")
+            defunits)
+           (setq new-units defunits)))
+     (when (string-match "\\` */" new-units)
+       (setq new-units (concat "1" new-units)))
+     (setq units (math-read-expr new-units))
+     (when (eq (car-safe units) 'error)
+       (error "Bad format in units expression: %s" (nth 2 units)))
+     (if calc-ensure-consistent-units
+         (math-check-unit-consistency expr units))
+     (let ((unew (math-units-in-expr-p units t))
+           (std (and (eq (car-safe units) 'var)
+                     (assq (nth 1 units) math-standard-units-systems)))
+           (comp (eq (car-safe units) '+)))
+       (unless (or unew std)
+         (error "No units specified"))
+       (let ((res
+              (if std
+                  (math-simplify-units (math-to-standard-units expr (nth 1 
std)))
+                (math-convert-units expr units (and uoldname (not (equal 
uoldname "1")))))))
+         (math-put-default-units res (if comp units))
+         (calc-enter-result 1 "cvun" res))))))
 
 (defun calc-autorange-units (arg)
   (interactive "P")


reply via email to

[Prev in Thread] Current Thread [Next in Thread]