;;; calc-bin.el --- binary functions for Calc
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2013 Free Software Foundation, Inc.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
(calc-do-refresh)
(calc-refresh-evaltos)
(if (< n 0)
- (message "Binary word size is %d bits (2's complement)" (- n))
+ (message "Binary word size is %d bits (two's complement)" (- n))
(message "Binary word size is %d bits" n))))
(if (and (>= n 2) (<= n 36))
(progn
(calc-change-mode
- (list 'calc-number-radix 'calc-complement-signed-mode)
- (list n (and (= n 2) arg)) t)
+ (list 'calc-number-radix 'calc-twos-complement-mode)
+ (list n (or arg (calc-is-option))) t)
;; also change global value so minibuffer sees it
(setq-default calc-number-radix calc-number-radix))
(setq n calc-number-radix))
- (if calc-complement-signed-mode
- (message "Number radix is %d, complement signed mode is on." n)
+ (if calc-twos-complement-mode
+ (message "Number radix is %d, two's complement mode is on." n)
(message "Number radix is %d" n))))
(defun calc-decimal-radix ()
(interactive "P")
(calc-radix 2 arg))
-(defun calc-octal-radix ()
- (interactive)
- (calc-radix 8))
+(defun calc-octal-radix (&optional arg)
+ (interactive "P")
+ (calc-radix 8 arg))
-(defun calc-hex-radix ()
- (interactive)
- (calc-radix 16))
+(defun calc-hex-radix (&optional arg)
+ (interactive "P")
+ (calc-radix 16 arg))
(defun calc-leading-zeros (n)
(interactive "P")
(if (eq (car-safe b) 'mod)
(if (equal mod (nth 2 b))
(setq b (nth 1 b))
- (math-reject-arg b "*Inconsistent modulos"))))
+ (math-reject-arg b "*Inconsistent modulus"))))
(setq mod (nth 2 b)
b (nth 1 b)))
(if (Math-messy-integerp mod)
(if w
(if (/= w bits)
(calc-record-why
- "*Warning: Modulo inconsistent with word size"))
+ "*Warning: Modulus inconsistent with word size"))
(setq w bits))
- (calc-record-why "*Warning: Modulo is not a power of 2"))
+ (calc-record-why "*Warning: Modulus is not a power of 2"))
(math-make-mod (if b
(funcall f a b w)
(funcall f a w))
calc-number-radix))))))
math-radix-float-cache))))))))
-;;; Complement signed mode
+;;; Two's complement mode
-(defun math-format-complement-signed (a)
- "Format an integer in complement signed mode."
+(defun math-format-twos-complement (a)
+ "Format an integer in two's complement mode."
(let* (;(calc-leading-zeros t)
(overflow nil)
(negative nil)
(len (length num)))
(if (< len digs)
(setq num (concat (make-string (- digs len) ?0) num))))
+ (when calc-group-digits
+ (setq num (math-group-float num)))
(concat
(number-to-string calc-number-radix)
"##"
num)))
-(defun math-symclip (a)
- "Reduce A to between -2^(w-1) and 2^(w-1)-1."
- (if (not (Math-num-integerp a))
- (math-reject-arg a 'integerp)
- (if (and (Math-lessp a math-half-2-word-size)
- (let
- ((comparison (math-compare (Math-integer-neg a) math-half-2-word-size)))
- (or (= comparison 0)
- (= comparison -1))))
- a
- (let ((smalla (math-clip a)))
- (if (Math-lessp smalla math-half-2-word-size)
- smalla
- (math-sub smalla math-2-word-size))))))
-
-(defalias 'calcFunc-symclip 'math-symclip)
-
-(defun calc-symclip (n)
- "Reduce N to between -2^(w-1) and 2^(w-1)-1."
- (interactive "P")
- (calc-slow-wrapper
- (calc-enter-result 1 "sclp"
- (append '(calcFunc-symclip)
- (calc-top-list-n 1)
- (and n (list (prefix-numeric-value n)))))))
-
-
(provide 'calc-bin)
-;; arch-tag: f6dba7bc-53b2-41ae-919c-c266ab0ca8b3
;;; calc-bin.el ends here