diff options
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/calc/calc.el | 236 |
2 files changed, 114 insertions, 125 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8bfd1dfa019..09ddbe5fe56 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2009-08-30 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2009-08-30 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * calc/calc.el: Improve commenting convention. | ||
| 4 | (calc-digit-map, toplevel): Simplify. | ||
| 5 | |||
| 3 | * comint.el (comint-insert-input): Be careful to only set point if we | 6 | * comint.el (comint-insert-input): Be careful to only set point if we |
| 4 | don't delegate to some other command. | 7 | don't delegate to some other command. |
| 5 | 8 | ||
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index 790647d62ca..d38d6b7dbde 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el | |||
| @@ -1043,25 +1043,13 @@ Used by `calc-user-invocation'.") | |||
| 1043 | map) | 1043 | map) |
| 1044 | "The key map for Calc.") | 1044 | "The key map for Calc.") |
| 1045 | 1045 | ||
| 1046 | |||
| 1047 | |||
| 1048 | (defvar calc-digit-map | 1046 | (defvar calc-digit-map |
| 1049 | (let ((map (make-keymap))) | 1047 | (let ((map (make-keymap))) |
| 1050 | (if (featurep 'xemacs) | 1048 | (map-keymap (lambda (key bind) |
| 1051 | (map-keymap (function | 1049 | (define-key map (vector key) |
| 1052 | (lambda (keys bind) | 1050 | (if (eq bind 'undefined) |
| 1053 | (define-key map keys | 1051 | 'undefined 'calcDigit-nondigit))) |
| 1054 | (if (eq bind 'undefined) | 1052 | calc-mode-map) |
| 1055 | 'undefined 'calcDigit-nondigit)))) | ||
| 1056 | calc-mode-map) | ||
| 1057 | (let ((cmap (nth 1 calc-mode-map)) | ||
| 1058 | (dmap (nth 1 map)) | ||
| 1059 | (i 0)) | ||
| 1060 | (while (< i 128) | ||
| 1061 | (aset dmap i | ||
| 1062 | (if (eq (aref cmap i) 'undefined) | ||
| 1063 | 'undefined 'calcDigit-nondigit)) | ||
| 1064 | (setq i (1+ i))))) | ||
| 1065 | (mapc (lambda (x) (define-key map (char-to-string x) 'calcDigit-key)) | 1053 | (mapc (lambda (x) (define-key map (char-to-string x) 'calcDigit-key)) |
| 1066 | "_0123456789.e+-:n#@oh'\"mspM") | 1054 | "_0123456789.e+-:n#@oh'\"mspM") |
| 1067 | (mapc (lambda (x) (define-key map (char-to-string x) 'calcDigit-letter)) | 1055 | (mapc (lambda (x) (define-key map (char-to-string x) 'calcDigit-letter)) |
| @@ -1078,15 +1066,13 @@ Used by `calc-user-invocation'.") | |||
| 1078 | (define-key calc-digit-map x 'calcDigit-backspace) | 1066 | (define-key calc-digit-map x 'calcDigit-backspace) |
| 1079 | (define-key calc-mode-map x 'calc-pop) | 1067 | (define-key calc-mode-map x 'calc-pop) |
| 1080 | (define-key calc-mode-map | 1068 | (define-key calc-mode-map |
| 1081 | (if (vectorp x) | 1069 | (if (and (vectorp x) (featurep 'xemacs)) |
| 1082 | (if (featurep 'xemacs) | 1070 | (if (= (length x) 1) |
| 1083 | (if (= (length x) 1) | 1071 | (vector (if (consp (aref x 0)) |
| 1084 | (vector (if (consp (aref x 0)) | 1072 | (cons 'meta (aref x 0)) |
| 1085 | (cons 'meta (aref x 0)) | 1073 | (list 'meta (aref x 0)))) |
| 1086 | (list 'meta (aref x 0)))) | 1074 | "\e\C-d") |
| 1087 | "\e\C-d") | 1075 | (vconcat "\e" x)) |
| 1088 | (vconcat "\e" x)) | ||
| 1089 | (concat "\e" x)) | ||
| 1090 | 'calc-pop-above)) | 1076 | 'calc-pop-above)) |
| 1091 | (error nil))) | 1077 | (error nil))) |
| 1092 | (if calc-scan-for-dels | 1078 | (if calc-scan-for-dels |
| @@ -2436,101 +2422,101 @@ largest Emacs integer.") | |||
| 2436 | 2422 | ||
| 2437 | 2423 | ||
| 2438 | ;;;; Arithmetic routines. | 2424 | ;;;; Arithmetic routines. |
| 2439 | ;;; | 2425 | ;; |
| 2440 | ;;; An object as manipulated by one of these routines may take any of the | 2426 | ;; An object as manipulated by one of these routines may take any of the |
| 2441 | ;;; following forms: | 2427 | ;; following forms: |
| 2442 | ;;; | 2428 | ;; |
| 2443 | ;;; integer An integer. For normalized numbers, this format | 2429 | ;; integer An integer. For normalized numbers, this format |
| 2444 | ;;; is used only for | 2430 | ;; is used only for |
| 2445 | ;;; negative math-small-integer-size + 1 to | 2431 | ;; negative math-small-integer-size + 1 to |
| 2446 | ;;; math-small-integer-size - 1 | 2432 | ;; math-small-integer-size - 1 |
| 2447 | ;;; | 2433 | ;; |
| 2448 | ;;; (bigpos N0 N1 N2 ...) A big positive integer, | 2434 | ;; (bigpos N0 N1 N2 ...) A big positive integer, |
| 2449 | ;;; N0 + N1*math-bignum-digit-size | 2435 | ;; N0 + N1*math-bignum-digit-size |
| 2450 | ;;; + N2*(math-bignum-digit-size)^2 ... | 2436 | ;; + N2*(math-bignum-digit-size)^2 ... |
| 2451 | ;;; (bigneg N0 N1 N2 ...) A big negative integer, | 2437 | ;; (bigneg N0 N1 N2 ...) A big negative integer, |
| 2452 | ;;; - N0 - N1*math-bignum-digit-size ... | 2438 | ;; - N0 - N1*math-bignum-digit-size ... |
| 2453 | ;;; Each digit N is in the range | 2439 | ;; Each digit N is in the range |
| 2454 | ;;; 0 ... math-bignum-digit-size -1. | 2440 | ;; 0 ... math-bignum-digit-size -1. |
| 2455 | ;;; Normalized, always at least three N present, | 2441 | ;; Normalized, always at least three N present, |
| 2456 | ;;; and the most significant N is nonzero. | 2442 | ;; and the most significant N is nonzero. |
| 2457 | ;;; | 2443 | ;; |
| 2458 | ;;; (frac NUM DEN) A fraction. NUM and DEN are small or big integers. | 2444 | ;; (frac NUM DEN) A fraction. NUM and DEN are small or big integers. |
| 2459 | ;;; Normalized, DEN > 1. | 2445 | ;; Normalized, DEN > 1. |
| 2460 | ;;; | 2446 | ;; |
| 2461 | ;;; (float NUM EXP) A floating-point number, NUM * 10^EXP; | 2447 | ;; (float NUM EXP) A floating-point number, NUM * 10^EXP; |
| 2462 | ;;; NUM is a small or big integer, EXP is a small int. | 2448 | ;; NUM is a small or big integer, EXP is a small int. |
| 2463 | ;;; Normalized, NUM is not a multiple of 10, and | 2449 | ;; Normalized, NUM is not a multiple of 10, and |
| 2464 | ;;; abs(NUM) < 10^calc-internal-prec. | 2450 | ;; abs(NUM) < 10^calc-internal-prec. |
| 2465 | ;;; Normalized zero is stored as (float 0 0). | 2451 | ;; Normalized zero is stored as (float 0 0). |
| 2466 | ;;; | 2452 | ;; |
| 2467 | ;;; (cplx REAL IMAG) A complex number; REAL and IMAG are any of above. | 2453 | ;; (cplx REAL IMAG) A complex number; REAL and IMAG are any of above. |
| 2468 | ;;; Normalized, IMAG is nonzero. | 2454 | ;; Normalized, IMAG is nonzero. |
| 2469 | ;;; | 2455 | ;; |
| 2470 | ;;; (polar R THETA) Polar complex number. Normalized, R > 0 and THETA | 2456 | ;; (polar R THETA) Polar complex number. Normalized, R > 0 and THETA |
| 2471 | ;;; is neither zero nor 180 degrees (pi radians). | 2457 | ;; is neither zero nor 180 degrees (pi radians). |
| 2472 | ;;; | 2458 | ;; |
| 2473 | ;;; (vec A B C ...) Vector of objects A, B, C, ... A matrix is a | 2459 | ;; (vec A B C ...) Vector of objects A, B, C, ... A matrix is a |
| 2474 | ;;; vector of vectors. | 2460 | ;; vector of vectors. |
| 2475 | ;;; | 2461 | ;; |
| 2476 | ;;; (hms H M S) Angle in hours-minutes-seconds form. All three | 2462 | ;; (hms H M S) Angle in hours-minutes-seconds form. All three |
| 2477 | ;;; components have the same sign; H and M must be | 2463 | ;; components have the same sign; H and M must be |
| 2478 | ;;; numerically integers; M and S are expected to | 2464 | ;; numerically integers; M and S are expected to |
| 2479 | ;;; lie in the range [0,60). | 2465 | ;; lie in the range [0,60). |
| 2480 | ;;; | 2466 | ;; |
| 2481 | ;;; (date N) A date or date/time object. N is an integer to | 2467 | ;; (date N) A date or date/time object. N is an integer to |
| 2482 | ;;; store a date only, or a fraction or float to | 2468 | ;; store a date only, or a fraction or float to |
| 2483 | ;;; store a date and time. | 2469 | ;; store a date and time. |
| 2484 | ;;; | 2470 | ;; |
| 2485 | ;;; (sdev X SIGMA) Error form, X +/- SIGMA. When normalized, | 2471 | ;; (sdev X SIGMA) Error form, X +/- SIGMA. When normalized, |
| 2486 | ;;; SIGMA > 0. X is any complex number and SIGMA | 2472 | ;; SIGMA > 0. X is any complex number and SIGMA |
| 2487 | ;;; is real numbers; or these may be symbolic | 2473 | ;; is real numbers; or these may be symbolic |
| 2488 | ;;; expressions where SIGMA is assumed real. | 2474 | ;; expressions where SIGMA is assumed real. |
| 2489 | ;;; | 2475 | ;; |
| 2490 | ;;; (intv MASK LO HI) Interval form. MASK is 0=(), 1=(], 2=[), or 3=[]. | 2476 | ;; (intv MASK LO HI) Interval form. MASK is 0=(), 1=(], 2=[), or 3=[]. |
| 2491 | ;;; LO and HI are any real numbers, or symbolic | 2477 | ;; LO and HI are any real numbers, or symbolic |
| 2492 | ;;; expressions which are assumed real, and LO < HI. | 2478 | ;; expressions which are assumed real, and LO < HI. |
| 2493 | ;;; For [LO..HI], if LO = HI normalization produces LO, | 2479 | ;; For [LO..HI], if LO = HI normalization produces LO, |
| 2494 | ;;; and if LO > HI normalization produces [LO..LO). | 2480 | ;; and if LO > HI normalization produces [LO..LO). |
| 2495 | ;;; For other intervals, if LO > HI normalization | 2481 | ;; For other intervals, if LO > HI normalization |
| 2496 | ;;; sets HI equal to LO. | 2482 | ;; sets HI equal to LO. |
| 2497 | ;;; | 2483 | ;; |
| 2498 | ;;; (mod N M) Number modulo M. When normalized, 0 <= N < M. | 2484 | ;; (mod N M) Number modulo M. When normalized, 0 <= N < M. |
| 2499 | ;;; N and M are real numbers. | 2485 | ;; N and M are real numbers. |
| 2500 | ;;; | 2486 | ;; |
| 2501 | ;;; (var V S) Symbolic variable. V is a Lisp symbol which | 2487 | ;; (var V S) Symbolic variable. V is a Lisp symbol which |
| 2502 | ;;; represents the variable's visible name. S is | 2488 | ;; represents the variable's visible name. S is |
| 2503 | ;;; the symbol which actually stores the variable's | 2489 | ;; the symbol which actually stores the variable's |
| 2504 | ;;; value: (var pi var-pi). | 2490 | ;; value: (var pi var-pi). |
| 2505 | ;;; | 2491 | ;; |
| 2506 | ;;; In general, combining rational numbers in a calculation always produces | 2492 | ;; In general, combining rational numbers in a calculation always produces |
| 2507 | ;;; a rational result, but if either argument is a float, result is a float. | 2493 | ;; a rational result, but if either argument is a float, result is a float. |
| 2508 | 2494 | ||
| 2509 | ;;; In the following comments, [x y z] means result is x, args must be y, z, | 2495 | ;; In the following comments, [x y z] means result is x, args must be y, z, |
| 2510 | ;;; respectively, where the code letters are: | 2496 | ;; respectively, where the code letters are: |
| 2511 | ;;; | 2497 | ;; |
| 2512 | ;;; O Normalized object (vector or number) | 2498 | ;; O Normalized object (vector or number) |
| 2513 | ;;; V Normalized vector | 2499 | ;; V Normalized vector |
| 2514 | ;;; N Normalized number of any type | 2500 | ;; N Normalized number of any type |
| 2515 | ;;; N Normalized complex number | 2501 | ;; N Normalized complex number |
| 2516 | ;;; R Normalized real number (float or rational) | 2502 | ;; R Normalized real number (float or rational) |
| 2517 | ;;; F Normalized floating-point number | 2503 | ;; F Normalized floating-point number |
| 2518 | ;;; T Normalized rational number | 2504 | ;; T Normalized rational number |
| 2519 | ;;; I Normalized integer | 2505 | ;; I Normalized integer |
| 2520 | ;;; B Normalized big integer | 2506 | ;; B Normalized big integer |
| 2521 | ;;; S Normalized small integer | 2507 | ;; S Normalized small integer |
| 2522 | ;;; D Digit (small integer, 0..999) | 2508 | ;; D Digit (small integer, 0..999) |
| 2523 | ;;; L Normalized bignum digit list (without "bigpos" or "bigneg" symbol) | 2509 | ;; L Normalized bignum digit list (without "bigpos" or "bigneg" symbol) |
| 2524 | ;;; or normalized vector element list (without "vec") | 2510 | ;; or normalized vector element list (without "vec") |
| 2525 | ;;; P Predicate (truth value) | 2511 | ;; P Predicate (truth value) |
| 2526 | ;;; X Any Lisp object | 2512 | ;; X Any Lisp object |
| 2527 | ;;; Z "nil" | 2513 | ;; Z "nil" |
| 2528 | ;;; | 2514 | ;; |
| 2529 | ;;; Lower-case letters signify possibly un-normalized values. | 2515 | ;; Lower-case letters signify possibly un-normalized values. |
| 2530 | ;;; "L.D" means a cons of an L and a D. | 2516 | ;; "L.D" means a cons of an L and a D. |
| 2531 | ;;; [N N; n n] means result will be normalized if argument is. | 2517 | ;; [N N; n n] means result will be normalized if argument is. |
| 2532 | ;;; Also, [Public] marks routines intended to be called from outside. | 2518 | ;; Also, [Public] marks routines intended to be called from outside. |
| 2533 | ;;; [This notation has been neglected in many recent routines.] | 2519 | ;; [This notation has been neglected in many recent routines.] |
| 2534 | 2520 | ||
| 2535 | (defvar math-eval-rules-cache) | 2521 | (defvar math-eval-rules-cache) |
| 2536 | (defvar math-eval-rules-cache-other) | 2522 | (defvar math-eval-rules-cache-other) |
| @@ -2662,7 +2648,7 @@ largest Emacs integer.") | |||
| 2662 | 2648 | ||
| 2663 | 2649 | ||
| 2664 | 2650 | ||
| 2665 | ;;; True if A is a floating-point real or complex number. [P x] [Public] | 2651 | ;; True if A is a floating-point real or complex number. [P x] [Public] |
| 2666 | (defun math-floatp (a) | 2652 | (defun math-floatp (a) |
| 2667 | (cond ((eq (car-safe a) 'float) t) | 2653 | (cond ((eq (car-safe a) 'float) t) |
| 2668 | ((memq (car-safe a) '(cplx polar mod sdev intv)) | 2654 | ((memq (car-safe a) '(cplx polar mod sdev intv)) |
| @@ -2674,7 +2660,7 @@ largest Emacs integer.") | |||
| 2674 | 2660 | ||
| 2675 | 2661 | ||
| 2676 | 2662 | ||
| 2677 | ;;; Verify that A is a complete object and return A. [x x] [Public] | 2663 | ;; Verify that A is a complete object and return A. [x x] [Public] |
| 2678 | (defun math-check-complete (a) | 2664 | (defun math-check-complete (a) |
| 2679 | (cond ((integerp a) a) | 2665 | (cond ((integerp a) a) |
| 2680 | ((eq (car-safe a) 'incomplete) | 2666 | ((eq (car-safe a) 'incomplete) |
| @@ -2684,7 +2670,7 @@ largest Emacs integer.") | |||
| 2684 | 2670 | ||
| 2685 | 2671 | ||
| 2686 | 2672 | ||
| 2687 | ;;; Coerce integer A to be a bignum. [B S] | 2673 | ;; Coerce integer A to be a bignum. [B S] |
| 2688 | (defun math-bignum (a) | 2674 | (defun math-bignum (a) |
| 2689 | (if (>= a 0) | 2675 | (if (>= a 0) |
| 2690 | (cons 'bigpos (math-bignum-big a)) | 2676 | (cons 'bigpos (math-bignum-big a)) |
| @@ -2697,7 +2683,7 @@ largest Emacs integer.") | |||
| 2697 | (math-bignum-big (/ a math-bignum-digit-size))))) | 2683 | (math-bignum-big (/ a math-bignum-digit-size))))) |
| 2698 | 2684 | ||
| 2699 | 2685 | ||
| 2700 | ;;; Build a normalized floating-point number. [F I S] | 2686 | ;; Build a normalized floating-point number. [F I S] |
| 2701 | (defun math-make-float (mant exp) | 2687 | (defun math-make-float (mant exp) |
| 2702 | (if (eq mant 0) | 2688 | (if (eq mant 0) |
| 2703 | '(float 0 0) | 2689 | '(float 0 0) |