(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
;;; calc-macs.el --- important macros for Calc
|
|
|
|
|
2005-07-14 20:05:30 +00:00
|
|
|
;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
|
2007-01-21 02:48:43 +00:00
|
|
|
;; 2005, 2006, 2007 Free Software Foundation, Inc.
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
|
|
|
|
;; Author: David Gillespie <daveg@synaptics.com>
|
2007-04-23 21:30:42 +00:00
|
|
|
;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
|
2001-11-06 18:59:06 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2007-03-19 20:59:53 +00:00
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2007-07-25 03:51:22 +00:00
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
2007-03-19 20:59:53 +00:00
|
|
|
;; any later version.
|
|
|
|
|
2001-11-06 18:59:06 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2007-03-19 20:59:53 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2001-11-06 18:59:06 +00:00
|
|
|
|
|
|
|
(defmacro calc-wrapper (&rest body)
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
`(calc-do (function (lambda ()
|
|
|
|
,@body))))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
|
|
|
(defmacro calc-slow-wrapper (&rest body)
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
`(calc-do
|
2001-11-21 06:24:04 +00:00
|
|
|
(function (lambda () ,@body)) (point)))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
(defmacro math-showing-full-precision (form)
|
|
|
|
`(let ((calc-float-format calc-full-float-format))
|
|
|
|
,form))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
|
|
|
(defmacro math-with-extra-prec (delta &rest body)
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
`(math-normalize
|
|
|
|
(let ((calc-internal-prec (+ calc-internal-prec ,delta)))
|
|
|
|
,@body)))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
(defmacro math-working (msg arg) ; [Public]
|
|
|
|
`(if (eq calc-display-working-message 'lots)
|
|
|
|
(math-do-working ,msg ,arg)))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
2002-02-18 20:05:49 +00:00
|
|
|
(defmacro calc-with-default-simplification (&rest body)
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
`(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
|
|
|
|
calc-simplify-mode)))
|
|
|
|
,@body))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
(defmacro calc-with-trail-buffer (&rest body)
|
|
|
|
`(let ((save-buf (current-buffer))
|
|
|
|
(calc-command-flags nil))
|
|
|
|
(with-current-buffer (calc-trail-display t)
|
|
|
|
(progn
|
|
|
|
(goto-char calc-trail-pointer)
|
|
|
|
,@body))))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
;;; Faster in-line version zerop, normalized values only.
|
|
|
|
(defsubst Math-zerop (a) ; [P N]
|
|
|
|
(if (consp a)
|
|
|
|
(and (not (memq (car a) '(bigpos bigneg)))
|
|
|
|
(if (eq (car a) 'float)
|
|
|
|
(eq (nth 1 a) 0)
|
|
|
|
(math-zerop a)))
|
|
|
|
(eq a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-integer-negp (a)
|
|
|
|
(if (consp a)
|
|
|
|
(eq (car a) 'bigneg)
|
|
|
|
(< a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-integer-posp (a)
|
|
|
|
(if (consp a)
|
|
|
|
(eq (car a) 'bigpos)
|
|
|
|
(> a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-negp (a)
|
|
|
|
(if (consp a)
|
|
|
|
(or (eq (car a) 'bigneg)
|
|
|
|
(and (not (eq (car a) 'bigpos))
|
|
|
|
(if (memq (car a) '(frac float))
|
|
|
|
(Math-integer-negp (nth 1 a))
|
|
|
|
(math-negp a))))
|
|
|
|
(< a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-looks-negp (a) ; [P x] [Public]
|
|
|
|
(or (Math-negp a)
|
|
|
|
(and (consp a) (or (eq (car a) 'neg)
|
|
|
|
(and (memq (car a) '(* /))
|
|
|
|
(or (math-looks-negp (nth 1 a))
|
|
|
|
(math-looks-negp (nth 2 a))))))))
|
|
|
|
|
|
|
|
(defsubst Math-posp (a)
|
|
|
|
(if (consp a)
|
|
|
|
(or (eq (car a) 'bigpos)
|
|
|
|
(and (not (eq (car a) 'bigneg))
|
|
|
|
(if (memq (car a) '(frac float))
|
|
|
|
(Math-integer-posp (nth 1 a))
|
|
|
|
(math-posp a))))
|
|
|
|
(> a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-integerp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg))))
|
|
|
|
|
|
|
|
(defsubst Math-natnump (a)
|
|
|
|
(if (consp a)
|
|
|
|
(eq (car a) 'bigpos)
|
|
|
|
(>= a 0)))
|
|
|
|
|
|
|
|
(defsubst Math-ratp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac))))
|
|
|
|
|
|
|
|
(defsubst Math-realp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac float))))
|
|
|
|
|
|
|
|
(defsubst Math-anglep (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac float hms))))
|
|
|
|
|
|
|
|
(defsubst Math-numberp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac float cplx polar))))
|
|
|
|
|
|
|
|
(defsubst Math-scalarp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac float cplx polar hms))))
|
|
|
|
|
|
|
|
(defsubst Math-vectorp (a)
|
|
|
|
(and (consp a) (eq (car a) 'vec)))
|
|
|
|
|
|
|
|
(defsubst Math-messy-integerp (a)
|
|
|
|
(and (consp a)
|
|
|
|
(eq (car a) 'float)
|
|
|
|
(>= (nth 2 a) 0)))
|
|
|
|
|
|
|
|
(defsubst Math-objectp (a) ; [Public]
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a)
|
|
|
|
'(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
|
|
|
|
|
|
|
|
(defsubst Math-objvecp (a) ; [Public]
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a)
|
|
|
|
'(bigpos bigneg frac float cplx polar hms date
|
|
|
|
sdev intv mod vec))))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
(calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
Change all toplevel `setq' forms to `defvar' forms, and move them
before their first use. Use `when', `unless'. Remove trailing
periods from error forms. Add description and headers suggested by
Emacs Lisp coding conventions.
2001-11-19 07:35:49 +00:00
|
|
|
;;; Compute the negative of A. [O O; o o] [Public]
|
|
|
|
(defsubst Math-integer-neg (a)
|
|
|
|
(if (consp a)
|
|
|
|
(if (eq (car a) 'bigpos)
|
|
|
|
(cons 'bigneg (cdr a))
|
|
|
|
(cons 'bigpos (cdr a)))
|
|
|
|
(- a)))
|
|
|
|
|
|
|
|
(defsubst Math-equal (a b)
|
|
|
|
(= (math-compare a b) 0))
|
|
|
|
|
|
|
|
(defsubst Math-lessp (a b)
|
|
|
|
(= (math-compare a b) -1))
|
|
|
|
|
|
|
|
(defsubst Math-primp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg frac float cplx polar
|
|
|
|
hms date mod var))))
|
|
|
|
|
|
|
|
(defsubst Math-num-integerp (a)
|
|
|
|
(or (not (consp a))
|
|
|
|
(memq (car a) '(bigpos bigneg))
|
|
|
|
(and (eq (car a) 'float)
|
|
|
|
(>= (nth 2 a) 0))))
|
|
|
|
|
|
|
|
(defsubst Math-bignum-test (a) ; [B N; B s; b b]
|
|
|
|
(if (consp a)
|
|
|
|
a
|
|
|
|
(math-bignum a)))
|
|
|
|
|
|
|
|
(defsubst Math-equal-int (a b)
|
|
|
|
(or (eq a b)
|
|
|
|
(and (consp a)
|
|
|
|
(eq (car a) 'float)
|
|
|
|
(eq (nth 1 a) b)
|
|
|
|
(= (nth 2 a) 0))))
|
|
|
|
|
|
|
|
(defsubst Math-natnum-lessp (a b)
|
|
|
|
(if (consp a)
|
|
|
|
(and (consp b)
|
|
|
|
(= (math-compare-bignum (cdr a) (cdr b)) -1))
|
|
|
|
(or (consp b)
|
|
|
|
(< a b))))
|
2001-11-06 18:59:06 +00:00
|
|
|
|
2004-11-29 05:56:56 +00:00
|
|
|
(provide 'calc-macs)
|
|
|
|
|
2003-09-01 15:45:59 +00:00
|
|
|
;;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
|
2001-11-14 09:09:09 +00:00
|
|
|
;;; calc-macs.el ends here
|