;;; calculator.el --- a calculator for Emacs -*- lexical-binding: t -*-
-;; Copyright (C) 1998, 2000-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000-2016 Free Software Foundation, Inc.
;; Author: Eli Barzilay <eli@barzilay.org>
;; Keywords: tools, convenience
:group 'calculator)
(defcustom calculator-unary-style 'postfix
- "Value is either 'prefix or 'postfix.
+ "Value is either `prefix' or `postfix'.
This determines the default behavior of unary operators."
:type '(choice (const prefix) (const postfix))
:group 'calculator)
will be stored in that character's register.
For example, use this to define the golden ratio number:
- (setq calculator-user-registers '((?g . 1.61803398875)))
+ (setq calculator-user-registers \\='((?g . 1.61803398875)))
before you load calculator."
:type '(repeat (cons character number))
:set (lambda (_ val)
t as a prefix key:
(setq calculator-user-operators
- '((\"tf\" cl-to-fr (+ 32 (/ (* X 9) 5)) 1)
+ \\='((\"tf\" cl-to-fr (+ 32 (/ (* X 9) 5)) 1)
(\"tc\" fr-to-cl (/ (* (- X 32) 5) 9) 1)
(\"tp\" kg-to-lb (/ X 0.453592) 1)
(\"tk\" lb-to-kg (* X 0.453592) 1)
version of `X' and `F' for a recursive call. Here is a [very
inefficient] Fibonacci number calculation:
- (add-to-list 'calculator-user-operators
- '(\"F\" fib
+ (add-to-list \\='calculator-user-operators
+ \\='(\"F\" fib
(if (<= TX 1) 1 (+ (F (- TX 1)) (F (- TX 2))))))
Note that this will be either postfix or prefix, according to
9 (highest) (optional, defaults to 1);
It it possible have a unary prefix version of a binary operator if it
-comes later in this list. If the list begins with the symbol 'nobind,
+comes later in this list. If the list begins with the symbol `nobind',
then no key binding will take place -- this is only useful for
predefined keys.
"A table to convert input characters to corresponding radix symbols.")
(defvar calculator-output-radix nil
- "The mode for display, one of: nil (decimal), 'bin, 'oct or 'hex.")
+ "The mode for display, one of: nil (decimal), `bin', `oct' or `hex'.")
(defvar calculator-input-radix nil
- "The mode for input, one of: nil (decimal), 'bin, 'oct or 'hex.")
+ "The mode for input, one of: nil (decimal), `bin', `oct' or `hex'.")
(defvar calculator-deg nil
"Non-nil if trig functions operate on degrees instead of radians.")
[kp-5] [kp-6] [kp-7] [kp-8] [kp-9])
(calculator-op [kp-divide] [kp-multiply])
(calculator-decimal "." [kp-decimal])
- (calculator-exp "e")
+ (calculator-exp "e" "E")
(calculator-dec/deg-mode "D")
(calculator-set-register "s")
(calculator-get-register "g")
;; f is an expression
(let ((TX (and X (calculator-truncate X)))
(TY (and Y (calculator-truncate Y)))
- (DX (if (and X calculator-deg) (/ (* X pi) 180) X))
+ (DX (if (and X calculator-deg) (degrees-to-radians X) X))
(L calculator-saved-list)
(fF `(calculator-funcall ',f x y))
- (fD `(if calculator-deg (/ (* x 180) float-pi) x)))
+ (fD `(if calculator-deg (* radians-to-degrees x) x)))
(eval `(cl-flet ((F (&optional x y) ,fF) (D (x) ,fD))
(let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L))
,f))
"Last char (or event or event sequence) that was read.
Use KEYS if given, otherwise use `this-command-keys'."
(let ((inp (or keys (this-command-keys))))
- (if (or (stringp inp) (not (arrayp inp)))
+ (if (or (stringp inp) (not (arrayp inp)) (member inp '([f1] [help])))
inp
;; Translates kp-x to x and [tries to] create a string to lookup
;; operators; assume all symbols are translatable via
+ - * / \\(div) %(rem) _(-X,postfix) ;(1/X,postfix) ^(exp) L(og)
Q(sqrt) !(fact) S(in) C(os) T(an) |(or) #(xor) &(and) ~(not)
* >/< repeats last binary operation with its 2nd (1st) arg as postfix op
-* I inverses next trig function * '/\"/{} - display/display args
+* I inverses next trig function * \\='/\"/{} - display/display args
* D - switch to all-decimal, or toggle deg/rad mode
* B/O/H/X - binary/octal/hex mode for i/o (X is a shortcut for H)
* i/o - prefix for d/b/o/x - set only input/output modes