comparison lisp/calc/calc-bin.el @ 106137:0e720bab47c6

(math-format-twos-complement): Renamed from math-format-complement-signed. (calc-radix): Rename `calc-complement-signed-mode' to `calc-twos-complement-mode'. (calc-octal-radix, calc-hex-radix): Add an argument for two's complement.
author Jay Belanger <jay.p.belanger@gmail.com>
date Fri, 20 Nov 2009 00:55:53 +0000
parents c3e7e20da11d
children 3875adeabec5
comparison
equal deleted inserted replaced
106136:72136220d7f5 106137:0e720bab47c6
157 (setq math-2-word-size (math-power-of-2 (math-abs n))) 157 (setq math-2-word-size (math-power-of-2 (math-abs n)))
158 (setq math-half-2-word-size (math-power-of-2 (1- (math-abs n)))) 158 (setq math-half-2-word-size (math-power-of-2 (1- (math-abs n))))
159 (calc-do-refresh) 159 (calc-do-refresh)
160 (calc-refresh-evaltos) 160 (calc-refresh-evaltos)
161 (if (< n 0) 161 (if (< n 0)
162 (message "Binary word size is %d bits (2's complement)" (- n)) 162 (message "Binary word size is %d bits (two's complement)" (- n))
163 (message "Binary word size is %d bits" n)))) 163 (message "Binary word size is %d bits" n))))
164 164
165 165
166 166
167 167
172 (interactive "NDisplay radix (2-36): ") 172 (interactive "NDisplay radix (2-36): ")
173 (calc-wrapper 173 (calc-wrapper
174 (if (and (>= n 2) (<= n 36)) 174 (if (and (>= n 2) (<= n 36))
175 (progn 175 (progn
176 (calc-change-mode 176 (calc-change-mode
177 (list 'calc-number-radix 'calc-complement-signed-mode) 177 (list 'calc-number-radix 'calc-twos-complement-mode)
178 (list n (and (= n 2) arg)) t) 178 (list n (and (or (= n 2) (= n 8) (= n 16)) arg)) t)
179 ;; also change global value so minibuffer sees it 179 ;; also change global value so minibuffer sees it
180 (setq-default calc-number-radix calc-number-radix)) 180 (setq-default calc-number-radix calc-number-radix))
181 (setq n calc-number-radix)) 181 (setq n calc-number-radix))
182 (if calc-complement-signed-mode 182 (if calc-twos-complement-mode
183 (message "Number radix is %d, complement signed mode is on." n) 183 (message "Number radix is %d, two's complement mode is on." n)
184 (message "Number radix is %d" n)))) 184 (message "Number radix is %d" n))))
185 185
186 (defun calc-decimal-radix () 186 (defun calc-decimal-radix ()
187 (interactive) 187 (interactive)
188 (calc-radix 10)) 188 (calc-radix 10))
189 189
190 (defun calc-binary-radix (&optional arg) 190 (defun calc-binary-radix (&optional arg)
191 (interactive "P") 191 (interactive "P")
192 (calc-radix 2 arg)) 192 (calc-radix 2 arg))
193 193
194 (defun calc-octal-radix () 194 (defun calc-octal-radix (&optional arg)
195 (interactive) 195 (interactive "P")
196 (calc-radix 8)) 196 (calc-radix 8 arg))
197 197
198 (defun calc-hex-radix () 198 (defun calc-hex-radix (&optional arg)
199 (interactive) 199 (interactive "P")
200 (calc-radix 16)) 200 (calc-radix 16 arg))
201 201
202 (defun calc-leading-zeros (n) 202 (defun calc-leading-zeros (n)
203 (interactive "P") 203 (interactive "P")
204 (calc-wrapper 204 (calc-wrapper
205 (if (calc-change-mode 'calc-leading-zeros n t t) 205 (if (calc-change-mode 'calc-leading-zeros n t t)
818 '(float 1 0) 818 '(float 1 0)
819 (math-float 819 (math-float
820 calc-number-radix)))))) 820 calc-number-radix))))))
821 math-radix-float-cache)))))))) 821 math-radix-float-cache))))))))
822 822
823 ;;; Complement signed mode 823 ;;; Two's complement mode
824 824
825 (defun math-format-complement-signed (a) 825 (defun math-format-twos-complement (a)
826 "Format an integer in complement signed mode." 826 "Format an integer in complement signed mode."
827 (let* (;(calc-leading-zeros t) 827 (let* (;(calc-leading-zeros t)
828 (overflow nil) 828 (overflow nil)
829 (negative nil) 829 (negative nil)
830 (num 830 (num