Commit 136211a9 authored by Eli Zaretskii's avatar Eli Zaretskii

Initial import of Calc 2.02f.

parent 0ffbbdeb
This diff is collapsed.
# Makefile for "Calc", the GNU Emacs Calculator.
# Copyright (C) 1991, 1992, 1993 Free Software Foundation.
# Author: Dave Gillespie.
# Author's address: daveg@synaptics.com.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation (any version).
# This program is distributed in the hope that it will be useful,
# 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., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# To install Calc for private use, type `make'.
# To install Calc for public use, type `make install'.
# How to read a Makefile:
# The command `make target' looks for `target:' in the Makefile.
# First, any sub-targets after the `:' are made.
# Then, the Unix commands on the following lines are executed.
# `$(SYMBOL)' expands according to the `SYMBOL =' definition below.
# Programs.
EMACS = emacs
TEX = tex
TEXINDEX = texindex
MAKEINFO = makeinfo
MAKE = make
ECHO = @echo
REMOVE = -rm -f
# (The leading `@' tells "make" not to echo the command itself during make;
# The leading `-' tells "make" to keep going if the command fails.)
# Other macros.
EFLAGS = -batch
MAINT = -l calc-maint.elc
# Control whether intermediate files are kept.
PURGE = -rm -f
#PURGE = echo Not deleting:
# Do full Calc installation. (Note that `make' == `make all'.)
# These are written this way instead of `all: compile private info'
# to make the steps more explicit while the `make' is in progress.
all:
$(MAKE) compile
$(MAKE) private
$(MAKE) info
$(ECHO) "Calc is now installed."
install:
$(MAKE) compile
$(MAKE) public
$(MAKE) info
$(ECHO) "Calc is now installed."
# Compile Calc.
compile: maint
$(EMACS) $(EFLAGS) $(MAINT) -f calc-compile
# Add autoload and set-global-key commands to system default file.
public: maint
$(EMACS) $(EFLAGS) $(MAINT) -f calc-public-autoloads
# Add autoload and set-global-key commands to ~/.emacs file.
private: maint
$(EMACS) $(EFLAGS) $(MAINT) -f calc-private-autoloads
# Format the Calc manual for the Info system using makeinfo.
info: calc.info
calc.info: calc.texinfo
-$(MAKEINFO) calc.texinfo
$(ECHO) "Please ignore warnings for Copying, Getting Started, and Interactive Tutorial."
$(MAKE) texinfo
# Format the Calc manual for the Info system using texinfo.el.
# (Use this only if you do not have makeinfo.)
texinfo: calc.info-2
calc.info-2: calc.texinfo
$(EMACS) $(EFLAGS) calc.texinfo -f texinfo-format-buffer -f save-buffer
# Format the Calc manual as one printable volume using TeX.
tex:
$(REMOVE) calc.aux
$(TEX) calc.texinfo
$(TEXINDEX) calc.[cfkptv]?
$(TEX) calc.texinfo
$(PURGE) calc.cp calc.fn calc.pg calc.tp calc.vr
$(PURGE) calc.cps calc.fns calc.kys calc.pgs calc.tps calc.vrs
$(PURGE) calc.toc
# Note, calc.aux and calc.ky are left behind for the benefit of "make summary".
# Format the Calc manual as two printable volumes (Tutorial and Reference).
tex2: texsplit texvol1 texvol2
# Format the Calc Tutorial volume only.
textut: texsplit1 texvol1
# Format the Calc Reference volume only.
texref: texsplit2 texvol2
texsplit: maint
$(EMACS) $(EFLAGS) $(MAINT) calc.texinfo -f calc-split-manual
texsplit1: maint
$(EMACS) $(EFLAGS) $(MAINT) calc.texinfo -f calc-split-tutorial
texsplit2: maint
$(EMACS) $(EFLAGS) $(MAINT) calc.texinfo -f calc-split-reference
texvol1:
$(TEX) calctut.tex
$(TEXINDEX) calctut.??
$(TEX) calctut.tex
$(PURGE) calctut.tex calctut.?? calctut.??s calctut.aux calctut.toc
texvol2:
$(TEX) calcref.tex
$(TEXINDEX) calcref.??
$(TEX) calcref.tex
$(PURGE) calcref.tex calcref.?? calcref.??s calcref.aux calcref.toc
# Format the Calc summary separately using TeX.
summary: texsum
$(TEX) calcsum.tex
$(PURGE) calcsum.?? calcsum.aux calcsum.toc
texsum: maint
$(EMACS) $(EFLAGS) $(MAINT) calc.texinfo -f calc-split-summary
isummary: texisum
$(TEX) calcsum.tex
$(PURGE) calcsum.?? calcsum.aux calcsum.toc
texisum: maint
$(EMACS) $(EFLAGS) $(MAINT) calc.texinfo -f calc-inline-summary
# All this because "-l calc-maint" doesn't work.
maint: calc-maint.elc
calc-maint.elc: calc-maint.el
cp calc-maint.el calc-maint.elc
# Create an Emacs TAGS file
tags: TAGS
TAGS:
etags *.el
# Delete .elc files and other reconstructible files.
clean: clean.elc clean.info clean.tex
clean.elc:
$(REMOVE) calc-*.elc
$(REMOVE) macedit.elc
clean.info:
$(REMOVE) calc.info*
clean.tex:
$(REMOVE) calc.cp calc.fn calc.ky calc.pg calc.tp calc.vr
$(REMOVE) calc.cps calc.fns calc.kys calc.pgs calc.tps calc.vrs
$(REMOVE) calc.aux calc.log calc.toc calc.dvi
$(REMOVE) calcref.*
$(REMOVE) calctut.*
$(REMOVE) calcsum.*
This directory contains version 2.02c of Calc, an advanced desk
calculator for GNU Emacs.
"Calc" Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
Written and maintained by: Dave Gillespie
c/o Synaptics, Inc.
2698 Orchard Parkway
San Jose CA 95134
daveg@synaptics.com, uunet!synaptx!daveg
From the introduction to the manual:
"Calc" is an advanced calculator and mathematical tool that runs as
part of the GNU Emacs environment. Very roughly based on the HP-28/48
series of calculators, its many features include:
* Choice of algebraic or RPN (stack-based) entry of calculations.
* Arbitrary precision integers and floating-point numbers.
* Arithmetic on rational numbers, complex numbers (rectangular and
polar), error forms with standard deviations, open and closed
intervals, vectors and matrices, dates and times, infinities,
sets, quantities with units, and algebraic formulas.
* Mathematical operations such as logarithms and trigonometric functions.
* Programmer's features (bitwise operations, non-decimal numbers).
* Financial functions such as future value and internal rate of return.
* Number theoretical features such as prime factorization and
arithmetic modulo M for any M.
* Algebraic manipulation features, including symbolic calculus.
* Moving data to and from regular editing buffers.
* "Embedded mode" for manipulating Calc formulas and data directly
inside any editing buffer.
* Graphics using GNUPLOT, a versatile (and free) plotting program.
* Easy programming using keyboard macros, algebraic formulas,
algebraic rewrite rules, or extended Emacs Lisp.
To install Calc:
1. Type "uncompress calc-2.02.tar.Z"
2. Type "tar xvf calc-2.02.tar"
1,2. Alternatively: "zcat calc-2.02.tar.Z | tar xvf -"
3. Note that the Calc tar file now creates a "calc-2.02" subdirectory
of the current directory in which to place its files.
4. Follow the instructions in the file "INSTALL".
Calc is written entirely in Emacs Lisp, for maximum portability.
You do not need to recompile Emacs to install and use Calc.
You will need about six megabytes of disk space to install Calc
and its Info documentation.
See the file INSTALL for installation instructions. The instructions
may seem long, but on typical systems you will only need to follow the
steps shown in the first section.
Don't even try to run Calc in uncompiled (.el) form! It's far too slow.
I am anxious to hear about your experiences using Calc. Send mail to
"daveg@synaptics.com". A bug report is most useful if you include the
exact input and output that occurred, any modes in effect (such as the
current precision), and so on. If you find Calc is difficult to operate
in any way, or if you have other suggestions, don't hesitate to let me
know. If you find errors (including simple typos) in the manual, let
me know. Even if you find no bugs at all I would love to hear your
opinions.
The latest Calc tar files and patches are always available for anonymous
FTP on prep.ai.mit.edu.
Thanks,
-- Dave
Summary of changes to "Calc"
------- -- ------- -- ----
Version 2.02f:
* Fixed a bug which broke `I', `H', `K' prefix keys in recent Emacs.
* Fixed a bug in calc.texinfo which prevented "make tex2" from working.
* Updated `C-y' (calc-yank) to understand Emacs 19 generalized kill ring.
* Added a copy of "calccard.tex", the Calc quick reference card.
Version 2.02e:
* Fixed an installation bug caused by recent changes to `write-region'.
Version 2.02d:
* Fixed a minor installation problem with a Emacs 19.29 byte-compiler bug.
* Removed archaic "macedit" package (superseded by "edmacro").
Version 2.02c:
* Patch to port Calc to Lucid Emacs 19; still works with GNU 18 and GNU 19.
* Fixed a bug that broke `C-x C-c' after Calc graphics had been used.
Version 2.02b:
* Minor patch to port Calc to GNU Emacs 19. Will be superseded by Calc 3.00.
Version 2.02:
* Revamped the manual a bit; rearranged some sections.
* Added marginal notes for Key/Function Index refs in printed manual.
* Changed `M-# r' to deal more gracefully with blank lines.
* Made reductions like `V R +' and `M-# :' considerably faster.
* Improved parsing and display of cases like "[a + b]".
* Added `t +' and `t -' for doing business date arithmetic.
* Added "syntax tables," the opposite of compositions.
* Added another Rewrites Tutorial exercise.
* Added the "vmatches" function.
* Added the `Modes' variable and `m g' command.
* Improved `u s' to cancel, e.g., "11 mph hr / yd" to get a number.
* Added "quick units" commands "u 0" through "u 9".
* Moved `M-%' to calc.el to avoid autoloading problems.
* Added `M-=' during algebraic entry, acts like `RET ='.
* Made `LFD' prevent evaluation when finishing a calc-edit command.
* Changed calc-store commands to use `t .' mode for trail display.
* Improved integrator to understand forms involving "erf".
* Fixed parser to make sense of "[1....1e2]" input.
* Fixed FORTRAN parser to treat a(i,j) as a_i_j if a is declared matrix.
* Got rid of some version number stamps to reduce size of patches.
* Fixed a bug in defmath treating "<=" and ">=" predicates.
* Fixed a bug in which Calc crashed multiplying two date forms.
* Fixed a bug in line breaker that crashed for large, nested formulas.
* Fixed a bug using ` to edit string("foo").
* Fixed a bug where `M-# y' in Big mode copied stack level number.
* Fixed a bug where `g O' used wrong default directory, no completion.
* Fixed a bug where "foo_bar(i)" parsed in C mode but showed as foo#bar.
* Fixed several bugs where large calculations got "computation too long."
Version 2.01:
* Added percentage commands `M-%', `b %', and `c %'.
* Changed Big mode to force radix-10 in superscripts.
* Improved display of fractions in various language modes.
* Changed `a n' to work properly with equations and inequalities.
* The problem with cross references to Index nodes in TeX has been fixed.
* Fixed a bug where recursive esc-maps make calc-ext/-aent unloadable.
* Fixed a bug in `M-# k', then `OFF' right away, with fresh Emacs.
* Fixed a bug in which "S_i_j" was formatted wrong after `j s'.
* Fixed a bug in which `h k u c' positioned cursor on wrong line.
* Fixed a bug where `z ?' crashed if `z %' was defined.
* Fixed a bug in `j O' (calc-select-once-maybe).
* Fixed "make private" not to ask "Delete excess versions" and crash.
Version 2.00:
* First complete posting of Calc since 1.01.
* Most parts of Calc have seen changes since version 1.07. See
section "New for Calc 2.00" in the manual for a summary. In
the FTP version of the Calc distribution, the file README.prev
contains a detailed change history from 1.00 up to 2.00.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
;; Calculator for GNU Emacs, part II [calc-frac.el]
;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; This file is part of GNU Emacs.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU Emacs General Public
;; License for full details.
;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
;; This file is autoloaded from calc-ext.el.
(require 'calc-ext)
(require 'calc-macs)
(defun calc-Need-calc-frac () nil)
(defun calc-fdiv (arg)
(interactive "P")
(calc-slow-wrapper
(calc-binary-op ":" 'calcFunc-fdiv arg 1))
)
(defun calc-fraction (arg)
(interactive "P")
(calc-slow-wrapper
(let ((func (if (calc-is-hyperbolic) 'calcFunc-frac 'calcFunc-pfrac)))
(if (eq arg 0)
(calc-enter-result 2 "frac" (list func
(calc-top-n 2)
(calc-top-n 1)))
(calc-enter-result 1 "frac" (list func
(calc-top-n 1)
(prefix-numeric-value (or arg 0)))))))
)
(defun calc-over-notation (fmt)
(interactive "sFraction separator (:, ::, /, //, :/): ")
(calc-wrapper
(if (string-match "\\`\\([^ 0-9][^ 0-9]?\\)[0-9]*\\'" fmt)
(let ((n nil))
(if (/= (match-end 0) (match-end 1))
(setq n (string-to-int (substring fmt (match-end 1)))
fmt (math-match-substring fmt 1)))
(if (eq n 0) (error "Bad denominator"))
(calc-change-mode 'calc-frac-format (list fmt n) t))
(error "Bad fraction separator format.")))
)
(defun calc-slash-notation (n)
(interactive "P")
(calc-wrapper
(calc-change-mode 'calc-frac-format (if n '("//" nil) '("/" nil)) t))
)
(defun calc-frac-mode (n)
(interactive "P")
(calc-wrapper
(calc-change-mode 'calc-prefer-frac n nil t)
(message (if calc-prefer-frac
"Integer division will now generate fractions."
"Integer division will now generate floating-point results.")))
)
;;;; Fractions.
;;; Build a normalized fraction. [R I I]
;;; (This could probably be implemented more efficiently than using
;;; the plain gcd algorithm.)
(defun math-make-frac (num den)
(if (Math-integer-negp den)
(setq num (math-neg num)
den (math-neg den)))
(let ((gcd (math-gcd num den)))
(if (eq gcd 1)
(if (eq den 1)
num
(list 'frac num den))
(if (equal gcd den)
(math-quotient num gcd)
(list 'frac (math-quotient num gcd) (math-quotient den gcd)))))
)
(defun calc-add-fractions (a b)
(if (eq (car-safe a) 'frac)
(if (eq (car-safe b) 'frac)
(math-make-frac (math-add (math-mul (nth 1 a) (nth 2 b))
(math-mul (nth 2 a) (nth 1 b)))
(math-mul (nth 2 a) (nth 2 b)))
(math-make-frac (math-add (nth 1 a)
(math-mul (nth 2 a) b))
(nth 2 a)))
(math-make-frac (math-add (math-mul a (nth 2 b))
(nth 1 b))
(nth 2 b)))
)
(defun calc-mul-fractions (a b)
(if (eq (car-safe a) 'frac)
(if (eq (car-safe b) 'frac)
(math-make-frac (math-mul (nth 1 a) (nth 1 b))
(math-mul (nth 2 a) (nth 2 b)))
(math-make-frac (math-mul (nth 1 a) b)
(nth 2 a)))
(math-make-frac (math-mul a (nth 1 b))
(nth 2 b)))
)
(defun calc-div-fractions (a b)
(if (eq (car-safe a) 'frac)
(if (eq (car-safe b) 'frac)
(math-make-frac (math-mul (nth 1 a) (nth 2 b))
(math-mul (nth 2 a) (nth 1 b)))
(math-make-frac (nth 1 a)
(math-mul (nth 2 a) b)))
(math-make-frac (math-mul a (nth 2 b))
(nth 1 b)))
)
;;; Convert a real value to fractional form. [T R I; T R F] [Public]
(defun calcFunc-frac (a &optional tol)
(or tol (setq tol 0))
(cond ((Math-ratp a)
a)
((memq (car a) '(cplx polar vec hms date sdev intv mod))
(cons (car a) (mapcar (function
(lambda (x)
(calcFunc-frac x tol)))
(cdr a))))
((Math-messy-integerp a)
(math-trunc a))
((Math-negp a)
(math-neg (calcFunc-frac (math-neg a) tol)))
((not (eq (car a) 'float))
(if (math-infinitep a)
a
(if (math-provably-integerp a)
a
(math-reject-arg a 'numberp))))
((integerp tol)
(if (<= tol 0)
(setq tol (+ tol calc-internal-prec)))
(calcFunc-frac a (list 'float 5
(- (+ (math-numdigs (nth 1 a))
(nth 2 a))
(1+ tol)))))
((not (eq (car tol) 'float))
(if (Math-realp tol)
(calcFunc-frac a (math-float tol))
(math-reject-arg tol 'realp)))
((Math-negp tol)
(calcFunc-frac a (math-neg tol)))
((Math-zerop tol)
(calcFunc-frac a 0))
((not (math-lessp-float tol '(float 1 0)))
(math-trunc a))
((Math-zerop a)
0)
(t
(let ((cfrac (math-continued-fraction a tol))
(calc-prefer-frac t))
(math-eval-continued-fraction cfrac))))
)
(defun math-continued-fraction (a tol)
(let ((calc-internal-prec (+ calc-internal-prec 2)))
(let ((cfrac nil)
(aa a)
(calc-prefer-frac nil)
int)
(while (or (null cfrac)
(and (not (Math-zerop aa))
(not (math-lessp-float
(math-abs
(math-sub a
(let ((f (math-eval-continued-fraction
cfrac)))
(math-working "Fractionalize" f)
f)))
tol))))
(setq int (math-trunc aa)
aa (math-sub aa int)
cfrac (cons int cfrac))
(or (Math-zerop aa)
(setq aa (math-div 1 aa))))
cfrac))
)
(defun math-eval-continued-fraction (cf)
(let ((n (car cf))
(d 1)
temp)
(while (setq cf (cdr cf))
(setq temp (math-add (math-mul (car cf) n) d)
d n
n temp))
(math-div n d))
)
(defun calcFunc-fdiv (a b) ; [R I I] [Public]
(if (Math-num-integerp a)
(if (Math-num-integerp b)
(if (Math-zerop b)
(math-reject-arg a "*Division by zero")
(math-make-frac (math-trunc a) (math-trunc b)))
(math-reject-arg b 'integerp))
(math-reject-arg a 'integerp))
)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment