]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc.el
Merge from emacs-24; up to 2012-05-04T19:17:01Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / calc / calc.el
index 626d2462b4f1a5bf59e364d1c627382fee928433..3e6ae1c7404e83293b277a87843621e9b262f497 100644 (file)
@@ -1,6 +1,6 @@
 ;;; calc.el --- the GNU Emacs calculator
 
-;; Copyright (C) 1990-1993, 2001-2011  Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2012  Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 
 (defgroup calc nil
-  "GNU Calc."
+  "Advanced desk calculator and mathematical tool."
   :prefix "calc-"
   :tag    "Calc"
   :group  'applications)
@@ -418,6 +418,13 @@ in normal mode."
   :group 'calc
   :type 'boolean)
 
+(defcustom calc-ensure-consistent-units
+  nil
+  "If non-nil, make sure new units are consistent with current units
+when converting units."
+  :group 'calc
+  :type 'boolean)
+
 (defcustom calc-undo-length
   100
   "The number of undo steps that will be preserved when Calc is quit."
@@ -431,24 +438,28 @@ If `calc-show-selections' is non-nil, then selected sub-formulas are shown
 by displaying the rest of the formula in `calc-nonselected-face'.
 If `calc-show-selections' is nil, then selected sub-formulas are shown
 by displaying the sub-formula in `calc-selected-face'."
+  :version "24.1"
   :group 'calc
   :type 'boolean)
 
 (defcustom calc-lu-field-reference
   "20 uPa"
   "The default reference level for logarithmic units (field)."
+  :version "24.1"
   :group 'calc
   :type '(string))
 
 (defcustom calc-lu-power-reference
   "mW"
   "The default reference level for logarithmic units (power)."
+  :version "24.1"
   :group 'calc
   :type '(string))
 
 (defcustom calc-note-threshold "1"
   "The number of cents that a frequency should be near a note
 to be identified as that note."
+  :version "24.1"
   :type 'string
   :group 'calc)
 
@@ -687,11 +698,11 @@ If `C' is present, display outer brackets for matrices (centered).")
 (defcalcmodevar calc-previous-modulo nil
   "Most recently used value of M in a modulo form.")
 
-(defcalcmodevar calc-simplify-mode nil
+(defcalcmodevar calc-simplify-mode 'alg
   "Type of simplification applied to results.
 If `none', results are not simplified when pushed on the stack.
 If `num', functions are simplified only when args are constant.
-If nil, only fast simplifications are applied.
+If nil, only limited simplifications are applied.
 If `binary', `math-clip' is applied if appropriate.
 If `alg', `math-simplify' is applied.
 If `ext', `math-simplify-extended' is applied.
@@ -813,7 +824,7 @@ If nil, selections displayed but ignored.")
 Used by `calc-user-invocation'.")
 
 (defcalcmodevar calc-show-banner t
-  "*If non-nil, show a friendly greeting above the stack.")
+  "If non-nil, show a friendly greeting above the stack.")
 
 (defconst calc-local-var-list '(calc-stack
                                calc-stack-top
@@ -903,7 +914,7 @@ Used by `calc-user-invocation'.")
 
 ;; Set up the autoloading linkage.
 (let ((name (and (fboundp 'calc-dispatch)
-                 (eq (car-safe (symbol-function 'calc-dispatch)) 'autoload)
+                 (autoloadp (symbol-function 'calc-dispatch))
                  (nth 1 (symbol-function 'calc-dispatch))))
       (p load-path))
 
@@ -1003,7 +1014,7 @@ Used by `calc-user-invocation'.")
 (defvar calc-quick-prev-results nil
   "Previous results from Quick Calc.")
 (defvar calc-said-hello nil
-  "Non-nil if the welcomd message has been displayed.")
+  "Non-nil if the welcome message has been displayed.")
 (defvar calc-executing-macro nil
   "Non-nil if a keyboard macro is executing from the \"K\" key.")
 (defvar calc-any-selections nil
@@ -1746,10 +1757,10 @@ See calc-keypad for details."
                           ((eq calc-simplify-mode 'num) "NumSimp ")
                           ((eq calc-simplify-mode 'binary)
                            (format "BinSimp%d " calc-word-size))
-                          ((eq calc-simplify-mode 'alg) "AlgSimp ")
+                          ((eq calc-simplify-mode 'alg) "")
                           ((eq calc-simplify-mode 'ext) "ExtSimp ")
                           ((eq calc-simplify-mode 'units) "UnitSimp ")
-                          (t ""))
+                          (t "BasicSimp "))
 
                     ;; Display modes
                     (cond ((= calc-number-radix 10) "")
@@ -2572,7 +2583,11 @@ largest Emacs integer.")
 ;;; Reduce an object to canonical (normalized) form.  [O o; Z Z] [Public]
 
 (defvar math-normalize-a)
+(defvar math-normalize-error nil
+  "Non-nil if the last call the `math-normalize' returned an error.")
+
 (defun math-normalize (math-normalize-a)
+  (setq math-normalize-error nil)
   (cond
    ((not (consp math-normalize-a))
     (if (integerp math-normalize-a)
@@ -2661,31 +2676,38 @@ largest Emacs integer.")
                                        (fboundp (car math-normalize-a))))
                               (apply (car math-normalize-a) args)))))
                (wrong-number-of-arguments
+                 (setq math-normalize-error t)
                 (calc-record-why "*Wrong number of arguments"
                                  (cons (car math-normalize-a) args))
                 nil)
                (wrong-type-argument
+                 (setq math-normalize-error t)
                 (or calc-next-why
                      (calc-record-why "Wrong type of argument"
                                       (cons (car math-normalize-a) args)))
                 nil)
                (args-out-of-range
+                 (setq math-normalize-error t)
                 (calc-record-why "*Argument out of range"
                                   (cons (car math-normalize-a) args))
                 nil)
                (inexact-result
+                 (setq math-normalize-error t)
                 (calc-record-why "No exact representation for result"
                                  (cons (car math-normalize-a) args))
                 nil)
                (math-overflow
+                 (setq math-normalize-error t)
                 (calc-record-why "*Floating-point overflow occurred"
                                  (cons (car math-normalize-a) args))
                 nil)
                (math-underflow
+                 (setq math-normalize-error t)
                 (calc-record-why "*Floating-point underflow occurred"
                                  (cons (car math-normalize-a) args))
                 nil)
                (void-variable
+                 (setq math-normalize-error t)
                 (if (eq (nth 1 err) 'var-EvalRules)
                     (progn
                       (setq var-EvalRules nil)