README
1
2Mpexpr README
3
4Multiple precision math for Tcl
5
6Copyright 1998 Tom Poindexter, all rights reserved
7tpoindex@gmail.com
8
9Mpexpr is distributed under a "BSD" style license.
10See the file 'LICENSE.TERMS' for details.
11
12
13WHERE TO GET IT
14
15http://sourceforge.net/projects/mpexpr/files/mpexpr/
16
17see http://mpexpr.sourceforge.net/ for web info
18
19
20WHAT IS MPEXPR ?
21
22Mpexpr adds two new commands to Tcl, 'mpexpr' and 'mpformat'. Mpexpr works
23much like Tcl's native 'expr', but does all calculations using an arbitrary
24precision math package. Mpexpr numbers can be any number of digits, with any
25decimal precision. Final precision is controlled by a Tcl variable
26'mp_precision', which can be any reasonable integer, limiting only the
27number of digits to the right of the decimal point.
28
29Mpformat works much like Tcl's 'format', except it formats multiple
30precision numbers in a variety of formats.
31
32Mpexpr also includes most math functions provided by 'expr', as well
33as several new functions. Mpexpr also supports Tcl variables and
34nested evaluation, just like 'expr':
35
36 % set mp_precision 50
37 50
38 % mpexpr 2.0/3.0
39 0.66666666666666666666666666666666666666666666666667
40 % mpexpr atan(1.0)*4 ;# common pi approximation
41 3.14159265358979323846264338327950288419716939937511
42 % mpexpr gcd(234521432954782625385493,725) ;# greatest common divisor
43 29.0
44 % mpexpr fact(34) ;# factorial
45 295232799039604140847618609643520000000
46 % mpexpr comb(2345,23) ;# combination
47 11318394336656126537744856410588463128324931424862853400
48 % set num 129
49 129
50 % mpexpr {fib($num)} ;# fibonnaci number
51 407305795904080553832073954
52 % set mp_precision 15
53 15
54 % set a [ mpexpr {root([set num],3)} ] ;# find the cube root
55 5.052774347208561
56 % mpformat %d $a ;# format as integer
57 5
58 % mpformat %r $a ;# as rational fraction
59 5052774347208561/1000000000000000
60 % mpformat %.7f $a ;# and as floating point
61 5.0527743
62
63
64The trade-off for 'mpepxr' is in execution time. Since 'mpepxr' doesn't
65use native integer or floating point machine instructions, execution
66times can be much greater. Larger precision values (set with 'mp_precision')
67also require more execution time that of smaller values.
68
69ACKNOWLEDGEMENTS:
70
71Mpexpr is a marraige between two other pieces of sofware,
72the code from the Tcl 7.6 'expr' command, and the math
73routines from David Bell's 'calc' program.
74
75I gratefully acknowledge the prior work of David Bell for his fine 'calc'
76program and math package, and all of the Tcl crew.
77
78Landon Curt Noll is now maintaining 'calc'. See his page at:
79
80 http://reality.sgi.com/chongo/calc.html
81
82Calc is being used to find some of the world's largest known prime numbers!
83Awesome!
84
85Here are the original copyright notices:
86
87 Calc
88 # Copyright (c) 1994 David I. Bell
89 # Permission is granted to use, distribute, or modify this source,
90 # provided that this copyright notice remains intact.
91 #
92 # Arbitrary precision calculator.
93
94 David Bell's original 'calc' source can be found at:
95 ftp://ripem.msu.edu/pub/bignum/calc-2.9.3t6.tar.gz
96
97
98 Tcl 7.6
99 * tclExpr.c --
100 *
101 * This file contains the code to evaluate expressions for
102 * Tcl.
103 *
104 * This implementation of floating-point support was modelled
105 * after an initial implementation by Bill Carpenter.
106 *
107 * Copyright (c) 1987-1994 The Regents of the University of California.
108 * Copyright (c) 1994 Sun Microsystems, Inc.
109 *
110 * See the file "license.terms" for information on usage and redistribution
111 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
112
113
114REQUIREMENTS:
115
116 Mpexpr should build with Tcl 7.5 through Tcl 8.6.
117 http://www.tcl.tk/
118
119 Mpexpr builds as a shared library by default, or builds a static library
120 and executables (--disable-shared).
121
122 Mpexpr can also build executables with Extended Tcl (TclX). See the
123 file INSTALL.
124
125 When mpexpr is built as a shared library, you can load the extension with:
126
127 package require Mpexpr
128
129
130WINDOWS BINARIES
131
132A Windows DLL is included, compiled with Tcl 8.6. To install, unpack
133all the files in the ./win directory, rename to appropriate DLL for
134your system to 'mpexpr12.dll' and run:
135 tclsh86 install.tcl
136
137Please note!! I'm not suppling a .zip file for Windows.
138 The popular WinZip program can unpack .tar.gz files. Save the
139 distribution file on your Windows machine,
140 using .tgz instead of .tar.gz for best results.
141
142INSTALLATION
143See the file INSTALL. Really.
144Quickie version:
145 ./configure --prefix=/same/as/tcl --exec-prefix=/same/as/tcl/exec/prefix
146 make
147 make install
148
149
150TEST SUITE
151A test suite exists in the ./tests directory. You can run the
152test suite from the Makefile by:
153 make tests
154
155
156DOCUMENTATION
157See the man page for mpexpr. Html, text, and Postscript
158versions of the man page are in ./doc. mpexpr.n was largely adapted from
159Tcl's documentation.
160
161
162SAMPLE
163See the ./samples directory. As of version 1.0, the only sample available
164is 'mpksc', an adaptation of Ken St-Cyr's Scientific Calculator. I've
165modified the program some to add some Mpexpr functions (gcd, lcm, perm, etc.)
166and to do all calculations in Mpexpr. See the comments in the
167file for other changes.
168
169Thanks to Ken St-Cyr for writing and sharing his fine calculator.
170
171BUG REPORTS, FIXES, COMMENTS, & SUGGESTIONS
172
173Please submit to the SourceForge Tracker:
174
175http://sourceforge.net/p/mpexpr/_list/tickets
176
177