1 |
;; Calculator for GNU Emacs, part II [calc-bin.el] |
;;; calc-bin.el --- binary functions for Calc |
2 |
|
|
3 |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
4 |
;; Written by Dave Gillespie, daveg@synaptics.com. |
|
5 |
|
;; Author: David Gillespie <daveg@synaptics.com> |
6 |
|
;; Maintainer: Colin Walters <walters@debian.org> |
7 |
|
|
8 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
9 |
|
|
22 |
;; file named COPYING. Among other things, the copyright notice |
;; file named COPYING. Among other things, the copyright notice |
23 |
;; and this notice must be preserved on all copies. |
;; and this notice must be preserved on all copies. |
24 |
|
|
25 |
|
;;; Commentary: |
26 |
|
|
27 |
|
;;; Code: |
28 |
|
|
29 |
;; This file is autoloaded from calc-ext.el. |
;; This file is autoloaded from calc-ext.el. |
30 |
(require 'calc-ext) |
(require 'calc-ext) |
148 |
(list n (math-power-of-2 (math-abs n))) |
(list n (math-power-of-2 (math-abs n))) |
149 |
calc-leading-zeros))) |
calc-leading-zeros))) |
150 |
(if (< n 0) |
(if (< n 0) |
151 |
(message "Binary word size is %d bits (2's complement)." (- n)) |
(message "Binary word size is %d bits (2's complement)" (- n)) |
152 |
(message "Binary word size is %d bits." n)))) |
(message "Binary word size is %d bits" n)))) |
153 |
|
|
154 |
|
|
155 |
|
|
166 |
;; also change global value so minibuffer sees it |
;; also change global value so minibuffer sees it |
167 |
(setq-default calc-number-radix calc-number-radix)) |
(setq-default calc-number-radix calc-number-radix)) |
168 |
(setq n calc-number-radix)) |
(setq n calc-number-radix)) |
169 |
(message "Number radix is %d." n))) |
(message "Number radix is %d" n))) |
170 |
|
|
171 |
(defun calc-decimal-radix () |
(defun calc-decimal-radix () |
172 |
(interactive) |
(interactive) |
188 |
(interactive "P") |
(interactive "P") |
189 |
(calc-wrapper |
(calc-wrapper |
190 |
(if (calc-change-mode 'calc-leading-zeros n t t) |
(if (calc-change-mode 'calc-leading-zeros n t t) |
191 |
(message "Zero-padding integers to %d digits (assuming radix %d)." |
(message "Zero-padding integers to %d digits (assuming radix %d)" |
192 |
(let* ((calc-internal-prec 6)) |
(let* ((calc-internal-prec 6)) |
193 |
(math-compute-max-digits (math-abs calc-word-size) |
(math-compute-max-digits (math-abs calc-word-size) |
194 |
calc-number-radix)) |
calc-number-radix)) |
195 |
calc-number-radix) |
calc-number-radix) |
196 |
(message "Omitting leading zeros on integers.")))) |
(message "Omitting leading zeros on integers")))) |
197 |
|
|
198 |
|
|
199 |
(defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024)) |
(defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024)) |
567 |
"K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" |
"K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" |
568 |
"U" "V" "W" "X" "Y" "Z"]) |
"U" "V" "W" "X" "Y" "Z"]) |
569 |
|
|
570 |
|
(defsubst math-format-radix-digit (a) ; [X D] |
571 |
|
(aref math-radix-digits a)) |
572 |
|
|
573 |
(defun math-format-radix (a) ; [X S] |
(defun math-format-radix (a) ; [X S] |
574 |
(if (< a calc-number-radix) |
(if (< a calc-number-radix) |
575 |
(if (< a 0) |
(if (< a 0) |
758 |
(format "%se%s" str estr))))))) |
(format "%se%s" str estr))))))) |
759 |
str)) |
str)) |
760 |
|
|
761 |
|
(defvar math-radix-digits-cache nil) |
762 |
|
|
763 |
(defun math-convert-radix-digits (n &optional to-dec) |
(defun math-convert-radix-digits (n &optional to-dec) |
764 |
(let ((key (cons n (cons to-dec calc-number-radix)))) |
(let ((key (cons n (cons to-dec calc-number-radix)))) |
765 |
(or (cdr (assoc key math-radix-digits-cache)) |
(or (cdr (assoc key math-radix-digits-cache)) |
772 |
(math-div n log)))) |
(math-div n log)))) |
773 |
math-radix-digits-cache)))))))) |
math-radix-digits-cache)))))))) |
774 |
|
|
775 |
(setq math-radix-digits-cache nil) |
(defvar math-radix-float-cache-tag nil) |
776 |
|
|
777 |
(defun math-radix-float-power (n) |
(defun math-radix-float-power (n) |
778 |
(if (eq n 0) |
(if (eq n 0) |
802 |
calc-number-radix)))))) |
calc-number-radix)))))) |
803 |
math-radix-float-cache)))))))) |
math-radix-float-cache)))))))) |
804 |
|
|
|
(setq math-radix-float-cache-tag nil) |
|
805 |
|
|
806 |
;;; calc-bin.el ends here |
;;; calc-bin.el ends here |