diff options
| author | Jay Belanger | 2013-01-30 08:14:27 -0600 |
|---|---|---|
| committer | Jay Belanger | 2013-01-30 08:14:27 -0600 |
| commit | 7c3fb76fc9b1ef672911c3385590fe620cae67e9 (patch) | |
| tree | cc737a34e248a43b47ff797853dce12075904224 | |
| parent | f0a9dee778a08283d067642278144fe01ee62d45 (diff) | |
| download | emacs-7c3fb76fc9b1ef672911c3385590fe620cae67e9.tar.gz emacs-7c3fb76fc9b1ef672911c3385590fe620cae67e9.zip | |
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.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/calc/calc-units.el | 90 |
2 files changed, 52 insertions, 44 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 348df715c70..997b0067d74 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-01-30 Jay Belanger <jay.p.belanger@gmail.com> | ||
| 2 | |||
| 3 | * calc-units.el (math-default-units-table): Remove initial value. | ||
| 4 | (calc-convert-units): Treat expressions where all the units cancel as | ||
| 5 | if they didn't have units. | ||
| 6 | |||
| 1 | 2013-01-30 Michael Albinus <michael.albinus@gmx.de> | 7 | 2013-01-30 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 8 | ||
| 3 | * net/tramp.el (tramp-process-connection-type): Fix docstring. | 9 | * net/tramp.el (tramp-process-connection-type): Fix docstring. |
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index a3d037ee042..72d51d9241c 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el | |||
| @@ -404,7 +404,7 @@ If EXPR is nil, return nil." | |||
| 404 | (math-composition-to-string cexpr)))))) | 404 | (math-composition-to-string cexpr)))))) |
| 405 | 405 | ||
| 406 | (defvar math-default-units-table | 406 | (defvar math-default-units-table |
| 407 | #s(hash-table test equal data (1 (1))) | 407 | (make-hash-table :test 'equal) |
| 408 | "A table storing previously converted units.") | 408 | "A table storing previously converted units.") |
| 409 | 409 | ||
| 410 | (defun math-get-default-units (expr) | 410 | (defun math-get-default-units (expr) |
| @@ -442,13 +442,19 @@ If COMP or STD is non-nil, put that in the units table instead." | |||
| 442 | (calc-slow-wrapper | 442 | (calc-slow-wrapper |
| 443 | (let ((expr (calc-top-n 1)) | 443 | (let ((expr (calc-top-n 1)) |
| 444 | (uoldname nil) | 444 | (uoldname nil) |
| 445 | (unitscancel nil) | ||
| 445 | unew | 446 | unew |
| 446 | units | 447 | units |
| 447 | defunits) | 448 | defunits) |
| 448 | (unless (math-units-in-expr-p expr t) | 449 | (if (or (not (math-units-in-expr-p expr t)) |
| 450 | (setq unitscancel (eq (math-get-standard-units expr) 1))) | ||
| 449 | (let ((uold (or old-units | 451 | (let ((uold (or old-units |
| 450 | (progn | 452 | (progn |
| 451 | (setq uoldname (read-string "Old units: ")) | 453 | (setq uoldname |
| 454 | (if unitscancel | ||
| 455 | (read-string | ||
| 456 | "(The expression is unitless when simplified) Old Units: ") | ||
| 457 | (read-string "Old units: "))) | ||
| 452 | (if (equal uoldname "") | 458 | (if (equal uoldname "") |
| 453 | (progn | 459 | (progn |
| 454 | (setq uoldname "1") | 460 | (setq uoldname "1") |
| @@ -460,47 +466,43 @@ If COMP or STD is non-nil, put that in the units table instead." | |||
| 460 | (error "Bad format in units expression: %s" (nth 1 uold))) | 466 | (error "Bad format in units expression: %s" (nth 1 uold))) |
| 461 | (setq expr (math-mul expr uold)))) | 467 | (setq expr (math-mul expr uold)))) |
| 462 | (setq defunits (math-get-default-units expr)) | 468 | (setq defunits (math-get-default-units expr)) |
| 463 | (if (equal defunits "1") | 469 | (unless new-units |
| 464 | (progn | 470 | (setq new-units |
| 465 | (calc-enter-result 1 "cvun" (math-simplify-units expr)) | 471 | (read-string (concat |
| 466 | (message "All units in expression cancel")) | 472 | (if uoldname |
| 467 | (unless new-units | 473 | (concat "Old units: " |
| 468 | (setq new-units | 474 | uoldname |
| 469 | (read-string (concat | 475 | ", new units") |
| 470 | (if uoldname | 476 | "New units") |
| 471 | (concat "Old units: " | 477 | (if defunits |
| 472 | uoldname | 478 | (concat |
| 473 | ", new units") | 479 | " (default " |
| 474 | "New units") | 480 | defunits |
| 475 | (if defunits | 481 | "): ") |
| 476 | (concat | 482 | ": ")))) |
| 477 | " (default " | 483 | (if (and |
| 478 | defunits | 484 | (string= new-units "") |
| 479 | "): ") | 485 | defunits) |
| 480 | ": ")))) | 486 | (setq new-units defunits))) |
| 481 | (if (and | 487 | (when (string-match "\\` */" new-units) |
| 482 | (string= new-units "") | 488 | (setq new-units (concat "1" new-units))) |
| 483 | defunits) | 489 | (setq units (math-read-expr new-units)) |
| 484 | (setq new-units defunits))) | 490 | (when (eq (car-safe units) 'error) |
| 485 | (when (string-match "\\` */" new-units) | 491 | (error "Bad format in units expression: %s" (nth 2 units))) |
| 486 | (setq new-units (concat "1" new-units))) | 492 | (if calc-ensure-consistent-units |
| 487 | (setq units (math-read-expr new-units)) | 493 | (math-check-unit-consistency expr units)) |
| 488 | (when (eq (car-safe units) 'error) | 494 | (let ((unew (math-units-in-expr-p units t)) |
| 489 | (error "Bad format in units expression: %s" (nth 2 units))) | 495 | (std (and (eq (car-safe units) 'var) |
| 490 | (if calc-ensure-consistent-units | 496 | (assq (nth 1 units) math-standard-units-systems))) |
| 491 | (math-check-unit-consistency expr units)) | 497 | (comp (eq (car-safe units) '+))) |
| 492 | (let ((unew (math-units-in-expr-p units t)) | 498 | (unless (or unew std) |
| 493 | (std (and (eq (car-safe units) 'var) | 499 | (error "No units specified")) |
| 494 | (assq (nth 1 units) math-standard-units-systems))) | 500 | (let ((res |
| 495 | (comp (eq (car-safe units) '+))) | 501 | (if std |
| 496 | (unless (or unew std) | 502 | (math-simplify-units (math-to-standard-units expr (nth 1 std))) |
| 497 | (error "No units specified")) | 503 | (math-convert-units expr units (and uoldname (not (equal uoldname "1"))))))) |
| 498 | (let ((res | 504 | (math-put-default-units res (if comp units)) |
| 499 | (if std | 505 | (calc-enter-result 1 "cvun" res)))))) |
| 500 | (math-simplify-units (math-to-standard-units expr (nth 1 std))) | ||
| 501 | (math-convert-units expr units (and uoldname (not (equal uoldname "1"))))))) | ||
| 502 | (math-put-default-units res (if comp units)) | ||
| 503 | (calc-enter-result 1 "cvun" res))))))) | ||
| 504 | 506 | ||
| 505 | (defun calc-autorange-units (arg) | 507 | (defun calc-autorange-units (arg) |
| 506 | (interactive "P") | 508 | (interactive "P") |