emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/lisp/calc calc.el


From: Jay Belanger
Subject: [Emacs-diffs] emacs/lisp/calc calc.el
Date: Sun, 15 Nov 2009 23:55:53 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Jay Belanger <jpb>      09/11/15 23:55:53

Modified files:
        lisp/calc      : calc.el 

Log message:
        (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.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/calc/calc.el?cvsroot=emacs&r1=1.136&r2=1.137

Patches:
Index: calc.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/calc/calc.el,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -b -r1.136 -r1.137
--- calc.el     28 Oct 2009 18:35:37 -0000      1.136
+++ calc.el     15 Nov 2009 23:55:53 -0000      1.137
@@ -153,6 +153,7 @@
 (declare-function calcFunc-unixtime "calc-forms" (date &optional zone))
 (declare-function math-parse-date "calc-forms" (math-pd-str))
 (declare-function math-lessp "calc-ext" (a b))
+(declare-function math-compare "calc-ext" (a b))
 (declare-function calc-embedded-finish-command "calc-embed" ())
 (declare-function calc-embedded-select-buffer "calc-embed" ())
 (declare-function calc-embedded-mode-line-change "calc-embed" ())
@@ -207,6 +208,7 @@
 (declare-function math-adjust-fraction "calc-ext" (a))
 (declare-function math-format-binary "calc-bin" (a))
 (declare-function math-format-radix "calc-bin" (a))
+(declare-function math-format-complement-signed "calc-bin" (a))
 (declare-function math-group-float "calc-ext" (str))
 (declare-function math-mod "calc-misc" (a b))
 (declare-function math-format-number-fancy "calc-ext" (a prec))
@@ -688,6 +690,10 @@
 If `scalar', variables are assumed to be scalar-valued.
 If nil, symbolic math routines make no assumptions about variables.")
 
+(defcalcmodevar calc-complement-signed-mode nil
+  "If non-nil, display integers in complement signed mode.")
+
+
 (defcalcmodevar calc-shift-prefix nil
   "If non-nil, shifted letter keys are prefix keys rather than normal 
meanings.")
 
@@ -1704,6 +1710,7 @@
                           ((= calc-number-radix 8) "Oct ")
                           ((= calc-number-radix 16) "Hex ")
                           (t (format "Radix%d " calc-number-radix)))
+                     (if calc-complement-signed-mode "CompSign " "")
                     (if calc-leading-zeros "Zero " "")
                     (cond ((null calc-language) "")
                            ((get calc-language 'math-lang-name)
@@ -2350,7 +2357,7 @@
          (insert "mod "))))
      (t
       (insert (char-to-string last-command-event))
-      (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]*\\)?\\)?\\'")
+      (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]*\\)?\\)?\\'")
                   (let ((radix (string-to-number
                                 (buffer-substring
                                  (match-beginning 2) (match-end 2)))))
@@ -3382,9 +3389,24 @@
 
 
 ;;; Format a number as a string.
+(defvar math-half-2-word-size)
 (defun math-format-number (a &optional prec)   ; [X N]   [Public]
   (cond
    ((eq calc-display-raw t) (format "%s" a))
+   ((and calc-complement-signed-mode
+         math-radix-explicit-format
+         (Math-integerp a)
+         (or (eq a 0)
+             (and (Math-integer-posp a)
+                  (Math-lessp a math-half-2-word-size))
+             (and (Math-integer-negp a)
+                  (require 'calc-ext)
+                  (let ((comparison 
+                         (math-compare (Math-integer-neg a) 
math-half-2-word-size)))
+                    (or (= comparison 0)
+                        (= comparison -1))))))
+    (require 'calc-bin)
+    (math-format-complement-signed a))
    ((and (nth 1 calc-frac-format) (Math-integerp a))
     (require 'calc-ext)
     (math-format-number (math-adjust-fraction a)))
@@ -3767,6 +3789,14 @@
       (setq unread-command-event nil)
     (setq unread-command-events nil)))
 
+(defcalcmodevar math-2-word-size 
+  (math-read-number-simple "4294967296")
+  "Two to the power of `calc-word-size'.")
+
+(defcalcmodevar math-half-2-word-size
+  (math-read-number-simple "2147483648")
+  "One-half of two to the power of `calc-word-size'.")
+
 (when calc-always-load-extensions
   (require 'calc-ext)
   (calc-load-everything))




reply via email to

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