Release calc version 2.12.0.3

This commit is contained in:
Landon Curt Noll
2006-06-11 00:54:41 -07:00
parent 9d62873a02
commit bd3086138b
43 changed files with 2651 additions and 829 deletions

349
CHANGES
View File

@@ -38,8 +38,8 @@ The following are the changes from calc version 2.12.0 to date:
etc.) for VT100 terminals and terminal window emulators (i.e., xterm, etc.) for VT100 terminals and terminal window emulators (i.e., xterm,
Apple OS/X Terminal, etc.) that support them. For example: Apple OS/X Terminal, etc.) that support them. For example:
read screen ; read screen
print green:"This is green. ":red:"This is red.":black ; print green:"This is green. ":red:"This is red.":black
Fixed a bug where too many open files returned E_FOPEN3. Now Fixed a bug where too many open files returned E_FOPEN3. Now
a new error symbol F_MANYOPEN is used for too many open files. a new error symbol F_MANYOPEN is used for too many open files.
@@ -134,14 +134,14 @@ The following are the changes from calc version 2.12.0 to date:
Global variables and functions must be declared ahead of time because Global variables and functions must be declared ahead of time because
the dotest scope of evaluation is a line at a time. For example: the dotest scope of evaluation is a line at a time. For example:
read dotest.cal ; read dotest.cal
read set8700.cal ; read set8700.cal
dotest("set8700.line"); ; dotest("set8700.line");
Updated the todo / wish list items. The top priority now is to Updated the todo / wish list items. The top priority now is to
convert calc to GNU autoconf / configure to build the calc. convert calc to GNU autoconf / configure to build the calc.
help todo ; help todo
Added missing help file for the stoponerror() builtin. Added missing help file for the stoponerror() builtin.
@@ -179,6 +179,87 @@ The following are the changes from calc version 2.12.0 to date:
no other compile errors, only the unterminated comment will stop no other compile errors, only the unterminated comment will stop
completion of the function being defined. completion of the function being defined.
Added the reading of more calc resource files to the cal/regress.cal
regression test.
The issq() test had a slight performance boost. A minor note
was added to the help/issq file.
Improved the documentation of the mul2, sq2, pow2, and redc2 config
parameters in help/config.
Added config("baseb"), a read-only configuration value to return
the number of bits in the fundamental base in which calculations
are performed. This is a read-only configuration value.
Calc now permits such as:
++*p-- ++*----*++p----
where p is an lvalue; successful evaluation of course require the
successive operations to be performed to have operands of appropriate
types; e.g. in *A, A is usually an lvalue whose current value is a
pointer. ++ and -- act on lvalues. In the above examples there are
implied parentheses from the beginning to immediately after p. If
there are no pre ++ or -- operations, as in
**p++
the implied parentheses are from immediately before p to the end.
Improved the error message when && is used as a prefix operator.
Changed the help/config file to read like a builtin function
help file.
One can no longer set to 1, or to a value < 0, the config()
parameters: "mul2", "sq2", "pow2", and "redc2". These values
in the past would result in improper configuration of internal
calc algorithms. Changed cal/test4100.cal to use the minimal
value of 2 for "pow2", and "redc2".
Changed the default values for the following config() parameters:
config("mul2") == 1780
config("sq2") == 3388
config("pow2") == 176
These values were determined established on a 1.8GHz AMD 32-bit
CPU of ~3406 BogoMIPS by the new resource file:
cal/alg_config.cal
Regarding the alg_config.cal resource file:
The best_mul2() function returns the optimal value of config("mul2").
The best_sq2() function returns the optimal value of config("sq2").
The best_pow2() function returns the optimal value of config("pow2").
The other functions are just support functions.
By design, best_mul2(), best_sq2(), and best_pow2() take a few
minutes to run. These functions increase the number of times a
given computational loop is executed until a minimum amount of CPU
time is consumed. To watch these functions progress, one can set
the config("user_debug") value.
Here is a suggested way to use the alg_config.cal resource file:
; read alg_config
; config("user_debug",2),;
; best_mul2(); best_sq2(); best_pow2();
; best_mul2(); best_sq2(); best_pow2();
; best_mul2(); best_sq2(); best_pow2();
NOTE: It is perfectly normal for the optimal value returned
to differ slightly from run to run. Slight variations due to
inaccuracy in CPU timings will cause the best value returned to
differ slightly from run to run.
See "help resource" for more information on alg_config.cal.
Updated the "help variable" text to reflect the current calc
use of ` (backquote), * (star), and & (ampersand).
The following are the changes from calc version 2.11.10.1 to 2.11.11: The following are the changes from calc version 2.11.10.1 to 2.11.11:
@@ -1094,11 +1175,11 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4:
files may be referred to in succession by separating their names files may be referred to in succession by separating their names
by whitespace. For example: by whitespace. For example:
> read alpha beta gamma; ; read alpha beta gamma;
does essentially the same as: does essentially the same as:
> read alpha; read beta; read gamma; ; read alpha; read beta; read gamma;
This is convenient for commands like: This is convenient for commands like:
@@ -1123,7 +1204,7 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4:
multiple read statement, -once applies only to the next named file. multiple read statement, -once applies only to the next named file.
For example For example
> read -once alpha beta -once gamma; ; read -once alpha beta -once gamma;
will read alpha and gamma only if they have not already been read, will read alpha and gamma only if they have not already been read,
but in any case, will read beta. but in any case, will read beta.
@@ -1131,7 +1212,7 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4:
(8) A fault in the programming for the cd command has been corrected (8) A fault in the programming for the cd command has been corrected
so that specifying a directory by a string constant will work. E.g: so that specifying a directory by a string constant will work. E.g:
> cd "my work" ; cd "my work"
should work if the current directory has a directory with name "my work". should work if the current directory has a directory with name "my work".
@@ -1191,17 +1272,17 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4:
(16) "global" and "local" may now be used in expressions. For example: (16) "global" and "local" may now be used in expressions. For example:
> for (local i = 0; i < 5; i++) print i^2; ; for (local i = 0; i < 5; i++) print i^2;
is now acceptable, as is: is now acceptable, as is:
> define f(x = global x) = (global x = x)^2; ; define f(x = global x) = (global x = x)^2;
which breaks wise programming rules and would probably better be handled which breaks wise programming rules and would probably better be handled
by something like: by something like:
> global x ; global x
> define f(t = x) = (x = t)^2; ; define f(t = x) = (x = t)^2;
Both definitions produce the same code for f. For non-null t, f(t) Both definitions produce the same code for f. For non-null t, f(t)
returns t^2 and assigns the value of t to x; f() and f(t) with null t returns t^2 and assigns the value of t to x; f() and f(t) with null t
@@ -1219,11 +1300,11 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4:
either 32 or 64-bit longs. In setting such components, the arguments either 32 or 64-bit longs. In setting such components, the arguments
are now to less than 2^31. Before this change: are now to less than 2^31. Before this change:
> config("mul2", 2^32 + 3) ; config("mul2", 2^32 + 3)
would be accepted on a 64-bit machine but result in the same as: would be accepted on a 64-bit machine but result in the same as:
> config("mul2", 3) ; config("mul2", 3)
The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0: The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0:
@@ -1462,9 +1543,9 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11:
The power(a, b, epsilon) builtin will return a "too-large result" The power(a, b, epsilon) builtin will return a "too-large result"
if an estimate indicates that the result will have absolute value if an estimate indicates that the result will have absolute value
> 2^2^30 * epsilon. Otherwise the evaluation will be attempted that is > 2^2^30 * epsilon. Otherwise the evaluation will be
but may fail due to shortage of memory or may require a long attempted but may fail due to shortage of memory or may require
runtime if the result will be very large. a long runtime if the result will be very large.
Changes have been made to the algorithms used for some special Changes have been made to the algorithms used for some special
functions sinh(), cosh(), tanh(), sin(), cos(), etc., that make functions sinh(), cosh(), tanh(), sin(), cos(), etc., that make
@@ -2500,10 +2581,10 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37:
of links to the occurrence of that argument that is being referred to. of links to the occurrence of that argument that is being referred to.
For example, supposing "abc" has not been used earlier: For example, supposing "abc" has not been used earlier:
> A = "abc" ; A = "abc"
> links(A) ; links(A)
2 2
> links(A) ; links(A)
1 1
The two links in the first call are to A and the current "oldvalue"; The two links in the first call are to A and the current "oldvalue";
@@ -2798,11 +2879,11 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37:
(30) Although it is not illegal, it seems pointless to use a comma operator (30) Although it is not illegal, it seems pointless to use a comma operator
with a constant or simple variable as in with a constant or simple variable as in
> 2 * 3,14159 ; 2 * 3,14159
14159 14159
> a = 4; b = 5; ; a = 4; b = 5;
> A = (a , b + 2); ; A = (a , b + 2);
> A ; A
7 7
I have added a few lines to addop.c so that when this occurs a I have added a few lines to addop.c so that when this occurs a
@@ -2833,27 +2914,27 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37:
Here is a demo: Here is a demo:
> global a; ; global a;
> ;
> define f(x) {local i = x^2; a++; ; define f(x) {local i = x^2; a++;
>> if (x > 5) quit "Too large!"; return i;} ;; if (x > 5) quit "Too large!"; return i;}
f() defined f() defined
> define g(x) = f(x) + f(2*x); ; define g(x) = f(x) + f(2*x);
g() defined g() defined
> g(2) ; g(2)
20 20
> g(3) ; g(3)
Too large! Too large!
"f": line 3 "f": line 3
"g": line 0 "g": line 0
"*": line 6 "*": line 6
> eval("g(3)") ; eval("g(3)")
Too large! Too large!
"f": line 3 "f": line 3
"g": line 0 "g": line 0
"**": line 1 "**": line 1
"*": line 7 "*": line 7
> a ; a
6 6
(32) I've made several small changes like removing (32) I've made several small changes like removing
@@ -2899,14 +2980,14 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
a variable as in p = &var, and then *p in expressions has a variable as in p = &var, and then *p in expressions has
the same effect as var. Here is a simple example of their use: the same effect as var. Here is a simple example of their use:
> define s(L) {local v=0; while (size(L)) v+= *pop(L);return v;} ; define s(L) {local v=0; while (size(L)) v+= *pop(L);return v;}
s() defined s() defined
> global a = 1, b = 2; ; global a = 1, b = 2;
> L = list(&a, &b); ; L = list(&a, &b);
> print s(L) ; print s(L)
3 3
> b = 3; ; b = 3;
> print s(L) ; print s(L)
4 4
Octet-pointers, number-pointers, and string-pointers in Octet-pointers, number-pointers, and string-pointers in
@@ -2918,11 +2999,11 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
Some arithmetic operations has been defined for corresponding Some arithmetic operations has been defined for corresponding
C operations. For example: C operations. For example:
> A = mat[4]; ; A = mat[4];
> p = &A[0]; ; p = &A[0];
> *(p+2) == A[2] ; *(p+2) == A[2]
> ++p ; ++p
> *p == A[1] ; *p == A[1]
There is at present no protection against "illegal" use of & There is at present no protection against "illegal" use of &
and *, e.g. if one attempts here to assign a value to *(p+5), and *, e.g. if one attempts here to assign a value to *(p+5),
@@ -2935,28 +3016,28 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
X; in effect X is an address and *X is the value at X. X; in effect X is an address and *X is the value at X.
Added isptr(p) builtin to return 0 is p is not a pointer, Added isptr(p) builtin to return 0 is p is not a pointer,
>0 if it is a pointer. The value of isptr(p) comes from the and >0 if it is a pointer. The value of isptr(p) comes from
V_XYZ #define (see the top of value.h) of the value to which the V_XYZ #define (see the top of value.h) of the value to
p points. which p points.
To allow & to be used as a C-like address operator, use of it To allow & to be used as a C-like address operator, use of it
has been dropped in calls to user-defined functions. For the has been dropped in calls to user-defined functions. For the
time being I have replaced it by the back-quote `. For example: time being I have replaced it by the back-quote `. For example:
> global a ; global a
> define f(a,b) = a = b ; define f(a,b) = a = b
> f(&a,5) ; f(&a,5)
> print a ; print a
0 0
> f(`a,5) ; f(`a,5)
> print a ; print a
5 5
However, one may use & in a similar way as in: However, one may use & in a similar way as in:
> define g(a,b) = *a = b ; define g(a,b) = *a = b
> g(&a, 7) ; g(&a, 7)
> print a ; print a
7 7
There is no hashvalue for pointers. Thus, like error values, There is no hashvalue for pointers. Thus, like error values,
@@ -2964,38 +3045,38 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
The -> also works in calc. For example: The -> also works in calc. For example:
> obj xy {x,y} ; obj xy {x,y}
> obj uvw {u, v, w} ; obj uvw {u, v, w}
> obj xy A = {1,2} ; obj xy A = {1,2}
> obj uvw B = {3,4,5} ; obj uvw B = {3,4,5}
> p = &A ; p = &A
> q = &B ; q = &B
> p->x ; p->x
1 1
> p->y = 6 ; p->y = 6
> A ; A
obj xy {1, 6} obj xy {1, 6}
> q -> u ; q -> u
3 3
> p->y = q ; p->y = q
> A ; A
obj xy {1, v-ptr: 1400474c0} obj xy {1, v-ptr: 1400474c0}
> p->y->u ; p->y->u
3 3
> p->y->u = 7 ; p->y->u = 7
> B ; B
obj uvw {7, 4, 5} obj uvw {7, 4, 5}
> p -> y = p ; p -> y = p
> A ; A
obj xy {1, v-ptr: 140047490} obj xy {1, v-ptr: 140047490}
> p -> y -> x ; p -> y -> x
1 1
> p->y->y ; p->y->y
v-ptr: 140047490 v-ptr: 140047490
> p->y->y-> x ; p->y->y-> x
1 1
> p->y->y->x = 8 ; p->y->y->x = 8
> A ; A
obj xy {8, v-ptr: 140047490} obj xy {8, v-ptr: 140047490}
@@ -3023,14 +3104,14 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
The prior method calc has used for handling "constants" amounted The prior method calc has used for handling "constants" amounted
to leakage. After: to leakage. After:
> define f(x) = 27 + x; ; define f(x) = 27 + x;
> a = 27; ; a = 27;
It is of course necessary for the constant 27 to be stored, but It is of course necessary for the constant 27 to be stored, but
if one now redefines f and a by: if one now redefines f and a by:
> define f(x) = 45 + x; ; define f(x) = 45 + x;
> a = 45; ; a = 45;
There seems little point in retaining 27 as a constant and There seems little point in retaining 27 as a constant and
therefore using up memory. If this example seems trivial, therefore using up memory. If this example seems trivial,
@@ -3112,16 +3193,16 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
The "." value: The "." value:
> 2 + 2 ; 2 + 2
4 4
> . ; .
4 4
can now be treated as an unnamed variable. For example: can now be treated as an unnamed variable. For example:
> mat x[3,3]={1,2,3,4,5,6,7,8,9} ; mat x[3,3]={1,2,3,4,5,6,7,8,9}
> x ; x
> print .[1,2] ; print .[1,2]
6 6
(9) for a list L defining L[i] to be same as L[[i]] (9) for a list L defining L[i] to be same as L[[i]]
@@ -3158,18 +3239,18 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
For example: For example:
> A = list(1,2,4); ; A = list(1,2,4);
> B = mat[2,2] = {5,6,7,8}; ; B = mat[2,2] = {5,6,7,8};
> define f(x) = (x ? A : B)[[1]]; ; define f(x) = (x ? A : B)[[1]];
> print f(1), f(0) ; print f(1), f(0)
2 6 2 6
> obj xy {x,y} ; obj xy {x,y}
> C = obj xy = {4,5} ; C = obj xy = {4,5}
> p = &C ; p = &C
> *p.x ; *p.x
Not indexing matrix or object Not indexing matrix or object
> (*p).x ; (*p).x
4 4
(14) swap(a,b) now permits swapping of octets in the same or different (14) swap(a,b) now permits swapping of octets in the same or different
@@ -3177,10 +3258,10 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
For example: For example:
> A = blk() = {1,2,3} ; A = blk() = {1,2,3}
> B = blk() = {4,5,6} ; B = blk() = {4,5,6}
> swap(A[0], B[2]) ; swap(A[0], B[2])
> A ; A
chunksize = 256, maxsize = 256, datalen = 3 chunksize = 256, maxsize = 256, datalen = 3
060203 060203
@@ -3316,12 +3397,12 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27:
Blocks will expand when required by the copy() builtin function: Blocks will expand when required by the copy() builtin function:
> f = fopen("help/full", "r") ; f = fopen("help/full", "r")
> B = blk() ; B = blk()
> B ; B
chunksize = 256, maxsize = 256, datalen = 0 chunksize = 256, maxsize = 256, datalen = 0
> copy(B, f) ; copy(B, f)
> B ; B
chunksize = 256, maxsize = 310272, datalen = 310084 chunksize = 256, maxsize = 310272, datalen = 310084
2a2a2a2a2a2a2a2a2a2a2a2a2a0a2a20696e74726f0a2a2a2a2a2a2a2a2a... 2a2a2a2a2a2a2a2a2a2a2a2a2a0a2a20696e74726f0a2a2a2a2a2a2a2a2a...
@@ -4241,11 +4322,11 @@ The following are the changes from calc version 2.10.2t25 to 2.10.2t32:
"global a" is read in the last line. Thus one may now use the "global a" is read in the last line. Thus one may now use the
same name in several "static" areas as in: same name in several "static" areas as in:
> static a = 10; ; static a = 10;
> define f(x) = a + x; ; define f(x) = a + x;
> static a = 20; ; static a = 20;
> define g(x) = a + x; ; define g(x) = a + x;
> global a; ; global a;
The first "a" exists only for the definition of f(); the second The first "a" exists only for the definition of f(); the second
"a" only for the definition of g(). At the end one has only "a" only for the definition of g(). At the end one has only
@@ -4254,10 +4335,10 @@ The following are the changes from calc version 2.10.2t25 to 2.10.2t32:
Ending the scope of a static variable in this way is consistent Ending the scope of a static variable in this way is consistent
with the normal use of static variables as in: with the normal use of static variables as in:
> static a = 10; ; static a = 10;
> define f(x) {static a = 20; return a++ + x;} ; define f(x) {static a = 20; return a++ + x;}
> define g(x) = a + x; ; define g(x) = a + x;
> global a; ; global a;
The scope of the first "a" is temporarily interrupted by the The scope of the first "a" is temporarily interrupted by the
"static a" in the second line; the second "a" remains active "static a" in the second line; the second "a" remains active
@@ -4273,12 +4354,12 @@ The following are the changes from calc version 2.10.2t25 to 2.10.2t32:
to me that its use must end the scope of any static "a". Thus to me that its use must end the scope of any static "a". Thus
the changes I introduce are such that after: the changes I introduce are such that after:
> global a = 10; ; global a = 10;
> define f(x) = a + x; ; define f(x) = a + x;
> static a = 20; ; static a = 20;
> define g(x) = a + x; ; define g(x) = a + x;
> define h(x) {global a = 30; return a + x;} ; define h(x) {global a = 30; return a + x;}
> define i(x) = a + x; ; define i(x) = a + x;
g(x) will always return 20 + x, and until h(x) has been called, g(x) will always return 20 + x, and until h(x) has been called,
f(x) and i(x) will return 10 + x; when h(x) is called, it f(x) and i(x) will return 10 + x; when h(x) is called, it
@@ -4425,8 +4506,8 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24:
The show keyword is now a statement instead of a command: The show keyword is now a statement instead of a command:
> define demo() {local f = open("foo", "w"); show files; fclose(f);} ; define demo() {local f = open("foo", "w"); show files; fclose(f);}
> demo() ; demo()
Added a new trace option for display of links to real and complex Added a new trace option for display of links to real and complex
numbers. This is activated by config("trace", 4). The printing of numbers. This is activated by config("trace", 4). The printing of
@@ -4905,13 +4986,13 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0:
The param(n) builtin, then n > 0, may be used as an lvalue: The param(n) builtin, then n > 0, may be used as an lvalue:
> define g() = (param(2) = param(1)); ; define g() = (param(2) = param(1));
> define h() = (param(1)++, param(2)--); ; define h() = (param(1)++, param(2)--);
> u = 5 ; u = 5
> v = 10 ; v = 10
> print g(u, &v), u, v; ; print g(u, &v), u, v;
5 5 5 5 5 5
> print h(&u, &v), u, v; ; print h(&u, &v), u, v;
5 6 4 5 6 4
Missing args now evaluate to null as in: Missing args now evaluate to null as in:
@@ -5272,9 +5353,9 @@ The following are the changes from calc version 2.10.0t13 to 2.10.1t10:
C-style arbitrary precision calculator (version 2.10.1t3) C-style arbitrary precision calculator (version 2.10.1t3)
[Type "exit" to exit, or "help" for help.] [Type "exit" to exit, or "help" for help.]
> files(5) ; files(5)
FILE 5 "descriptor[5]" (unknown_mode, pos 0) FILE 5 "descriptor[5]" (unknown_mode, pos 0)
> fgetline(files(5)) ; fgetline(files(5))
"A line of text in the file on descriptor 5" "A line of text in the file on descriptor 5"
The -m mode flag now controls calc's ability to open files The -m mode flag now controls calc's ability to open files
@@ -5996,8 +6077,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.78 $ ## @(#) $Revision: 29.80 $
## @(#) $Id: CHANGES,v 29.78 2006/06/03 22:52:39 chongo Exp $ ## @(#) $Id: CHANGES,v 29.80 2006/06/11 07:52:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $ ## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $
## ##
## Under source code control: 1993/06/02 18:12:57 ## Under source code control: 1993/06/02 18:12:57

View File

@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc. # received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
# #
# @(#) $Revision: 29.18 $ # @(#) $Revision: 29.19 $
# @(#) $Id: Makefile,v 29.18 2006/05/20 19:32:40 chongo Exp $ # @(#) $Id: Makefile,v 29.19 2006/06/10 13:01:34 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/Makefile,v $ # @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/Makefile,v $
# #
# Under source code control: 1991/07/21 05:00:54 # Under source code control: 1991/07/21 05:00:54
@@ -177,7 +177,7 @@ CALC_FILES= README bigprime.cal deg.cal ellip.cal lucas.cal lucas_chk.cal \
beer.cal hello.cal test5100.cal test5200.cal randombitrun.cal \ beer.cal hello.cal test5100.cal test5200.cal randombitrun.cal \
randomrun.cal repeat.cal xx_print.cal natnumset.cal qtime.cal \ randomrun.cal repeat.cal xx_print.cal natnumset.cal qtime.cal \
test8400.cal test8500.cal test8600.cal chi.cal intfile.cal screen.cal \ test8400.cal test8500.cal test8600.cal chi.cal intfile.cal screen.cal \
dotest.cal set8700.cal set8700.line dotest.cal set8700.cal set8700.line alg_config.cal
# These files are found (but not built) in the distribution # These files are found (but not built) in the distribution
# #

View File

@@ -75,7 +75,7 @@ have meanings are as follows:
is displayed. is displayed.
2 Show func will display more information about a functions 2 Show func will display more information about a functions
arguments as well as more argument sdummary information. arguments as well as more argument summary information.
3 During execution, allow calc standard resource files 3 During execution, allow calc standard resource files
to output additional debugging information. to output additional debugging information.
@@ -103,7 +103,7 @@ either of the bottom 2 bits set:
print "funcB(size, mass, ...) defined"; print "funcB(size, mass, ...) defined";
} }
If your the resource file needs to output special debugging informatin, If your the resource file needs to output special debugging information,
we recommend that you check for bit 3 of the config("resource_debug") we recommend that you check for bit 3 of the config("resource_debug")
before printing the debug statement: before printing the debug statement:
@@ -117,12 +117,68 @@ The following is a brief description of some of the calc resource files
that are shipped with calc. See above for example of how to read in that are shipped with calc. See above for example of how to read in
and execute these files. and execute these files.
alg_config.cal
global test_time
mul_loop(repeat,x) defined
mul_ratio(len) defined
best_mul2() defined
sq_loop(repeat,x) defined
sq_ratio(len) defined
best_sq2() defined
pow_loop(repeat,x,ex) defined
pow_ratio(len) defined
best_pow2() defined
These functions search for an optimal value of config("mul2"),
config("sq2"), and config("pow2"). The calc default values of these
configuration values were set by running this resource file on a
1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS.
The best_mul2() function returns the optimal value of config("mul2").
The best_sq2() function returns the optimal value of config("sq2").
The best_pow2() function returns the optimal value of config("pow2").
The other functions are just support functions.
By design, best_mul2(), best_sq2(), and best_pow2() take a few
minutes to run. These functions increase the number of times a
given computational loop is executed until a minimum amount of CPU
time is consumed. To watch these functions progress, one can set
the config("user_debug") value.
Here is a suggested way to use this resource file:
; read alg_config
; config("user_debug",2),;
; best_mul2(); best_sq2(); best_pow2();
; best_mul2(); best_sq2(); best_pow2();
; best_mul2(); best_sq2(); best_pow2();
NOTE: It is perfectly normal for the optimal value returned to differ
slightly from run to run. Slight variations due to inaccuracy in
CPU timings will cause the best value returned to differ slightly
from run to run.
One can use a calc startup file to change the initial values of
config("mul2"), config("sq2"), and config("pow2"). For example one
can place into ~/.calcrc these lines:
config("mul2", 1780),;
config("sq2", 3388),;
config("pow2", 176),;
to automatically and silently change these config values.
See help/config and CALCRC in help/environment for more information.
beer.cal beer.cal
Calc's contribution to the 99 Bottles of Beer web page: Calc's contribution to the 99 Bottles of Beer web page:
http://www.ionet.net/~timtroyr/funhouse/beer.html#calc http://www.ionet.net/~timtroyr/funhouse/beer.html#calc
NOTE: This resource produces a lot of output. :-)
bernoulli.cal bernoulli.cal
@@ -132,7 +188,7 @@ bernoulli.cal
NOTE: There is now a bernoulli() builtin function. This file is NOTE: There is now a bernoulli() builtin function. This file is
left here for backward compatibility and now simply returns left here for backward compatibility and now simply returns
the buildin function. the builtin function.
bigprime.cal bigprime.cal
@@ -153,9 +209,9 @@ chi.cal
The chi_prob() function does not work well with odd degrees of freedom. The chi_prob() function does not work well with odd degrees of freedom.
It is reasonable with even degrees of freedom, although one must give It is reasonable with even degrees of freedom, although one must give
a sifficently small error term as the degress gets large (>100). a sufficiently small error term as the degrees gets large (>100).
The Z(x) and P(x) are internal statistical funcions. The Z(x) and P(x) are internal statistical functions.
eps is an optional epsilon() like error term. eps is an optional epsilon() like error term.
@@ -226,6 +282,8 @@ hello.cal
http://www.latech.edu/~acm/HelloWorld.shtml http://www.latech.edu/~acm/HelloWorld.shtml
http://www.latech.edu/~acm/helloworld/calc.html http://www.latech.edu/~acm/helloworld/calc.html
NOTE: This resource produces a lot of output. :-)
intfile.cal intfile.cal
@@ -935,8 +993,8 @@ xx_print.cal
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.12 $ ## @(#) $Revision: 29.14 $
## @(#) $Id: README,v 29.12 2006/05/21 04:41:09 chongo Exp $ ## @(#) $Id: README,v 29.14 2006/06/11 07:22:05 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $ ## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $
## ##
## Under source code control: 1990/02/15 01:50:32 ## Under source code control: 1990/02/15 01:50:32

1253
cal/alg_config.cal Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.26 $ * @(#) $Revision: 29.29 $
* @(#) $Id: regress.cal,v 29.26 2006/06/02 09:49:13 chongo Exp $ * @(#) $Id: regress.cal,v 29.29 2006/06/11 07:07:23 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $
* *
* Under source code control: 1990/02/15 01:50:36 * Under source code control: 1990/02/15 01:50:36
@@ -404,14 +404,14 @@ define test_config()
'512: config("trace") == 0'); '512: config("trace") == 0');
vrfy(config("maxprint") == 16, vrfy(config("maxprint") == 16,
'513: config("maxprint") == 16'); '513: config("maxprint") == 16');
vrfy(config("mul2") == 20, vrfy(config("mul2") == 1780,
'514: config("mul2") == 20'); '514: config("mul2") == 1780');
vrfy(config("sq2") == 20, vrfy(config("sq2") == 3388,
'515: config("sq2") == 20'); '515: config("sq2") == 3388');
vrfy(config("pow2") == 40, vrfy(config("pow2") == 176,
'516: config("pow2") == 40'); '516: config("pow2") == 176');
vrfy(config("redc2") == 50, vrfy(config("redc2") == 220,
'517: config("redc2") == 50'); '517: config("redc2") == 220');
vrfy(config("tilde"), vrfy(config("tilde"),
'518: config("tilde")'); '518: config("tilde")');
vrfy(config("tab"), vrfy(config("tab"),
@@ -5226,6 +5226,11 @@ define test_is()
local square; /* square of an odd prime */ local square; /* square of an odd prime */
local string; /* string */ local string; /* string */
local com; /* complex value */ local com; /* complex value */
local rndint; /* a random integer */
local rndexp; /* a random exponent */
local rndval; /* rndint ^ rndexp */
local i; /* integer value */
local ok; /* 1 ==> issq() tests were OK, 0 ==> failure */
print '5900: Beginning test_is'; print '5900: Beginning test_is';
@@ -6163,15 +6168,75 @@ define test_is()
vrfy(istype(matrix,odd) == 0, '6661: istype(matrix,odd) == 0'); vrfy(istype(matrix,odd) == 0, '6661: istype(matrix,odd) == 0');
vrfy(istype(a,odd) == 0, '6662: istype(a,odd) == 0'); vrfy(istype(a,odd) == 0, '6662: istype(a,odd) == 0');
/*
* perform more extensive issq() testing
*/
ok = 1;
for (i=0; i < 256; ++i) {
/* rndval will be a square - even powers>0 of x>1 */
rndexp = random(1, 16) * 2;
rndint = random(2, 4294967296);
if (issq(rndint)) {
++rndint;
}
rndval = rndint ^ rndexp;
if (issq(rndval) == 0) {
prob(strprintf("issq(%d^%d) returned 0",
rndint, rndexp));
ok = 0;
}
}
if (ok) {
print '6663: issq() on 256 squares';
} else {
print '****: failure(s): 6663: faiissq() on 256 squares';
}
for (i=0; i < 256; ++i) {
/* rndval will not be a square - 1 + even powers>0 of x>1 */
rndexp = random(1, 16) * 2;
rndint = random(2, 4294967296);
rndval = rndint ^ rndexp;
if (issq(rndval+1) != 0) {
prob(strprintf("issq(%d^%d)+1 returned non-zero",
rndint, rndexp));
ok = 0;
}
}
if (ok) {
print '6664: issq() on 256 squares+1';
} else {
print '****: failure(s): 6664: issq() on 256 squares+1';
}
print '6664: issq() on 256 squares+1';
for (i=0; i < 256; ++i) {
/* rndval will not be a square - odd powers>0 of x>1 */
rndexp = (random(1, 16) * 2) + 1;
rndint = random(2, 4294967296);
if (issq(rndint)) {
++rndint;
}
rndval = rndint ^ rndexp;
if (issq(rndval) != 0) {
prob(strprintf("issq(%d^%d) returned non-zero",
rndint, rndexp));
ok = 0;
}
}
if (ok) {
print '6665: issq() on 256 non-squares';
} else {
print '****: failure(s): 6665: issq() on 256 non-squares';
}
/* /*
* cleanup * cleanup
*/ */
blkfree("blk5900"); blkfree("blk5900");
print '6663: blkfree("blk5900")'; print '6666: blkfree("blk5900")';
fclose(ofd); fclose(ofd);
print '6664: fclose(ofd)'; print '6667: fclose(ofd)';
print '6665: Ending test_is'; print '6668: Ending test_is';
} }
print '168: test_is()'; print '168: test_is()';
@@ -7847,7 +7912,26 @@ read -once varargs;
print '9827: read -once varargs'; print '9827: read -once varargs';
read -once qtime; read -once qtime;
print '9828: read -once qtime'; print '9828: read -once qtime';
print '9829: Ending read of selected calc resource files'; read -once chi;
print '9829: read -once chi';
read -once intfile;
print '9830: read -once intfile';
read -once lucas;
print '9831: read -once lucas';
read -once lucas_tbl;
print '9832: read -once lucas_tbl';
read -once natnumset;
print '9833: read -once natnumset';
read -once repeat;
print '9834: read -once repeat';
read -once screen;
print '9835: read -once screen';
read -once linear;
print '9836: read -once linear';
print '9837: skipping read -once beer.cal because it is an infinite loop';
print '9838: skipping read -once hello.cal because it is an infinite loop';
print '9839: skipping read -once xx_print.cal because it is a printing demo';
print '9840: Ending read of selected calc resource files';
/* /*

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.2 $ * @(#) $Revision: 29.3 $
* @(#) $Id: test4100.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $ * @(#) $Id: test4100.cal,v 29.3 2006/06/10 20:19:20 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4100.cal,v $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4100.cal,v $
* *
* Under source code control: 1996/03/13 03:53:22 * Under source code control: 1996/03/13 03:53:22
@@ -316,8 +316,8 @@ define powtimes(str, N1, N2, n, verbose)
mat B[n]; mat B[n];
v = olen(N1); v = olen(N1);
cp = config("pow2", 1); cp = config("pow2", 2);
crc = config("redc2", 1); crc = config("redc2", 2);
/* initialize redc and lastmod info */ /* initialize redc and lastmod info */
@@ -346,7 +346,7 @@ define powtimes(str, N1, N2, n, verbose)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
z4 += rcpow(Ar[i], B[i], v); z4 += rcpow(Ar[i], B[i], v);
trcsmall = round(runtime() - t, 4); trcsmall = round(runtime() - t, 4);
config("redc2", 1); config("redc2", 2);
t = runtime(); t = runtime();
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
z5 += rcpow(Ar[i], B[i], v); z5 += rcpow(Ar[i], B[i], v);

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.18 $ * @(#) $Revision: 29.20 $
* @(#) $Id: codegen.c,v 29.18 2006/06/03 22:47:28 chongo Exp $ * @(#) $Id: codegen.c,v 29.20 2006/06/11 07:25:14 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $
* *
* Under source code control: 1990/02/15 01:48:13 * Under source code control: 1990/02/15 01:48:13
@@ -1953,7 +1953,8 @@ getreference(void)
switch(gettoken()) { switch(gettoken()) {
case T_ANDAND: case T_ANDAND:
scanerror(T_NULL, "Non-variable operand for &"); scanerror(T_NULL, "&& used as prefix operator");
/*FALLTHRU*/
case T_AND: case T_AND:
type = getreference(); type = getreference();
addop(OP_PTR); addop(OP_PTR);
@@ -2108,6 +2109,19 @@ getterm(void)
type = getidexpr(TRUE, 0); type = getidexpr(TRUE, 0);
break; break;
case T_MULT:
(void) getterm();
addop(OP_DEREF);
type = 0;
break;
case T_POWER: /* '**' or '^' */
(void) getterm();
addop(OP_DEREF);
addop(OP_DEREF);
type = 0;
break;
case T_GLOBAL: case T_GLOBAL:
if (gettoken() != T_SYMBOL) { if (gettoken() != T_SYMBOL) {
scanerror(T_NULL, "Global id expected"); scanerror(T_NULL, "Global id expected");

111
config.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.17 $ * @(#) $Revision: 29.20 $
* @(#) $Id: config.c,v 29.17 2006/05/19 15:26:10 chongo Exp $ * @(#) $Id: config.c,v 29.20 2006/06/11 00:08:56 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $
* *
* Under source code control: 1991/07/20 00:21:56 * Under source code control: 1991/07/20 00:21:56
@@ -97,6 +97,7 @@ NAMETYPE configs[] = {
{"compile_custom", CONFIG_COMPILE_CUSTOM}, {"compile_custom", CONFIG_COMPILE_CUSTOM},
{"allow_custom", CONFIG_ALLOW_CUSTOM}, {"allow_custom", CONFIG_ALLOW_CUSTOM},
{"version", CONFIG_VERSION}, {"version", CONFIG_VERSION},
{"baseb", CONFIG_BASEB},
{NULL, 0} {NULL, 0}
}; };
@@ -159,7 +160,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
FALSE, /* compiled without -DCUSTOM */ FALSE, /* compiled without -DCUSTOM */
#endif #endif
&allow_custom, /* *TRUE=> custom functions are enabled */ &allow_custom, /* *TRUE=> custom functions are enabled */
NULL /* version */ NULL, /* version */
BASEB, /* base for calculations */
}; };
CONFIG newstd = { /* new non-backward compatible configuration */ CONFIG newstd = { /* new non-backward compatible configuration */
MODE_INITIAL, /* current output mode */ MODE_INITIAL, /* current output mode */
@@ -216,7 +218,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
FALSE, /* compiled without -DCUSTOM */ FALSE, /* compiled without -DCUSTOM */
#endif #endif
&allow_custom, /* *TRUE=> custom functions are enabled */ &allow_custom, /* *TRUE=> custom functions are enabled */
NULL /* version */ NULL, /* version */
BASEB, /* base for calculations */
}; };
CONFIG *conf = NULL; /* loaded in at startup - current configuration */ CONFIG *conf = NULL; /* loaded in at startup - current configuration */
@@ -527,7 +530,7 @@ setconfig(int type, VALUE *vp)
break; break;
case CONFIG_MUL2: case CONFIG_MUL2:
if (getlen(vp, &len)) { if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for mul2"); math_error("Bad value for mul2");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@@ -537,7 +540,7 @@ setconfig(int type, VALUE *vp)
break; break;
case CONFIG_SQ2: case CONFIG_SQ2:
if (getlen(vp, &len)) { if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for sq2"); math_error("Bad value for sq2");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@@ -547,7 +550,7 @@ setconfig(int type, VALUE *vp)
break; break;
case CONFIG_POW2: case CONFIG_POW2:
if (getlen(vp, &len)) { if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for pow2"); math_error("Bad value for pow2");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@@ -557,7 +560,7 @@ setconfig(int type, VALUE *vp)
break; break;
case CONFIG_REDC2: case CONFIG_REDC2:
if (getlen(vp, &len)) { if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for redc2"); math_error("Bad value for redc2");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@@ -899,6 +902,10 @@ setconfig(int type, VALUE *vp)
math_error("The version config parameter is read-only"); math_error("The version config parameter is read-only");
/*NOTREACHED*/ /*NOTREACHED*/
case CONFIG_BASEB:
math_error("The baseb config parameter is read-only");
/*NOTREACHED*/
default: default:
math_error("Setting illegal config parameter"); math_error("Setting illegal config parameter");
/*NOTREACHED*/ /*NOTREACHED*/
@@ -1110,20 +1117,12 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break; break;
case CONFIG_TILDE: case CONFIG_TILDE:
if (cfg->tilde_ok) { i = (cfg->tilde_ok ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_TAB: case CONFIG_TAB:
if (cfg->tab_ok) { i = (cfg->tab_ok ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_QUOMOD: case CONFIG_QUOMOD:
i = cfg->quomod; i = cfg->quomod;
@@ -1162,20 +1161,12 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break; break;
case CONFIG_LEADZERO: case CONFIG_LEADZERO:
if (cfg->leadzero) { i = (cfg->leadzero ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_FULLZERO: case CONFIG_FULLZERO:
if (cfg->fullzero) { i = (cfg->fullzero ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_MAXSCAN: case CONFIG_MAXSCAN:
i = cfg->maxscancount; i = cfg->maxscancount;
@@ -1196,12 +1187,8 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break; break;
case CONFIG_BLKVERBOSE: case CONFIG_BLKVERBOSE:
if (cfg->blkverbose) { i = (cfg->blkverbose ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_BLKBASE: case CONFIG_BLKBASE:
vp->v_type = V_STR; vp->v_type = V_STR;
@@ -1236,12 +1223,8 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break; break;
case CONFIG_VERBOSE_QUIT: case CONFIG_VERBOSE_QUIT:
if (cfg->verbose_quit) { i = (cfg->verbose_quit ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_CTRL_D: case CONFIG_CTRL_D:
vp->v_type = V_STR; vp->v_type = V_STR;
@@ -1272,40 +1255,24 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
return; return;
case CONFIG_WINDOWS: case CONFIG_WINDOWS:
if (cfg->windows) { i = (cfg->windows ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_CYGWIN: case CONFIG_CYGWIN:
if (cfg->cygwin) { i = (cfg->cygwin ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_COMPILE_CUSTOM: case CONFIG_COMPILE_CUSTOM:
if (cfg->compile_custom) { i = (cfg->compile_custom ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_ALLOW_CUSTOM: case CONFIG_ALLOW_CUSTOM:
/* firewall */ /* firewall */
if (cfg->allow_custom == NULL) { if (cfg->allow_custom == NULL) {
cfg->allow_custom = &allow_custom; cfg->allow_custom = &allow_custom;
} }
if (*(cfg->allow_custom)) { i = (*(cfg->allow_custom) ? 1 : 0);
vp->v_num = itoq(1); break;
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_VERSION: case CONFIG_VERSION:
vp->v_type = V_STR; vp->v_type = V_STR;
@@ -1316,6 +1283,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
} }
return; return;
case CONFIG_BASEB:
i = BASEB;
break;
default: default:
math_error("Getting illegal CONFIG element"); math_error("Getting illegal CONFIG element");
/*NOTREACHED*/ /*NOTREACHED*/
@@ -1420,5 +1391,7 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
(cfg1->version == NULL && cfg2->version != NULL) || (cfg1->version == NULL && cfg2->version != NULL) ||
(cfg1->version != NULL && cfg2->version == NULL) || (cfg1->version != NULL && cfg2->version == NULL) ||
(cfg1->version != NULL && cfg2->version != NULL && (cfg1->version != NULL && cfg2->version != NULL &&
strcmp(cfg1->version, cfg2->version) != 0); strcmp(cfg1->version, cfg2->version) != 0) ||
cfg1->baseb != cfg2->baseb;
} }

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.17 $ * @(#) $Revision: 29.18 $
* @(#) $Id: config.h,v 29.17 2004/02/25 23:56:13 chongo Exp $ * @(#) $Id: config.h,v 29.18 2006/06/06 07:17:02 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.h,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/config.h,v $
* *
* Under source code control: 1995/11/01 22:20:17 * Under source code control: 1995/11/01 22:20:17
@@ -94,6 +94,7 @@
#define CONFIG_CYGWIN 40 #define CONFIG_CYGWIN 40
#define CONFIG_COMPILE_CUSTOM 41 #define CONFIG_COMPILE_CUSTOM 41
#define CONFIG_ALLOW_CUSTOM 42 #define CONFIG_ALLOW_CUSTOM 42
#define CONFIG_BASEB 43
/* /*
@@ -162,6 +163,7 @@ struct config {
BOOL compile_custom; /* TRUE => compiled with -DCUSTOM */ BOOL compile_custom; /* TRUE => compiled with -DCUSTOM */
BOOL *allow_custom; /* ptr to if custom functions are allowed */ BOOL *allow_custom; /* ptr to if custom functions are allowed */
char *version; /* calc version string */ char *version; /* calc version string */
int baseb; /* base for calculations */
}; };
typedef struct config CONFIG; typedef struct config CONFIG;

6
func.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.25 $ * @(#) $Revision: 29.26 $
* @(#) $Id: func.c,v 29.25 2006/05/21 07:28:54 chongo Exp $ * @(#) $Id: func.c,v 29.26 2006/06/11 00:08:56 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $
* *
* Under source code control: 1990/02/15 01:48:15 * Under source code control: 1990/02/15 01:48:15
@@ -871,7 +871,7 @@ f_nextcand(int count, NUMBER **vals)
ans->num = tmp; ans->num = tmp;
return ans; return ans;
} }
return qlink(&_qzero_);; return qlink(&_qzero_);
} }

5
hash.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.8 $ * @(#) $Revision: 29.9 $
* @(#) $Id: hash.c,v 29.8 2006/05/19 15:26:10 chongo Exp $ * @(#) $Id: hash.c,v 29.9 2006/06/06 07:17:02 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/hash.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/hash.c,v $
* *
* Under source code control: 1995/11/23 05:13:11 * Under source code control: 1995/11/23 05:13:11
@@ -995,6 +995,7 @@ hash_value(int type, void *v, HASH *state)
state = hash_bool(type, FALSE, state); state = hash_bool(type, FALSE, state);
} }
state = hash_str(type, value->v_config->version, state); state = hash_str(type, value->v_config->version, state);
state = hash_int(type, value->v_config->baseb, state);
break; break;
case V_HASH: case V_HASH:

View File

@@ -38,7 +38,7 @@ DESCRIPTION
&X with that component or element depends only on the continued existence &X with that component or element depends only on the continued existence
of the matrix or object. For example, after of the matrix or object. For example, after
> mat A[3] ; mat A[3]
the addresses &A[0], &A[1], &A[2] locate the three elements the addresses &A[0], &A[1], &A[2] locate the three elements
of the matrix specified by A until another value is assigned to A, etc. of the matrix specified by A until another value is assigned to A, etc.
@@ -60,15 +60,15 @@ DESCRIPTION
results refer to octets in the same block or existing components of the results refer to octets in the same block or existing components of the
same matrix or object. For example, immediately after same matrix or object. For example, immediately after
> mat A[10] ; mat A[10]
> p = &A[5] ; p = &A[5]
it is permitted to use expressions like p + 4, p - 5, p++ . it is permitted to use expressions like p + 4, p - 5, p++ .
Strings defined literally have fixed addresses, e.g., after Strings defined literally have fixed addresses, e.g., after
> p = &"abc" ; p = &"abc"
> A = "abc" ; A = "abc"
the address &*A of the value of A will be equal to p. the address &*A of the value of A will be equal to p.
@@ -78,7 +78,7 @@ DESCRIPTION
be useable only while the variables retain these defined values. be useable only while the variables retain these defined values.
For example, after For example, after
> B = C = strcat("a", "bc"); ; B = C = strcat("a", "bc");
&*B and &*C will be different. If p is defined by p = &*B, p should &*B and &*C will be different. If p is defined by p = &*B, p should
not be used after a new value is assigned to B, or B ceases to exist, not be used after a new value is assigned to B, or B ceases to exist,
@@ -91,9 +91,9 @@ DESCRIPTION
so long as the number remains associated with at least one function or so long as the number remains associated with at least one function or
lvalue. For example, after lvalue. For example, after
> x = 27; ; x = 27;
> y = 3 * 9; ; y = 3 * 9;
> define f(a) = 27 + a; ; define f(a) = 27 + a;
the three occurrences of 27 have the same address which may be displayed the three occurrences of 27 have the same address which may be displayed
by any of &27, &*x, &*y and &f(0). If x and y are assigned by any of &27, &*x, &*y and &f(0). If x and y are assigned
@@ -109,13 +109,13 @@ DESCRIPTION
non-zero value for a will be assigned to different addresses as can be non-zero value for a will be assigned to different addresses as can be
seen from printing &*A, &*B, &*C after seen from printing &*A, &*B, &*C after
> A = f(2); B = f(2); C = f(2); ; A = f(2); B = f(2); C = f(2);
(the case of f(0) is exceptional since 27 + 0 simply copies the 27 (the case of f(0) is exceptional since 27 + 0 simply copies the 27
rather than creating a new number value). Here it is clearly more rather than creating a new number value). Here it is clearly more
efficient to use efficient to use
> A = B = C = f(2); ; A = B = C = f(2);
which, not only performs the addition in f() only once, but stores the which, not only performs the addition in f() only once, but stores the
number values for A, B and C at the same address. number values for A, B and C at the same address.
@@ -160,7 +160,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
dereference, isptr dereference, isptr
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -176,8 +176,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: address,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: address,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/address,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/address,v $
## ##
## Under source code control: 1997/09/06 20:03:34 ## Under source code control: 1997/09/06 20:03:34

View File

@@ -79,11 +79,11 @@ DESCRIPTION
sufficient memory allocated for the copying. For example, to copy sufficient memory allocated for the copying. For example, to copy
a matrix M of size 100 to a newly created list, one may use: a matrix M of size 100 to a newly created list, one may use:
L = makelist(100); ; L = makelist(100);
copy(M, L); ; copy(M, L);
or: or:
L = makelist(100); ; L = makelist(100);
blkcpy(L, M); ; blkcpy(L, M);
For copying from a block B (named or unnamed), the total number of octets For copying from a block B (named or unnamed), the total number of octets
available for copying is taken to the the datalen for that block, available for copying is taken to the the datalen for that block,
@@ -114,7 +114,6 @@ EXAMPLE
; B ; B
chunksize = 256, maxsize = 256, datalen = 4 chunksize = 256, maxsize = 256, datalen = 4
01020304 01020304
>
; blkcpy(B,A) ; blkcpy(B,A)
; B ; B
chunksize = 256, maxsize = 256, datalen = 8 chunksize = 256, maxsize = 256, datalen = 8
@@ -191,7 +190,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
blk, mat, file, list, str blk, mat, file, list, str
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -207,8 +206,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: blkcpy,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: blkcpy,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blkcpy,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blkcpy,v $
## ##
## Under source code control: 1997/04/05 14:08:50 ## Under source code control: 1997/04/05 14:08:50

View File

@@ -13,9 +13,9 @@ DESCRIPTION
may occur when activity is resumed by an fg command after a ctrl-Z may occur when activity is resumed by an fg command after a ctrl-Z
interrupt, or by any of the three commands: interrupt, or by any of the three commands:
> !stty echo ; !stty echo
> !stty -cbreak ; !stty -cbreak
> !stty echo -cbreak ; !stty echo -cbreak
EXAMPLE EXAMPLE
; calc_tty(); ; calc_tty();
@@ -26,7 +26,7 @@ LIBRARY
SEE ALSO SEE ALSO
none none
## Copyright (C) 2000 Ernest Bowen ## Copyright (C) 2000-2006 Ernest Bowen
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -42,8 +42,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.2 $ ## @(#) $Revision: 29.3 $
## @(#) $Id: calc_tty,v 29.2 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: calc_tty,v 29.3 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $
## ##
## Under source code control: 2000/12/14 01:33:00 ## Under source code control: 2000/12/14 01:33:00

View File

@@ -157,7 +157,6 @@ Command sequence
more information. more information.
abort abort
----- -----
abort abort
@@ -240,7 +239,6 @@ Command sequence
=-= =-=
more information about abort and quit more information about abort and quit
===================================== =====================================
@@ -291,7 +289,7 @@ Command sequence
after statment #1 after statment #1
start statment #2 start statment #2
abort from a() abort from a()
> <==== calc interactive prompt ; <==== calc interactive prompt
because the '-i' calc causes ABORT to drop into an because the '-i' calc causes ABORT to drop into an
interactive prompt. However typing a QUIT or ABORT interactive prompt. However typing a QUIT or ABORT
@@ -321,21 +319,21 @@ Command sequence
If one were to type in the contents of myfile.cal interactively, If one were to type in the contents of myfile.cal interactively,
calc will produce: calc will produce:
> print "start of myfile.cal"; ; print "start of myfile.cal";
start of myfile.cal start of myfile.cal
> define q() {quit "quit from q()"; print "end of q()"} ; define q() {quit "quit from q()"; print "end of q()"}
q() defined q() defined
> define a() {abort "abort from a()"} ; define a() {abort "abort from a()"}
a() defined a() defined
> x = 3; ; x = 3;
> {print "start #1"; if (x > 1) q()} print "after #1"; ; {print "start #1"; if (x > 1) q()} print "after #1";
start statment #1 start statment #1
quit from q() quit from q()
after statment #1 after statment #1
> {print "start #2"; if (x > 1) a()} print "after #2"; ; {print "start #2"; if (x > 1) a()} print "after #2";
start statment #2 start statment #2
abort from a() abort from a()
> {print "start #3"; if (x > 1) quit "quit from 3rd statement"} ; {print "start #3"; if (x > 1) quit "quit from 3rd statement"}
start #3 start #3
quit from 3rd statement quit from 3rd statement
@@ -345,16 +343,14 @@ Command sequence
The QUIT (after the if (x > 1) ...) will cause calc to exit The QUIT (after the if (x > 1) ...) will cause calc to exit
because it was given at the interactive prompt level. because it was given at the interactive prompt level.
=-= =-=
Also see the help topic: Also see the help topic:
statement flow control and declaration statements statement flow control and declaration statements
usage how to invoke the calc command and calc -options usage how to invoke the calc command and calc -options
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -370,8 +366,8 @@ Command sequence
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: command,v 29.3 2006/05/20 10:01:33 chongo Exp $ ## @(#) $Id: command,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/command,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/command,v $
## ##
## Under source code control: 1991/07/21 04:37:17 ## Under source code control: 1991/07/21 04:37:17

View File

@@ -1,12 +1,24 @@
Configuration parameters NAME
config - configuration parameters
Configuration parameters affect how the calculator performs certain SYNOPSIS
config(parameter [,value])
TYPES
parameter string
value int, string, config state
return config state
DESCRIPTION
The config() builtin affects how the calculator performs certain
operations. Among features that are controlled by these parameters operations. Among features that are controlled by these parameters
are the accuracy of some calculations, the displayed format of results, are the accuracy of some calculations, the displayed format of results,
the choice from possible alternative algorithms, and whether or not the choice from possible alternative algorithms, and whether or not
debugging information is displayed. The parameters are debugging information is displayed. The parameters are
read or set using the "config" built-in function; they remain in effect read or set using the "config" built-in function; they remain in effect
until their values are changed by a config or equivalent instruction. until their values are changed by a config or equivalent instruction.
The following parameters can be specified: The following parameters can be specified:
"all" all configuration values listed below "all" all configuration values listed below
@@ -53,6 +65,7 @@ Configuration parameters
"compile_custom" TRUE=>calc was compiled with custom functions "compile_custom" TRUE=>calc was compiled with custom functions
"allow_custom" TRUE=>custom functions are enabled "allow_custom" TRUE=>custom functions are enabled
"version" Read-only calc version "version" Read-only calc version
"baseb" bits in calculation base, a read-only value
The "all" config value allows one to save/restore the configuration The "all" config value allows one to save/restore the configuration
set of values. The return of: set of values. The return of:
@@ -120,9 +133,6 @@ Configuration parameters
config("tilde", 0) disable roundoff tilde printing config("tilde", 0) disable roundoff tilde printing
config("tab", "off") disable leading tab printing config("tab", "off") disable leading tab printing
Detailed config descriptions
=-= =-=
config("trace", bitflag) config("trace", bitflag)
@@ -258,12 +268,32 @@ Detailed config descriptions
the maximum value is very large. If 2 is used, then the recursive the maximum value is very large. If 2 is used, then the recursive
algorithm is used all the way down to single digits, which becomes algorithm is used all the way down to single digits, which becomes
slow since the recursion overhead is high. If a number such as slow since the recursion overhead is high. If a number such as
1000000 is used, then the recursive algorithm is never used, causing 1000000 is used, then the recursive algorithm is almost never used,
calculations for large numbers to slow down. For a typical example causing calculations for large numbers to slow down.
on a 386, the two algorithms are about equal in speed for a value
of 20, which is about 100 decimal digits. A value of zero resets Units refer to internal calculation digits where each digit
the parameter back to its default value. Usually there is no need is BASEB bits in length. The value of BASEB is returned by
to change these parameters. config("baseb").
The default value for config("sq2") is 3388. This default was
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
the two algorithms are about equal in speed. For that CPU test,
config("baseb") was 32. This means that by default numbers up to
(3388*32)+31 = 108447 bits in length (< 32645 decinal digits) use
the 1st algorithm, for squaring.
The default value for config("mul2") is 1780. This default was
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
the two algorithms are about equal in speed. For that CPU test,
config("baseb") was 32. This means that by default numbers up to
(1779*32)+31 = 56927 bits in length (< 17137 decinal digits) use
the 1st algorithm, for multiplication.
A value of zero resets the parameter back to their default values.
The value of 1 and values < 0 are reserved for future use.
Usually there is no need to change these parameters.
=-= =-=
@@ -277,6 +307,23 @@ Detailed config descriptions
which avoids divisions. The argument for pow2 is the size of the which avoids divisions. The argument for pow2 is the size of the
modulus at which the second algorithm begins to be used. modulus at which the second algorithm begins to be used.
Units refer to internal calculation digits where each digit
is BASEB bits in length. The value of BASEB is returned by
config("baseb").
The default value for config("pow2") is 176. This default was
established on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS when
the two algorithms are about equal in speed. For that CPU test,
config("baseb") was 32. This means that by default numbers up to
(176*32)+31 = 5663 bits in length (< 1704 decinal digits) use the
1st algorithm, for calculating powers modulo another number.
A value of zero resets the parameter back to their default values.
The value of 1 and values < 0 are reserved for future use.
Usually there is no need to change these parameters.
=-= =-=
config("redc2", int) config("redc2", int)
@@ -289,6 +336,23 @@ Detailed config descriptions
O(N^1.585). The argument for redc2 is the size of the modulus at O(N^1.585). The argument for redc2 is the size of the modulus at
which the second algorithm begins to be used. which the second algorithm begins to be used.
Units refer to internal calculation digits where each digit
is BASEB bits in length. The value of BASEB is returned by
config("baseb").
The default value for config("redc2") is 220. This default was
established as 5/4 (the historical ratio of config("pow2") to
config("pow2")) of the config("pow2") value. This means that if
config("baseb") is 32, then by default numbers up to (220*32)+31 =
7071 bits in length (< 2128 decinal digits) use the REDC algorithm,
for calculating powers modulo another number.
A value of zero resets the parameter back to their default values.
The value of 1 and values < 0 are reserved for future use.
Usually there is no need to change these parameters.
=-= =-=
config("tilde", boolean) config("tilde", boolean)
@@ -560,11 +624,12 @@ Detailed config descriptions
3 During execution, allow calc standard resource files 3 During execution, allow calc standard resource files
to output additional debugging information. to output additional debugging information.
The value for config("resource_debug") in both oldstd and newstd is 3, The value for config("resource_debug") in both oldstd and newstd
but if calc is invoked with the -d flag, its initial value is zero. is 3, but if calc is invoked with the -d flag, its initial value
Thus, if calc is started without the -d flag, until config("resource_debug") is zero. Thus, if calc is started without the -d flag, until
is changed, a message will be output when a function is defined config("resource_debug") is changed, a message will be output when
either interactively or during the reading of a file. a function is defined either interactively or during the reading of
a file.
The name config("lib_debug") is equivalent to config("resource_debug") The name config("lib_debug") is equivalent to config("resource_debug")
and is included for backward compatibility. and is included for backward compatibility.
@@ -601,7 +666,7 @@ Detailed config descriptions
A quit of abort without an argument does not display a message when A quit of abort without an argument does not display a message when
invoked at the interactive level. invoked at the interactive level.
By deafult, "verbose_quit" is false. By default, "verbose_quit" is false.
=-= =-=
@@ -756,7 +821,95 @@ Detailed config descriptions
This config parameter is read-only and cannot be set. This config parameter is read-only and cannot be set.
## Copyright (C) 1999 Landon Curt Noll =-=
config("baseb") <== NOTE: This is a read-only config value
Returns the number of bits in the fundamental base in which
internal calculations are performed. For example, a value of
32 means that calc will perform many internal calculations in
base 2^32 with digits that are 32 bits in length.
For libcalc programmers, this is the value of BASEB as defined
in the zmath.h header file.
This config parameter is read-only and cannot be set.
EXAMPLE
; current_cfg = config("all");
; config("tilde", off),;
; config("calc_debug", 15),;
; config("all") == current_cfg
0
; config("all", current_cfg),;
; config("all") == current_cfg
1
; config("version")
"2.12.0"
; config("all")
mode "real"
mode2 "off"
display 20
epsilon 0.00000000000000000001
trace 0
maxprint 16
mul2 20
sq2 20
pow2 40
redc2 50
tilde 1
tab 1
quomod 0
quo 2
mod 0
sqrt 24
appr 24
cfappr 0
cfsim 8
outround 24
round 24
leadzero 1
fullzero 0
maxscan 20
prompt "; "
more ";; "
blkmaxprint 256
blkverbose 0
blkbase "hexadecimal"
blkfmt "hd_style"
resource_debug 3
lib_debug 3
calc_debug 0
user_debug 0
verbose_quit 0
ctrl_d "virgin_eof"
program "calc"
basename "calc"
windows 0
cygwin 0
compile_custom 1
allow_custom 0
version "2.12.0"
baseb 32
; display()
20
; config("display", 50),;
; display()
50
LIMITS
none
LINK LIBRARY
n/a
SEE ALSO
usage, custom, custom_cal, usage, epsilon, display
## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -772,8 +925,8 @@ Detailed config descriptions
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.10 $ ## @(#) $Revision: 29.15 $
## @(#) $Id: config,v 29.10 2004/07/27 23:45:52 chongo Exp $ ## @(#) $Id: config,v 29.15 2006/06/11 07:22:05 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
## ##
## Under source code control: 1991/07/21 04:37:17 ## Under source code control: 1991/07/21 04:37:17

View File

@@ -30,17 +30,17 @@ DESCRIPTION
For example, suppose a function f and a global variable A have been For example, suppose a function f and a global variable A have been
defined by: defined by:
define f(x) = (x = 3); ; define f(x) = (x = 3);
global mat A[3]; ; global mat A[3];
If g() is a function that evaluates to 2: If g() is a function that evaluates to 2:
f(A[g()]); ; f(A[g()]);
assigns the value of A[2] to the parameter x and then assigns the assigns the value of A[2] to the parameter x and then assigns the
value 3 to x: value 3 to x:
f(`A[g()]); ; f(`A[g()]);
has essentially the effect of assigning A[2] as an lvalue to x and has essentially the effect of assigning A[2] as an lvalue to x and
then assigning the value 3 to A[2]. (Very old versions of calc then assigning the value 3 to A[2]. (Very old versions of calc
@@ -79,7 +79,7 @@ DESCRIPTION
If the expr is omitted from an expression definition, as in: If the expr is omitted from an expression definition, as in:
define h() = ; ; define h() = ;
any call to the function will evaluate the arguments and return the any call to the function will evaluate the arguments and return the
null value. null value.
@@ -105,11 +105,11 @@ DESCRIPTION
After fname has been defined, the definition may be removed by the command: After fname has been defined, the definition may be removed by the command:
undefine fname ; undefine fname
The definitions of all user-defined functions may be removed by: The definitions of all user-defined functions may be removed by:
undefine * ; undefine *
If bit 0 of config("resource_debug") is set and the define command is If bit 0 of config("resource_debug") is set and the define command is
at interactive level, a message saying that fname has been defined at interactive level, a message saying that fname has been defined
@@ -120,8 +120,8 @@ DESCRIPTION
The identifiers used for the parameters in a function definition do The identifiers used for the parameters in a function definition do
not form part of the completed definition. For example, not form part of the completed definition. For example,
define f(a,b) = a + b; ; define f(a,b) = a + b;
define g(alpha, beta) = alpha + beta; ; define g(alpha, beta) = alpha + beta;
result in identical code for the functions f, g. result in identical code for the functions f, g.
@@ -129,8 +129,8 @@ DESCRIPTION
function are displayed on completion of its definition, parameters function are displayed on completion of its definition, parameters
being specified by names used in the definition. For example: being specified by names used in the definition. For example:
> config("trace", 8), ; config("trace", 8),
> define f(a,b) = a + b ; define f(a,b) = a + b
0: PARAMADDR a 0: PARAMADDR a
2: PARAMADDR b 2: PARAMADDR b
4: ADD 4: ADD
@@ -140,7 +140,7 @@ DESCRIPTION
The opcodes may also be displayed later using the show opcodes command; The opcodes may also be displayed later using the show opcodes command;
parameters will be specified by indices instead of by names. For example: parameters will be specified by indices instead of by names. For example:
> show opco f ; show opco f
0: PARAMADDR 0 0: PARAMADDR 0
2: PARAMADDR 1 2: PARAMADDR 1
4: ADD 4: ADD
@@ -168,19 +168,19 @@ DESCRIPTION
EXAMPLE EXAMPLE
; define f(a,b) = 2*a + b; ; define f(a,b) = 2*a + b;
; define g(alpha, beta) ; define g(alpha, beta)
>> { ;; {
>> local a, pi2; ;; local a, pi2;
>> ;;
>> pi2 = 2 * pi(); ;; pi2 = 2 * pi();
>> a = sin(alpha % pi2); ;; a = sin(alpha % pi2);
>> if (a > 0.0) { ;; if (a > 0.0) {
>> return a*beta; ;; return a*beta;
>> } ;; }
>> if (beta > 0.0) { ;; if (beta > 0.0) {
>> a *= cos(-beta % pi2); ;; a *= cos(-beta % pi2);
>> } ;; }
>> return a; ;; return a;
>> } ;; }
LIMITS LIMITS
The number of arguments in a function-call cannot exceed 100. The number of arguments in a function-call cannot exceed 100.
@@ -191,7 +191,7 @@ LIBRARY
SEE ALSO SEE ALSO
param, variable, undefine, show param, variable, undefine, show
## Copyright (C) 2000 David I. Bell, Landon Curt Noll and Ernest Bowen ## Copyright (C) 2000-2006 David I. Bell, Landon Curt Noll and Ernest Bowen
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -207,8 +207,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: define,v 29.4 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: define,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $
## ##
## ##

View File

@@ -33,16 +33,17 @@ DESCRIPTION
structure rather than the structure identified by X. For example, structure rather than the structure identified by X. For example,
suppose B has been created by suppose B has been created by
mat B[3] = {1,2,3} ; mat B[3] = {1,2,3}
then then
A = *B = {4,5,6}
; A = *B = {4,5,6}
will assign the values 4,5,6 to the elements of a copy of B, which will assign the values 4,5,6 to the elements of a copy of B, which
will then become the value of A, so that the values of A and B will will then become the value of A, so that the values of A and B will
be different. On the other hand, be different. On the other hand,
A = B = {4,5,6} ; A = B = {4,5,6}
will result in A and B having the same value. will result in A and B having the same value.
@@ -51,9 +52,9 @@ DESCRIPTION
The * operator may be iterated with suitable sequences of pointer-valued The * operator may be iterated with suitable sequences of pointer-valued
lvalues. For example, after lvalues. For example, after
> global a, b, c; ; global a, b, c;
> b = &a; ; b = &a;
> c = &b; ; c = &b;
**c returns the lvalue a; ***c returns the value of a. **c returns the lvalue a; ***c returns the value of a.
@@ -81,7 +82,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
address, isptr address, isptr
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -97,8 +98,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: dereference,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: dereference,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/dereference,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/dereference,v $
## ##
## Under source code control: 1997/09/06 20:03:34 ## Under source code control: 1997/09/06 20:03:34

View File

@@ -28,11 +28,11 @@ DESCRIPTION
left of the "decimal" point; the digit d_n at position n contributes left of the "decimal" point; the digit d_n at position n contributes
additively d_n * b^n to the value of x. For example, additively d_n * b^n to the value of x. For example,
d_2 d_1 d_0 . d_-1 d_-2 ; d_2 d_1 d_0 . d_-1 d_-2
represents the number represents the number
d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2 ; d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
The sequence of digits has to be infinite if den(x) has a prime factor The sequence of digits has to be infinite if den(x) has a prime factor
which is not a factor of the base b. In cases where the representation which is not a factor of the base b. In cases where the representation
@@ -53,30 +53,30 @@ DESCRIPTION
With base-b digits for x as explained above, the integer whose base-b With base-b digits for x as explained above, the integer whose base-b
representation is representation is
b_n+k-1 b_n_k-2 ... b_n, ; b_n+k-1 b_n_k-2 ... b_n,
i.e. the k digits with last digit b_n, is given by i.e. the k digits with last digit b_n, is given by
digit(b^-r * x, q, b^k) ; digit(b^-r * x, q, b^k)
if r and q satisfy n = q * b + r. if r and q satisfy n = q * b + r.
EXAMPLE EXAMPLE
> a = 123456.789 ; a = 123456.789
> for (n = 6; n >= -6; n++) print digit(a, n),; print ; for (n = 6; n >= -6; n++) print digit(a, n),; print
0 1 2 3 4 5 6 7 8 9 0 0 0 0 1 2 3 4 5 6 7 8 9 0 0 0
> for (n = 6; n >= -6; n--) print digit(a, n, 100),; print ; for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
0 0 0 0 12 34 56 78 90 0 0 0 0 0 0 0 0 12 34 56 78 90 0 0 0 0
> for (n = 6; n >= -6; n--) print digit(a, n, 256),; print ; for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
0 0 0 0 1 226 64 201 251 231 108 139 67 0 0 0 0 1 226 64 201 251 231 108 139 67
> for (n = 1; n >= -12; n++) print digit(10/7, n),; print ; for (n = 1; n >= -12; n++) print digit(10/7, n),; print
> 0 1 4 2 8 5 7 1 4 2 8 5 7 1 ; 0 1 4 2 8 5 7 1 4 2 8 5 7 1
> print digit(10/7, -7e1000, 1e6) ; print digit(10/7, -7e1000, 1e6)
428571 428571
LIMITS LIMITS
@@ -92,7 +92,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
bit bit
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -108,8 +108,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: digit,v 29.4 2000/12/17 12:27:58 chongo Exp $ ## @(#) $Id: digit,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digit,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digit,v $
## ##
## Under source code control: 1995/10/03 10:40:01 ## Under source code control: 1995/10/03 10:40:01

View File

@@ -21,7 +21,6 @@ Environment variables
The CALCBINDINGS file searches the CALCPATH as well. The CALCBINDINGS file searches the CALCPATH as well.
CALCRC CALCRC
On startup (unless -h or -q was given on the command On startup (unless -h or -q was given on the command
@@ -105,8 +104,8 @@ Environment variables
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: environment,v 29.4 2006/05/07 07:22:20 chongo Exp $ ## @(#) $Id: environment,v 29.5 2006/06/10 13:01:09 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/environment,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/environment,v $
## ##
## Under source code control: 1991/07/23 05:47:25 ## Under source code control: 1991/07/23 05:47:25

View File

@@ -31,7 +31,7 @@ EXAMPLE
; fgetfield(f) ; fgetfield(f)
"Beta" "Beta"
; fgetfield(f) ; fgetfield(f)
>
; freopen(f, "w") ; freopen(f, "w")
; fputstr(f, " Alpha ", "Beta") ; fputstr(f, " Alpha ", "Beta")
; freopen(f, "r") ; freopen(f, "r")
@@ -51,7 +51,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
fgetstr, fputstr, fgets, fputs, fopen, files, fprintf fgetstr, fputstr, fgets, fputs, fopen, files, fprintf
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -67,8 +67,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: fgetfield,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: fgetfield,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetfield,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetfield,v $
## ##
## Under source code control: 1996/04/30 03:05:17 ## Under source code control: 1996/04/30 03:05:17

View File

@@ -36,7 +36,6 @@ EXAMPLE
"Gamma "Gamma
Delta" Delta"
; fgetstr(f) ; fgetstr(f)
>
LIMITS LIMITS
none - XXX - is this correct? none - XXX - is this correct?
@@ -47,7 +46,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
fputstr, fgetword, fgets, fputs, fopen, files, fprintf fputstr, fgetword, fgets, fputs, fopen, files, fprintf
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -63,8 +62,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: fgetstr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: fgetstr,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetstr,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetstr,v $
## ##
## Under source code control: 1996/04/30 03:05:17 ## Under source code control: 1996/04/30 03:05:17

View File

@@ -29,16 +29,16 @@ DESCRIPTION
is assumed to be an open file opened in an unknown mode. Calc is assumed to be an open file opened in an unknown mode. Calc
will try to read and write to this file when directed. will try to read and write to this file when directed.
Consider the following commands: Consider the following commands shell commands:
$ echo "A line of text in the file on descriptor 5" > datafile echo "A line of text in the file on descriptor 5" > datafile
$ calc 5<datafile calc 5<datafile
then one could do the following: then one could do the following:
> files(5) ; files(5)
FILE 5 "descriptor[5]" (unknown_mode, pos 0) FILE 5 "descriptor[5]" (unknown_mode, pos 0)
> fgetline(files(5)) ; fgetline(files(5))
"A line of text in the file on descriptor 5" "A line of text in the file on descriptor 5"
EXAMPLE EXAMPLE
@@ -68,7 +68,7 @@ SEE ALSO
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -84,8 +84,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: files,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: files,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/files,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/files,v $
## ##
## Under source code control: 1995/03/04 11:33:19 ## Under source code control: 1995/03/04 11:33:19

View File

@@ -26,7 +26,7 @@ EXAMPLE
; fgetstr(f) ; fgetstr(f)
"Beta" "Beta"
; fgetstr(f) ; fgetstr(f)
>
; fputstr(f, "Gamma") ; fputstr(f, "Gamma")
Error 72 Error 72
@@ -39,7 +39,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -55,8 +55,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: fputstr,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: fputstr,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputstr,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputstr,v $
## ##
## Under source code control: 1996/04/30 03:05:18 ## Under source code control: 1996/04/30 03:05:18

View File

@@ -19,7 +19,6 @@ EXAMPLE
1 2 15 1 2 15
; freeredc() ; freeredc()
; show redc ; show redc
>
LIMITS LIMITS
none none
@@ -30,7 +29,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
free, freeglobals, freestatics free, freeglobals, freestatics
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -46,8 +45,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: freeredc,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: freeredc,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeredc,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeredc,v $
## ##
## Under source code control: 1997/09/06 20:03:35 ## Under source code control: 1997/09/06 20:03:35

View File

@@ -26,21 +26,21 @@ DESCRIPTION
double-bracket index of the item found. double-bracket index of the item found.
EXAMPLE EXAMPLE
> mat M[2,3,1:5] ; mat M[2,3,1:5]
> indices(M, 11) ; indices(M, 11)
list (3 elements, 2 nonzero): list (3 elements, 2 nonzero):
[[0]] = 0 [[0]] = 0
[[1]] = 2 [[1]] = 2
[[2]] = 2 [[2]] = 2
> A = assoc(); ; A = assoc();
> A["cat", "dog"] = "fight"; ; A["cat", "dog"] = "fight";
> A[2,3,5,7] = "primes"; ; A[2,3,5,7] = "primes";
> A["square", 3] = 9 ; A["square", 3] = 9
> indices(A, search(A, "primes")) ; indices(A, search(A, "primes"))
list (4 elements, 4 nonzero): list (4 elements, 4 nonzero):
[[0]] = 2 [[0]] = 2
[[1]] = 3 [[1]] = 3
@@ -57,7 +57,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
assoc, mat assoc, mat
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -73,8 +73,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.2 $ ## @(#) $Revision: 29.3 $
## @(#) $Id: indices,v 29.2 2000/06/07 14:02:33 chongo Exp $ ## @(#) $Id: indices,v 29.3 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/indices,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/indices,v $
## ##
## Under source code control: 1999/11/16 08:02:03 ## Under source code control: 1999/11/16 08:02:03

View File

@@ -42,8 +42,8 @@ ABORT opcodes
the calculation is never completed and to stop it, an interruption the calculation is never completed and to stop it, an interruption
(on many systems, by ctrl-C) will be necessary. (on many systems, by ctrl-C) will be necessary.
> config("trace", 8), ; config("trace", 8),
> define f(x) {local s; while (x) {s += x--} return s} ; define f(x) {local s; while (x) {s += x--} return s}
0: DEBUG line 2 0: DEBUG line 2
2: PARAMADDR x 2: PARAMADDR x
4: JUMPZ 19 4: JUMPZ 19
@@ -68,7 +68,7 @@ ABORT opcodes
{s += x--} loop. In interactive mode, with ^C indicating {s += x--} loop. In interactive mode, with ^C indicating
input of ctrl-C, the displayed output is as in: input of ctrl-C, the displayed output is as in:
> f(-1) ; f(-1)
^C ^C
[Abort level 1] [Abort level 1]
"f": line 2: Calculation aborted at statement boundary "f": line 2: Calculation aborted at statement boundary
@@ -77,7 +77,7 @@ ABORT opcodes
Changing config("trace") to achieve this, and defining g(x) with Changing config("trace") to achieve this, and defining g(x) with
the same definition as for f(x) gives: the same definition as for f(x) gives:
> define g(x) {local s; while (x) {s += x--} return s} ; define g(x) {local s; while (x) {s += x--} return s}
0: PARAMADDR x 0: PARAMADDR x
2: JUMPZ 15 2: JUMPZ 15
4: LOCALADDR s 4: LOCALADDR s
@@ -94,13 +94,15 @@ ABORT opcodes
If g(-1) is called, two interrupts are necessary, as in: If g(-1) is called, two interrupts are necessary, as in:
> g(-1) ; g(-1)
^C ^C
[Abort level 1] [Abort level 1]
^C ^C
[Abort level 2] [Abort level 2]
"g": Calculation aborted in opcode "g": Calculation aborted in opcode
## Copyright (C) 1999-2006 David I. Bell, Landon Curt Noll and Ernest Bowen
##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
## as published by the Free Software Foundation. ## as published by the Free Software Foundation.
@@ -115,8 +117,8 @@ ABORT opcodes
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: interrupt,v 29.4 2000/07/17 15:38:52 chongo Exp $ ## @(#) $Id: interrupt,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/interrupt,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/interrupt,v $
## ##
## Under source code control: 1991/07/21 04:37:21 ## Under source code control: 1991/07/21 04:37:21

View File

@@ -23,12 +23,12 @@ DESCRIPTION
strings and real numbers. strings and real numbers.
EXAMPLE EXAMPLE
> a = "abc", b = 3, B = blk() ; a = "abc", b = 3, B = blk()
> p1 = &B[1] ; p1 = &B[1]
> p2 = &a ; p2 = &a
> p3 = &*a ; p3 = &*a
> p4 = &*b ; p4 = &*b
> print isptr(a), isptr(p1), isptr(p2), isptr(p3), isptr(p4) ; print isptr(a), isptr(p1), isptr(p2), isptr(p3), isptr(p4)
0 1 2 3 4 0 1 2 3 4
LIMITS LIMITS
@@ -40,7 +40,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
isnum, isstr, isblk, isoctet isnum, isstr, isblk, isoctet
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -56,8 +56,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.2 $ ## @(#) $Revision: 29.3 $
## @(#) $Id: isptr,v 29.2 2000/06/07 14:02:33 chongo Exp $ ## @(#) $Id: isptr,v 29.3 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isptr,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isptr,v $
## ##
## Under source code control: 1997/09/06 20:03:35 ## Under source code control: 1997/09/06 20:03:35

View File

@@ -16,6 +16,15 @@ DESCRIPTION
return 1, otherwise return 0. return 1, otherwise return 0.
Note that issq() works on rational values, so:
issq(25/16) == 1
If you want to test for prefect square integers, you need to exclude
non-integer values before you test:
isint(curds) && issq(curds)
EXAMPLE EXAMPLE
; print issq(25), issq(3), issq(0) ; print issq(25), issq(3), issq(0)
1 0 1 1 0 1
@@ -52,8 +61,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: issq,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: issq,v 29.4 2006/06/04 21:12:23 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issq,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issq,v $
## ##
## Under source code control: 1994/10/21 02:21:31 ## Under source code control: 1994/10/21 02:21:31

View File

@@ -79,10 +79,10 @@ DESCRIPTION
simple assignments, as in A[0,0] = 1, A[0,2] = 2; simple assignments, as in A[0,0] = 1, A[0,2] = 2;
If the index-range is left blank but an initializer list is specified If the index-range is left blank but an initializer list is specified
as in as in:
mat A[] = {1, 2 } ; mat A[] = {1, 2 }
B = mat[] = {1, , 3, } ; B = mat[] = {1, , 3, }
the matrix created is one-dimensional. If the list contains a the matrix created is one-dimensional. If the list contains a
positive number n of values or blanks, the result is as if the positive number n of values or blanks, the result is as if the
@@ -93,10 +93,12 @@ DESCRIPTION
If the index-range is left blank and no initializer list is specified, If the index-range is left blank and no initializer list is specified,
as in mat C[] or C = mat[], the matrix assigned to C has zero as in mat C[] or C = mat[], the matrix assigned to C has zero
dimension; this has one element C[]. To assign a value using "= { ...}" dimension; this has one element C[].
at the same time as creating C, parentheses are required as in
(mat[]) = {value} or (mat C[]) = {value}. Later a value may be To assign a value using "= { ...}" at the same time as creating C,
assigned to C[] by C[] = value or C = {value}. parentheses are required as in (mat[]) = {value} or (mat C[]) =
{value}. Later a value may be assigned to C[] by C[] = value or
C = {value}.
The value assigned at any time to any element of a matrix can be of The value assigned at any time to any element of a matrix can be of
any type - number, string, list, matrix, object of previously specified any type - number, string, list, matrix, object of previously specified
@@ -106,10 +108,11 @@ DESCRIPTION
If an element of a matrix is a structure for which indices or an If an element of a matrix is a structure for which indices or an
object element specifier is required, an element of that structure is object element specifier is required, an element of that structure is
referred to by appropriate uses of [ ] or ., and so on if an element referred to by appropriate uses of [ ] or ., and so on if an element
of that element is required. For example, one may have an expressions of that element is required.
like
A[1,2][3].alpha[2]; For example, one may have an expressions like:
; A[1,2][3].alpha[2];
if A[1,2][3].alpha is a list with at least three elements, A[1,2][3] is if A[1,2][3].alpha is a list with at least three elements, A[1,2][3] is
an object of a type like obj {alpha, beta}, A[1,2] is a matrix of an object of a type like obj {alpha, beta}, A[1,2] is a matrix of
@@ -165,7 +168,7 @@ DESCRIPTION
So that when one defines a 2D matrix such as: So that when one defines a 2D matrix such as:
mat X[2,3] = {1,2,3,4,5,6} ; mat X[2,3] = {1,2,3,4,5,6}
then printing X results in: then printing X results in:
@@ -174,7 +177,7 @@ DESCRIPTION
The default printing may be restored by The default printing may be restored by
undefine mat_print; ; undefine mat_print;
The keyword "mat" followed by two or more index-range-lists returns a The keyword "mat" followed by two or more index-range-lists returns a
matrix with indices specified by the first list, whose elements are matrix with indices specified by the first list, whose elements are
@@ -183,11 +186,11 @@ DESCRIPTION
as its value a 3-element matrix. Values may be assigned to the as its value a 3-element matrix. Values may be assigned to the
elements of the innermost matrices by nested = {...} operations as in elements of the innermost matrices by nested = {...} operations as in
mat [2][3] = {{1,2,3},{4,5,6}} ; mat [2][3] = {{1,2,3},{4,5,6}}
An example of the use of mat with a declarator is An example of the use of mat with a declarator is
global mat A B [2,3], C [4] ; global mat A B [2,3], C [4]
This creates, if they do not already exist, three global variables with This creates, if they do not already exist, three global variables with
names A, B, C, and assigns to A and B the value mat[2,3] and to C mat[4]. names A, B, C, and assigns to A and B the value mat[2,3] and to C mat[4].
@@ -344,9 +347,9 @@ DESCRIPTION
in effect they are treated as linear arrays. in effect they are treated as linear arrays.
EXAMPLE EXAMPLE
> obj point {x,y} ; obj point {x,y}
> mat A[5] = {1, 2+3i, "ab", mat[2] = {4,5}, obj point = {6,7}} ; mat A[5] = {1, 2+3i, "ab", mat[2] = {4,5}, obj point = {6,7}}
> A ; A
mat [5] (5 elements, 5 nonzero): mat [5] (5 elements, 5 nonzero):
[0] = 1 [0] = 1
[1] = 2+3i [1] = 2+3i
@@ -354,14 +357,14 @@ EXAMPLE
[3] = mat [2] (2 elements, 2 nonzero) [3] = mat [2] (2 elements, 2 nonzero)
[4] = obj point {6, 7} [4] = obj point {6, 7}
> print A[0], A[1], A[2], A[3][0], A[4].x ; print A[0], A[1], A[2], A[3][0], A[4].x
1 2+3i ab 4 6 1 2+3i ab 4 6
> define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y} ; define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y}
point_add(a,b) defined point_add(a,b) defined
> mat [B] = {8, , "cd", mat[2] = {9,10}, obj point = {11,12}} ; mat [B] = {8, , "cd", mat[2] = {9,10}, obj point = {11,12}}
> A + B ; A + B
mat [5] (5 elements, 5 nonzero): mat [5] (5 elements, 5 nonzero):
[0] = 9 [0] = 9
@@ -370,8 +373,8 @@ EXAMPLE
[3] = mat [2] (2 elements, 2 nonzero) [3] = mat [2] (2 elements, 2 nonzero)
[4] = obj point {17, 19} [4] = obj point {17, 19}
> mat C[2,2] = {1,2,3,4} ; mat C[2,2] = {1,2,3,4}
> C^10 ; C^10
mat [2,2] (4 elements, 4 nonzero): mat [2,2] (4 elements, 4 nonzero):
[0,0] = 4783807 [0,0] = 4783807
@@ -379,7 +382,7 @@ EXAMPLE
[1,0] = 10458075 [1,0] = 10458075
[1,1] = 15241882 [1,1] = 15241882
> C^-10 ; C^-10
mat [2,2] (4 elements, 4 nonzero): mat [2,2] (4 elements, 4 nonzero):
[0,0] = 14884.650390625 [0,0] = 14884.650390625
@@ -387,7 +390,7 @@ EXAMPLE
[1,0] = -10212.9638671875 [1,0] = -10212.9638671875
[1,1] = 4671.6865234375 [1,1] = 4671.6865234375
> mat A[4] = {1,2,3,4}, A * reverse(A); ; mat A[4] = {1,2,3,4}, A * reverse(A);
mat [4] (4 elements, 4 nonzero): mat [4] (4 elements, 4 nonzero):
[0] = 4 [0] = 4
@@ -411,7 +414,7 @@ SEE ALSO
isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp, isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp,
randperm, sort randperm, sort
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -427,8 +430,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.6 $
## @(#) $Id: mat,v 29.4 2005/10/18 10:08:45 chongo Exp $ ## @(#) $Id: mat,v 29.6 2006/06/11 07:25:14 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mat,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mat,v $
## ##
## Under source code control: 1991/07/21 04:37:22 ## Under source code control: 1991/07/21 04:37:22

View File

@@ -44,12 +44,12 @@ EXAMPLE
"triangle side length <= 0" "triangle side length <= 0"
; define area(a,b,c) { ; define area(a,b,c) {
>> local s; ;; local s;
>> if (!(a > 0) || !(b > 0) || !(c > 0)) return e1; ;; if (!(a > 0) || !(b > 0) || !(c > 0)) return e1;
>> s = (a + b + c)/2; ;; s = (a + b + c)/2;
>> if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides"); ;; if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides");
>> return sqrt(s * (s - a) * (s - b) * (s - c)); ;; return sqrt(s * (s - a) * (s - b) * (s - c));
>> } ;; }
"area" defined "area" defined
; A = area(8,2,5); ; A = area(8,2,5);
@@ -86,8 +86,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: newerror,v 29.4 2006/05/21 07:31:46 chongo Exp $ ## @(#) $Id: newerror,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/newerror,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/newerror,v $
## ##
## Under source code control: 1996/04/30 03:39:56 ## Under source code control: 1996/04/30 03:39:56

View File

@@ -32,11 +32,11 @@ DESCRIPTION
EXAMPLE EXAMPLE
; define f() { ; define f() {
>> local n, v = 0; ;; local n, v = 0;
>> for (n = 1; n <= param(0); n++) ;; for (n = 1; n <= param(0); n++)
>> v += param(n)^2; ;; v += param(n)^2;
>> return v; ;; return v;
>> } ;; }
; print f(), f(1), f(1,2), f(1,2,3) ; print f(), f(1), f(1,2), f(1,2,3)
0 1 5 14 0 1 5 14
@@ -50,7 +50,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
argv, command argv, command
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -66,8 +66,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: param,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: param,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/param,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/param,v $
## ##
## Under source code control: 1996/03/12 23:10:01 ## Under source code control: 1996/03/12 23:10:01

View File

@@ -27,7 +27,6 @@ EXAMPLE
? 2 + 3 ? 2 + 3
25 25
? end ? end
>
LIMITS LIMITS
none none
@@ -38,7 +37,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
XXX - fill in XXX - fill in
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -54,8 +53,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: prompt,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: prompt,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prompt,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prompt,v $
## ##
## Under source code control: 1995/12/18 12:34:58 ## Under source code control: 1995/12/18 12:34:58

View File

@@ -55,10 +55,10 @@ DESCRIPTION
For the purposes of this function, the depth of a global or local For the purposes of this function, the depth of a global or local
variable is zero; if A has depth d and the value of A is a list, variable is zero; if A has depth d and the value of A is a list,
matrix, object or association, its elements have depth d + 1. matrix, object or association, its elements have depth d + 1.
For example, after For example, after:
obj point {x,y} ; obj point {x,y}
X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} } ; X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} }
X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1], X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1],
X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x
@@ -85,14 +85,14 @@ DESCRIPTION
Users may define functions that return values with positive status, e.g. Users may define functions that return values with positive status, e.g.
define noassigntovalue(x) {protect(x,1); return x}; ; define noassigntovalue(x) {protect(x,1); return x};
S = noassigntovalue(42); ; S = noassigntovalue(42);
will result in S having the value 42 and no-assign-to protection. will result in S having the value 42 and no-assign-to protection.
By using a backquote with a variable as argument, an even simpler By using a backquote with a variable as argument, an even simpler
function: function:
define noassignto(x) = protect(x, 1); ; define noassignto(x) = protect(x, 1);
gives no-assign-to protection to the variable; i.e. noassignto(`A) gives no-assign-to protection to the variable; i.e. noassignto(`A)
achieves the same as protect(A,1). achieves the same as protect(A,1).
@@ -128,9 +128,9 @@ DESCRIPTION
prevent any change in the content or size of the list. prevent any change in the content or size of the list.
No-relocation protection of a block prevents reallocation of the No-relocation protection of a block prevents reallocation of the
memory used by a block and the freeing of a named block, For example, memory used by a block and the freeing of a named block, For example,
if a block B has maxsize 256, then after if a block B has maxsize 256, then after:
protect(B, 32); ; protect(B, 32);
copy(A, B) will fail if the copying would cause size(B) to equal or copy(A, B) will fail if the copying would cause size(B) to equal or
exceed 256; if B is a named block, blkfree(B) will not be permitted. exceed 256; if B is a named block, blkfree(B) will not be permitted.
@@ -175,9 +175,10 @@ DESCRIPTION
to have positive value. Then code for evaluating a function might to have positive value. Then code for evaluating a function might
include lines like include lines like
if (protect(A) & 1024 && B <= 0) ; if (protect(A) & 1024 && B <= 0) {
return newerror("Prohibited assignment"); ;; return newerror("Prohibited assignment");
A = B; ;; }
; A = B;
When an operation forbidden by a particular bit in the protection When an operation forbidden by a particular bit in the protection
status of A is attempted, an error value is created but unless this status of A is attempted, an error value is created but unless this
@@ -200,75 +201,76 @@ DESCRIPTION
EXAMPLE EXAMPLE
> A = 27 ; A = 27
> protect(A,1) ; protect(A,1)
> A = 45 ; A = 45
> A ; A
27 27
> strerror() ; strerror()
"No-assign-to destination for assign" "No-assign-to destination for assign"
> protect(A,64) ; protect(A,64)
> protect(A) ; protect(A)
65 65
> X = A ; X = A
> X ; X
0 0
> strerror() ; strerror()
"No-assign-from source for assign" "No-assign-from source for assign"
> protect(A,-1) ; protect(A,-1)
> protect(A) ; protect(A)
64 64
> protect(A,4) ; protect(A,4)
> protect(A) ; protect(A)
68 68
> A = "abc" ; A = "abc"
> A ; A
27 27
> strerror() ; strerror()
"No-type-change destination for assign" "No-type-change destination for assign"
> B = 45 ; B = 45
> swap(A,B) ; swap(A,B)
Error 10372 Error 10372
> strerror() ; strerror()
"No-assign-to-or-from argument for swap" "No-assign-to-or-from argument for swap"
> protect(A,-64) ; protect(A,-64)
> protect(A) ; protect(A)
4 4
> swap(A,B) ; swap(A,B)
> A ; A
45 45
> B ; B
27 27
> A = mat[4] = {1,2,3,4} ; A = mat[4] = {1,2,3,4}
> B = list(5,6,7,8) ; B = list(5,6,7,8)
> protect(A,16) ; protect(A,16)
> copy(B,A) ; copy(B,A)
Error 10226 Error 10226
> strerror() ; strerror()
"No-copy-to destination variable" "No-copy-to destination variable"
> A = list(1,2,3) ; A = list(1,2,3)
> protect(A,32) ; protect(A,32)
< append(A,4) ; append(A,4)
Error 10402 Error 10402
> strerror() ; strerror()
"No-relocate for list append" "No-relocate for list append"
> A = blk(0,5) ; A = blk(0,5)
> copy("abc", A) ; copy("abc", A)
> copy("de",A) ; copy("de",A)
Error 10229 Error 10229
> strerror() ; strerror()
"No-relocate destination variable" "No-relocate destination variable"
> A = blk("alpha") = {1,2,3,4,5} ; A = blk("alpha") = {1,2,3,4,5}
> protect(A,0) ; protect(A,0)
< protect(*A, 16) ; protect(*A, 16)
< copy("abc", A) ; copy("abc", A)
Error 10228 Error 10228
> strerror() ; strerror()
"No-copy-to destination named block" "No-copy-to destination named block"
LIMITS LIMITS
none none
@@ -278,7 +280,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
assign, copy, blk, error, errno, strerror assign, copy, blk, error, errno, strerror
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -294,8 +296,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.4 $ ## @(#) $Revision: 29.5 $
## @(#) $Id: protect,v 29.4 2006/05/19 15:12:57 chongo Exp $ ## @(#) $Id: protect,v 29.5 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/protect,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/protect,v $
## ##
## Under source code control: 1997/07/10 22:38:44 ## Under source code control: 1997/07/10 22:38:44

View File

@@ -28,9 +28,9 @@ LINK LIBRARY
none none
SEE ALSO SEE ALSO
ctime ctime, time
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -46,8 +46,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: runtime,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: runtime,v 29.4 2006/06/04 18:24:33 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/runtime,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/runtime,v $
## ##
## Under source code control: 1996/03/12 23:10:01 ## Under source code control: 1996/03/12 23:10:01

View File

@@ -18,19 +18,18 @@ DESCRIPTION
One kind of use is to slow down output to permit easier reading of One kind of use is to slow down output to permit easier reading of
results, as in: results, as in:
> for (i = 0; i < 100; i++) { ; for (i = 0; i < 100; i++) {
print sqrt(i); ;; print sqrt(i);
sleep(1/2); ;; sleep(1/2);
} ;; }
The following illustrates what happens if ctrl-C is hit 5 seconds The following illustrates what happens if ctrl-C is hit 5 seconds
after the first command: after the first command:
> print sleep(20) ; print sleep(20)
[Abort level 1] [Abort level 1]
15 15
>
EXAMPLE EXAMPLE
; sleep(1/3); ; sleep(1/3);
@@ -42,7 +41,7 @@ LIBRARY
SEE ALSO SEE ALSO
none none
## Copyright (C) 2000 Ernest Bowen ## Copyright (C) 2000-2006 Ernest Bowen
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -58,8 +57,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.3 $ ## @(#) $Revision: 29.4 $
## @(#) $Id: sleep,v 29.3 2006/05/07 07:25:46 chongo Exp $ ## @(#) $Id: sleep,v 29.4 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $
## ##
## Under source code control: 2000/12/14 01:33:00 ## Under source code control: 2000/12/14 01:33:00

View File

@@ -35,14 +35,14 @@ DESCRIPTION
Error-value or other types: never Error-value or other types: never
EXAMPLE EXAMPLE
> print test(27), test(0), test("abc"), test("") ; print test(27), test(0), test("abc"), test("")
1 0 1 0 1 0 1 0
> print test(mat[3] = {1,,2}), test(mat[2][2]) ; print test(mat[3] = {1,,2}), test(mat[2][2])
1 0 1 0
> A = list(0, 2, 0) ; A = list(0, 2, 0)
> print test(A), test(pop(A)), test(A), test(pop(A)), test(A) ; print test(A), test(pop(A)), test(A), test(pop(A)), test(A)
1 0 1 1 0 1 0 1 1 0
LIMITS LIMITS
@@ -55,7 +55,7 @@ SEE ALSO
isassoc, isfile, isident, isnum, isint, islist, ismat, isnull, isobj, isassoc, isfile, isident, isnum, isint, islist, ismat, isnull, isobj,
isreal, isstr, issimple, istype isreal, isstr, issimple, istype
## Copyright (C) 1999 Landon Curt Noll ## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -71,8 +71,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.2 $ ## @(#) $Revision: 29.3 $
## @(#) $Id: test,v 29.2 2000/06/07 14:02:33 chongo Exp $ ## @(#) $Id: test,v 29.3 2006/06/10 12:28:10 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/test,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/test,v $
## ##
## Under source code control: 1996/07/11 01:05:13 ## Under source code control: 1996/07/11 01:05:13

View File

@@ -64,24 +64,83 @@ Variable declarations
static mat table[3] = {5, 6, 7}; static mat table[3] = {5, 6, 7};
local obj point p1, p2; local obj point p1, p2;
There are no pointers in the calculator language, thus all When working with user-defined functions, the syntax for passing an
arguments to user-defined functions are normally passed by value. lvalue by reference rather than by value is to precede an expression
This is true even for matrices, strings, and lists. In order for the lvalue by a backquote. For example, if the function invert is
to circumvent this, the '&' operator is allowed before a variable defined by:
when it is an argument to a function. When this is done, the
address of the variable is passed to the function instead of its
value. This is true no matter what the type of the variable is.
This allows for fast calls of functions when the passed variable
is huge (such as a large array). However, the passed variable can
then be changed by the function if the parameter is assigned into.
The function being called does not need to know if the variable
is being passed by value or by address.
Built-in functions and object functions always accept their define invert(x) {x = inverse(x)}
arguments as addresses, thus there is no need to use '&' when
calling built-in functions.
## Copyright (C) 1999 Landon Curt Noll then invert(`A) achieves the effect of A = inverse(A). In other
words, passing and argument of `variable (with a back-quote)
will cause and changes to the function argument to be applied to
the calling variable. Calling invert(A) (without the ` backquote)
assigns inverse(A) to the temporary function parameter x and leaves
A unchanged.
In an argument, a backquote before other than an lvalue is ignored.
Consider, for example:
; define logplus(x,y,z) {return log(++x + ++y + ++z);}
; eh = 55;
; mi = 25;
; answer = logplus(eh, `mi, `17);
; print eh, mi, answer;
55 26 2
The value of eh is was not changed because eh was used as
an argument without a back-quote (`). However, mi was incremented
because it was passed as `mi (with a back-quote). Passing 17
(not an lvalue) as `17 has not effect on the value 17.
The back-quote should only be used before arguments to a function.
In all other contexts, a backquote causes a compile error.
Another method is to pass the address of the lvalue explicitly and
use the indirection operator * (star) to refer to the lvalue in the
function body. Consider the following function:
; define ten(a) { *a = 10; }
; n = 17;
; ten(n);
; print n;
17
; ten(`n);
; print n;
17
; ten(&n);
; print n;
10
Passing an argument with a & (ampersand) allows the tenmore()
function to modify the calling variable:
; wa = tenmore(&vx);
; print vx, wa;
65 65
Great care should be taken when using a pointer to a local variable
or element of a matrix, list or object, since the lvalue pointed to
is deleted when evaluation of the function is completed or the lvalue
whose value is the matrix, list or object is assigned another value.
As both of the above methods (using & arguments (ampersand) *value
(star) function values or by using ` arguments (back quote) alone)
copy the address rather than the value of the argument to the function
parameter, they allow for faster calls of functions when the memory
required for the value is huge (such as for a large matrix).
As the built-in functions and object functions always accept their
arguments as addresses, there is no gain in using the backquote when
calling these functions.
## Copyright (C) 1999-2006 Landon Curt Noll
## ##
## Calc is open software; you can redistribute it and/or modify it under ## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License ## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -97,8 +156,8 @@ Variable declarations
## received a copy with calc; if not, write to Free Software Foundation, Inc. ## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## ##
## @(#) $Revision: 29.2 $ ## @(#) $Revision: 29.3 $
## @(#) $Id: variable,v 29.2 2000/06/07 14:02:33 chongo Exp $ ## @(#) $Id: variable,v 29.3 2006/06/11 07:50:48 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/variable,v $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/variable,v $
## ##
## Under source code control: 1991/07/21 04:37:25 ## Under source code control: 1991/07/21 04:37:25

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.9 $ * @(#) $Revision: 29.10 $
* @(#) $Id: quickhash.c,v 29.9 2006/05/20 08:43:55 chongo Exp $ * @(#) $Id: quickhash.c,v 29.10 2006/06/06 07:17:02 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/quickhash.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/quickhash.c,v $
* *
* Under source code control: 1995/03/04 11:34:23 * Under source code control: 1995/03/04 11:34:23
@@ -487,6 +487,7 @@ config_hash(CONFIG *cfg, QCKHASH val)
if (cfg->version) { if (cfg->version) {
val = fnv_strhash(cfg->version, val); val = fnv_strhash(cfg->version, val);
} }
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->baseb);
/* /*
* hash the epsilon if possible * hash the epsilon if possible

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.59 $ * @(#) $Revision: 29.60 $
* @(#) $Id: version.c,v 29.59 2006/06/03 22:52:39 chongo Exp $ * @(#) $Id: version.c,v 29.60 2006/06/11 07:52:58 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $
* *
* Under source code control: 1990/05/22 11:00:58 * Under source code control: 1990/05/22 11:00:58
@@ -48,7 +48,7 @@ static char *program;
#define MAJOR_VER 2 /* major version */ #define MAJOR_VER 2 /* major version */
#define MINOR_VER 12 /* minor version */ #define MINOR_VER 12 /* minor version */
#define MAJOR_PATCH 0 /* patch level or 0 if no patch */ #define MAJOR_PATCH 0 /* patch level or 0 if no patch */
#define MINOR_PATCH 2 /* test number or 0 if no minor patch */ #define MINOR_PATCH 3 /* test number or 0 if no minor patch */
/* /*

161
zfunc.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.7 $ * @(#) $Revision: 29.8 $
* @(#) $Id: zfunc.c,v 29.7 2006/05/20 08:43:55 chongo Exp $ * @(#) $Id: zfunc.c,v 29.8 2006/06/04 20:18:44 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zfunc.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zfunc.c,v $
* *
* Under source code control: 1990/02/15 01:48:27 * Under source code control: 1990/02/15 01:48:27
@@ -37,6 +37,148 @@ ZVALUE _tenpowers_[TEN_MAX+1]; /* table of 10^2^n */
static long *power10 = NULL; static long *power10 = NULL;
static int max_power10_exp = 0; static int max_power10_exp = 0;
/*
* given:
*
* unsigned long x
* or: unsigned long long x
* or: long x and x >= 0
* or: long long x and x >= 0
*
* If issq_mod4k[x & 0xfff] == 0, then x cannot be a perfect square
* else x might be a perfect square.
*/
static USB8 issq_mod4k[1<<12] = {
1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,
0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,
1,1,0,0,1,0,0,0,0,1,0,0,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ial of a number.
@@ -1945,7 +2087,7 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest)
BOOL BOOL
zissquare(ZVALUE z) zissquare(ZVALUE z)
{ {
long n, i; long n;
ZVALUE tmp; ZVALUE tmp;
/* negative values are never perfect squares */ /* negative values are never perfect squares */
@@ -1964,17 +2106,10 @@ zissquare(ZVALUE z)
return TRUE; return TRUE;
} }
/* check mod 16 values */ /* check mod 4096 values */
n = (long)(*z.v & 0xf); if (issq_mod4k[(int)(*z.v & 0xfff)] == 0) {
if ((n != 0) && (n != 1) && (n != 4) && (n != 9))
return FALSE;
/* check mod 256 values */
n = (long)(*z.v & 0xff);
i = 0x80;
while (((i * i) & 0xff) != n)
if (--i <= 0)
return FALSE; return FALSE;
}
/* must do full square root test now */ /* must do full square root test now */
n = !zsqrt(z, &tmp, 0); n = !zsqrt(z, &tmp, 0);

15
zmath.h
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.15 $ * @(#) $Revision: 29.17 $
* @(#) $Id: zmath.h,v 29.15 2006/05/21 07:10:22 chongo Exp $ * @(#) $Id: zmath.h,v 29.17 2006/06/11 07:07:23 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zmath.h,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zmath.h,v $
* *
* Under source code control: 1993/07/30 19:42:48 * Under source code control: 1993/07/30 19:42:48
@@ -228,11 +228,12 @@ typedef SB32 LEN; /* unit of length storage */
#define MAXLEN ((LEN) 0x7fffffff >> 3) /* longest value allowed */ #define MAXLEN ((LEN) 0x7fffffff >> 3) /* longest value allowed */
#define MAXREDC 5 /* number of entries in REDC cache */ #define MAXREDC 64 /* number of entries in REDC cache */
#define SQ_ALG2 20 /* size for alternative squaring */ #define SQ_ALG2 3388 /* size for alternative squaring */
#define MUL_ALG2 20 /* size for alternative multiply */ #define MUL_ALG2 1780 /* size for alternative multiply */
#define POW_ALG2 40 /* size for using REDC for powers */ #define POW_ALG2 176 /* size for using REDC for powers */
#define REDC_ALG2 50 /* size for using alternative REDC */ /* old REDC_ALG2 was 5/4 of POW_ALG2, so we will keep the same ratio */
#define REDC_ALG2 220 /* size for using alternative REDC */
typedef union { typedef union {

6
zmod.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc. * received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* @(#) $Revision: 29.3 $ * @(#) $Revision: 29.4 $
* @(#) $Id: zmod.c,v 29.3 2000/07/17 15:35:49 chongo Exp $ * @(#) $Id: zmod.c,v 29.4 2006/06/11 00:08:56 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zmod.c,v $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/zmod.c,v $
* *
* Under source code control: 1991/05/22 23:03:55 * Under source code control: 1991/05/22 23:03:55
@@ -1197,7 +1197,7 @@ zredcmul(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res)
ZVALUE z1tmp, z2tmp; ZVALUE z1tmp, z2tmp;
int sign; int sign;
sign = z1.sign ^ z2.sign;; sign = z1.sign ^ z2.sign;
z1.sign = 0; z1.sign = 0;
z2.sign = 0; z2.sign = 0;
z1tmp.len = 0; z1tmp.len = 0;