aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2009-11-15 23:55:53 +0000
committerJay Belanger2009-11-15 23:55:53 +0000
commit7d08336e25cd0ad15b24c0670d3f00b876b69140 (patch)
treeac768152d1bbfe44453f7497b0ae69e35900001d
parent4cf1d7e39cfd52b756005bafdbeeaa49109887ef (diff)
downloademacs-7d08336e25cd0ad15b24c0670d3f00b876b69140.tar.gz
emacs-7d08336e25cd0ad15b24c0670d3f00b876b69140.zip
(math-2-word-size, math-half-2-word-size, calc-complement-signed-mode):
new variables. (calc-set-mode-line): Add indicator for twos-complements. (math-format-number): Format twos-complement notation.
-rw-r--r--lisp/calc/calc.el32
1 files changed, 31 insertions, 1 deletions
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index d061de9f87a..e9a09ad054a 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -153,6 +153,7 @@
153(declare-function calcFunc-unixtime "calc-forms" (date &optional zone)) 153(declare-function calcFunc-unixtime "calc-forms" (date &optional zone))
154(declare-function math-parse-date "calc-forms" (math-pd-str)) 154(declare-function math-parse-date "calc-forms" (math-pd-str))
155(declare-function math-lessp "calc-ext" (a b)) 155(declare-function math-lessp "calc-ext" (a b))
156(declare-function math-compare "calc-ext" (a b))
156(declare-function calc-embedded-finish-command "calc-embed" ()) 157(declare-function calc-embedded-finish-command "calc-embed" ())
157(declare-function calc-embedded-select-buffer "calc-embed" ()) 158(declare-function calc-embedded-select-buffer "calc-embed" ())
158(declare-function calc-embedded-mode-line-change "calc-embed" ()) 159(declare-function calc-embedded-mode-line-change "calc-embed" ())
@@ -207,6 +208,7 @@
207(declare-function math-adjust-fraction "calc-ext" (a)) 208(declare-function math-adjust-fraction "calc-ext" (a))
208(declare-function math-format-binary "calc-bin" (a)) 209(declare-function math-format-binary "calc-bin" (a))
209(declare-function math-format-radix "calc-bin" (a)) 210(declare-function math-format-radix "calc-bin" (a))
211(declare-function math-format-complement-signed "calc-bin" (a))
210(declare-function math-group-float "calc-ext" (str)) 212(declare-function math-group-float "calc-ext" (str))
211(declare-function math-mod "calc-misc" (a b)) 213(declare-function math-mod "calc-misc" (a b))
212(declare-function math-format-number-fancy "calc-ext" (a prec)) 214(declare-function math-format-number-fancy "calc-ext" (a prec))
@@ -688,6 +690,10 @@ If `sqmatrix', variables are assumed to be square matrices of an unspecified siz
688If `scalar', variables are assumed to be scalar-valued. 690If `scalar', variables are assumed to be scalar-valued.
689If nil, symbolic math routines make no assumptions about variables.") 691If nil, symbolic math routines make no assumptions about variables.")
690 692
693(defcalcmodevar calc-complement-signed-mode nil
694 "If non-nil, display integers in complement signed mode.")
695
696
691(defcalcmodevar calc-shift-prefix nil 697(defcalcmodevar calc-shift-prefix nil
692 "If non-nil, shifted letter keys are prefix keys rather than normal meanings.") 698 "If non-nil, shifted letter keys are prefix keys rather than normal meanings.")
693 699
@@ -1704,6 +1710,7 @@ See calc-keypad for details."
1704 ((= calc-number-radix 8) "Oct ") 1710 ((= calc-number-radix 8) "Oct ")
1705 ((= calc-number-radix 16) "Hex ") 1711 ((= calc-number-radix 16) "Hex ")
1706 (t (format "Radix%d " calc-number-radix))) 1712 (t (format "Radix%d " calc-number-radix)))
1713 (if calc-complement-signed-mode "CompSign " "")
1707 (if calc-leading-zeros "Zero " "") 1714 (if calc-leading-zeros "Zero " "")
1708 (cond ((null calc-language) "") 1715 (cond ((null calc-language) "")
1709 ((get calc-language 'math-lang-name) 1716 ((get calc-language 'math-lang-name)
@@ -2350,7 +2357,7 @@ See calc-keypad for details."
2350 (insert "mod ")))) 2357 (insert "mod "))))
2351 (t 2358 (t
2352 (insert (char-to-string last-command-event)) 2359 (insert (char-to-string last-command-event))
2353 (if (or (and (calc-minibuffer-contains "[-+]?\\(.*\\+/- *\\|.*mod *\\)?\\([0-9][0-9]?\\)#[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\)?\\|.[0-9a-zA-Z]*\\(e[-+]?[0-9]*\\)?\\)?\\'") 2360 (if (or (and (calc-minibuffer-contains "[-+]?\\(.*\\+/- *\\|.*mod *\\)?\\([0-9][0-9]?\\)#[#&]?[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\)?\\|.[0-9a-zA-Z]*\\(e[-+]?[0-9]*\\)?\\)?\\'")
2354 (let ((radix (string-to-number 2361 (let ((radix (string-to-number
2355 (buffer-substring 2362 (buffer-substring
2356 (match-beginning 2) (match-end 2))))) 2363 (match-beginning 2) (match-end 2)))))
@@ -3382,9 +3389,24 @@ largest Emacs integer.")
3382 3389
3383 3390
3384;;; Format a number as a string. 3391;;; Format a number as a string.
3392(defvar math-half-2-word-size)
3385(defun math-format-number (a &optional prec) ; [X N] [Public] 3393(defun math-format-number (a &optional prec) ; [X N] [Public]
3386 (cond 3394 (cond
3387 ((eq calc-display-raw t) (format "%s" a)) 3395 ((eq calc-display-raw t) (format "%s" a))
3396 ((and calc-complement-signed-mode
3397 math-radix-explicit-format
3398 (Math-integerp a)
3399 (or (eq a 0)
3400 (and (Math-integer-posp a)
3401 (Math-lessp a math-half-2-word-size))
3402 (and (Math-integer-negp a)
3403 (require 'calc-ext)
3404 (let ((comparison
3405 (math-compare (Math-integer-neg a) math-half-2-word-size)))
3406 (or (= comparison 0)
3407 (= comparison -1))))))
3408 (require 'calc-bin)
3409 (math-format-complement-signed a))
3388 ((and (nth 1 calc-frac-format) (Math-integerp a)) 3410 ((and (nth 1 calc-frac-format) (Math-integerp a))
3389 (require 'calc-ext) 3411 (require 'calc-ext)
3390 (math-format-number (math-adjust-fraction a))) 3412 (math-format-number (math-adjust-fraction a)))
@@ -3767,6 +3789,14 @@ See Info node `(calc)Defining Functions'."
3767 (setq unread-command-event nil) 3789 (setq unread-command-event nil)
3768 (setq unread-command-events nil))) 3790 (setq unread-command-events nil)))
3769 3791
3792(defcalcmodevar math-2-word-size
3793 (math-read-number-simple "4294967296")
3794 "Two to the power of `calc-word-size'.")
3795
3796(defcalcmodevar math-half-2-word-size
3797 (math-read-number-simple "2147483648")
3798 "One-half of two to the power of `calc-word-size'.")
3799
3770(when calc-always-load-extensions 3800(when calc-always-load-extensions
3771 (require 'calc-ext) 3801 (require 'calc-ext)
3772 (calc-load-everything)) 3802 (calc-load-everything))