assign to A the unit n * n matrix, one may use matfill(mat A[n,n], 0, 1). For a square matrix A, mattrace(A) returns the trace of A, i.e. the sum of the diagonal elements. For zero- or one-dimensional A, mattrace(A) returns the sum of the elements of A. For a two-dimensional matrix A, mattrans(A) returns the transpose of A, i.e. if A is mat[m,n], it returns a mat[n,m] matrix with [i,j] element equal to A[j,i]. For zero- or one-dimensional A, mattrace(A) returns a matrix with the same value as A. The functions search(A, value, start, end]) and rsearch(A, value, start, end]) return the first or last index i for which A[[i]] == value and start <= i < end, or if there is no such index, the null value. For further information on default values and the use of an "accept" function, see the help files for search and rsearch. reverse(A) returns a matrix with the same index-lists as A but the elements in reversed order. The copy and blkcpy functions may be used to copy data to a matrix from a matrix or list, or from a matrix to a list. In copying from a matrix to a matrix the matrices need not have the same dimension; in effect they are treated as linear arrays. EXAMPLE ; obj point {x,y} ; mat A[5] = {1, 2+3i, "ab", mat[2] = {4,5}, obj point = {6,7}} ; A mat [5] (5 elements, 5 nonzero): [0] = 1 [1] = 2+3i [2] = "ab" [3] = mat [2] (2 elements, 2 nonzero) [4] = obj point {6, 7} ; print A[0], A[1], A[2], A[3][0], A[4].x 1 2+3i ab 4 6 ; define point_add(a,b) = obj point = {a.x + b.x, a.y + b.y} point_add(a,b) defined ; mat [B] = {8, , "cd", mat[2] = {9,10}, obj point = {11,12}} ; A + B mat [5] (5 elements, 5 nonzero): [0] = 9 [1] = 2+3i [2] = "abcd" [3] = mat [2] (2 elements, 2 nonzero) [4] = obj point {17, 19} ; mat C[2,2] = {1,2,3,4} ; C^10 mat [2,2] (4 elements, 4 nonzero): [0,0] = 4783807 [0,1] = 6972050 [1,0] = 10458075 [1,1] = 15241882 ; C^-10 mat [2,2] (4 elements, 4 nonzero): [0,0] = 14884.650390625 [0,1] = -6808.642578125 [1,0] = -10212.9638671875 [1,1] = 4671.6865234375 ; mat A[4] = {1,2,3,4}, A * reverse(A); mat [4] (4 elements, 4 nonzero): [0] = 4 [1] = 6 [2] = 6 [3] = 4 LIMITS The theoretical upper bound for the absolute values of indices is 2^31 - 1, but the size of matrices that can be handled in practice will be limited by the availability of memory and what is an acceptable runtime. For example, although it may take only a fraction of a second to invert a 10 * 10 matrix, it will probably take about 1000 times as long to invert a 100 * 100 matrix. LINK LIBRARY n/a SEE ALSO ismat, matdim, matmax, matmin, mattrans, mattrace, matsum, matfill, det, inverse, isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp, randperm, sort ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: mat,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mat,v $ ## ## Under source code control: 1991/07/21 04:37:22 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME max - maximum, or maximum of defined maxima SYNOPSIS max(x_1, x_2, ...) TYPES x_1, x_2, ... any return any DESCRIPTION If an argument x_i is a list with elements e_1, e_2, ..., e_n, it is treated as if x_i were replaced by e_1, e_2, ..., e_n; this may continue recurively if any of the e_j is a list. If an argument x_i is an object of type xx, then x_i is replaced by xx_max(x_i) if the function xx_max() has been defined. If the type xx has been defined by: obj xx = {x, y, z}, an appropriate definition of xx_max(a) is sometimes max(a.x, a.y, a.z). max(a) then returns the maximum of the elements of a. If x_i has the null value, it is ignored. Thus, sum(a, , b, , c) If x_i has the null value, it is ignored. Thus, max(a, , b, , c) will return the same as max(a, b, c). Assuming the above replacements, and that the x_1, x_2, ..., are of sufficently simple ordered types (e.g. real numbers or strings), or, if some are objects, the relevant xx_rel(a,b) has been defined and returns a real-number value for any comparison that has to be made, max(x_1, x_2, ...) returns the value determined by max(x_1) = x_1, and succesively for later arguments, by the use of the equivalent of max(a,b) = (a < b) ? b : a. If the ordering determined by < is total, max(x_1, ...) will be the maximum value among the arguments. For a preorder relation it may be one of several maximal values. For other relations, it may be difficult to predict the result. EXAMPLE ; print max(2), max(5, 3, 7, 2, 9), max(3.2, -0.5, 8.7, -1.2, 2.5) 2 9 8.7 ; print max(list(3,5), 7, list(6, list(7,8), 2)) 8 ; print max("one", "two", "three", "four") two ; obj point {x, y} ; define point_rel(a,b) = sgn(a.x - b.x) ; obj point A = {1, 5} ; obj point B = {1, 4} ; obj point C = {3, 3} ; print max(A, B, C) obj point {3, 3} ; define point_max(a) = a.x ; print max(A, B, C) 3 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY NUMBER *qmax(NUMBER *x1, NUMBER *x2) SEE ALSO max, obj ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: max,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/max,v $ ## ## Under source code control: 1995/10/05 04:52:27 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME feof - determine if end-of-file flag is set SYNOPSIS feof(fd) TYPES fd file stream open for reading return 0 or 1 DESCRIPTION The function feof(fd) returns 1 or 0 according as the end-of-file flag is set or clear. The end-of-file flag for the stream fd is set if reading at the end-of-file position is attempted. The flag is cleared by positioning operations (fseek, rewind, fsetpos) and by freopen. EXAMPLE ; fd1 = fopen("/tmp/newfile", "w") ; fputs(fd1, "Chongo was here\n") ; fflush(fd1) ; fd2 = fopen("/tmp/newfile", "r") ; feof(fd2) 0 ; fgetline(fd2) "Chongo was here" ; feof(fd2) 0 ; fgetline(fd2) ; feof(fd2) 1 LIMITS none LINK LIBRARY none SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: feof,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/feof,v $ ## ## Under source code control: 1994/10/27 03:04:17 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME bround - round numbers to a specified number of binary digits SYNOPSIS bround(x [,plcs [, rnd]]) TYPES If x is a matrix or a list, bround(x[[i]], ...) is to return a value for each element x[[i]] of x; the value returned will be a matrix or list with the same structure as x. Otherwise, if x is an object of type tt, or if x is not an object or number but y is an object of type tt, and the function tt_bround has to be defined; the types for x, plcs, rnd, and the returned value, if any, are as required for specified in tt_bround. For the object case, plcs and rnd default to the null value. For other cases: x number (real or complex) plcs integer, defaults to zero rnd integer, defaults to config("round") return number DESCRIPTION For real x, bround(x, plcs, rnd) returns x rounded to either plcs significant binary digits (if rnd & 32 is nonzero) or to plcs binary places (if rnd & 32 is zero). In the significant-figure case the rounding is to plcs - ilog10(x) - 1 binary places. If the number of binary places is n and eps = 10^-n, the result is the same as for appr(x, eps, rnd). This will be exactly x if x is a multiple of eps; otherwise rounding occurs to one of the nearest multiples of eps on either side of x. Which of these multiples is returned is determined by z = rnd & 31, i.e. the five low order bits of rnd, as follows: z = 0 or 4: round down, i.e. towards minus infinity z = 1 or 5: round up, i.e. towards plus infinity z = 2 or 6: round towards zero z = 3 or 7: round away from zero z = 8 or 12: round to the nearest even multiple of eps z = 9 or 13: round to the nearest odd multiple of eps z = 10 or 14: round to nearest even or odd multiple of eps according as x > or < 0 z = 11 or 15: round to nearest odd or even multiple of eps according as x > or < 0 z = 16 to 31: round to the nearest multiple of eps when this is uniquely determined. Otherwise rounding is as if z is replaced by z - 16 For complex x: The real and imaginary parts are rounded as for real x; if the imaginary part rounds to zero, the result is real. For matrix or list x: The returned values has element bround(x[[i]], plcs, rnd) in the same position as x[[i]] in x. For object x or plcs: When bround(x, plcs, rnd) is called, x is passed by address so may be changed by assignments; plcs and rnd are copied to temporary variables, so their values are not changed by the call. EXAMPLES ; a = 7/32, b = -7/32 ; print a, b .21875 -.21875 ; print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3) .218, .219, .218, .219 ; print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3) -.219, -.218, -.218, -.219 ; print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19) .2188 .2188 .2188 .2188 ; print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19) .2187 .2188 .2187 .2188 ; print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8) .22 .218 .2188 .21875 ; print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24) .22 .219 .2188 .21875 ; c = 21875 ; print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16) 21800 21900 21000 22000 ; print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56) 21000 22000 22000 21880 ; A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8) ; print round(A,2,24) list(7 elements, 7 nonzero): [[0]] = .12 [[1]] = .25 [[3]] = .38 [[4]] = .5 [[5]] = .62 [[6]] = .75 [[7]] = .88 LIMITS For non-object case: 0 <= abs(plcs) < 2^31 0 <= abs(rnd) < 2^31 LINK LIBRARY void broundvalue(VALUE *x, VALUE *plcs, VALUE *rnd, VALUE *result) MATRIX *matbround(MATRIX *m, VALUE *plcs, VALUE *rnd); LIST *listbround(LIST *m, VALUE *plcs, VALUE *rnd); NUMBER *qbround(NUMBER *m, long plcs, long rnd); SEE ALSO round, trunc, btrunc, int, appr ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: bround,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bround,v $ ## ## Under source code control: 1994/09/30 00:22:35 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME cfsim - simplify a value using continued fractions SYNOPSIS cfsim(x [,rnd]) TYPES x real rnd integer, defaults to config("cfsim") return real DESCRIPTION If x is not an integer, cfsim(x, rnd) returns either the nearest above x, or the nearest below x, number with denominator less than den(x). If x is an integer, cfsim(x, rnd) returns x + 1, x - 1, or 0. Which of the possible results is returned is controlled by bits 0, 1, 3 and 4 of the parameter rnd. For 0 <= rnd < 4, the sign of the remainder x - cfsim(x, rnd) is as follows: rnd sign of x - cfsim(x, rnd) 0 +, as if rounding down 1 -. as if rounding up 2 sgn(x), as if rounding to zero 3 -sgn(x), as if rounding from zero This corresponds to the use of rnd for functions like round(x, n, rnd). If bit 3 or 4 of rnd is set, the lower order bits are ignored; bit 3 is ignored if bit 4 is set. Thusi, for rnd > 3, it sufficient to consider the two cases rnd = 8 and rnd = 16. If den(x) > 2, cfsim(x, 8) returns the value of the penultimate simple continued-fraction approximant to x, i.e. if: x = a_0 + 1/(a_1 + 1/(a_2 + ... + 1/a_n) ...)), where a_0 is an integer, a_1, ..., a_n are positive integers, and a_n >= 2, the value returned is that of the continued fraction obtained by dropping the last quotient 1/a_n. If den(x) > 2, cfsim(x, 16) returns the nearest number to x with denominator less than den(x). In the continued-fraction representation of x described above, this is given by replacing a_n by a_n - 1. If den(x) = 2, the definition adopted is to round towards zero for the approximant case (rnd = 8) and from zero for the "nearest" case (rnd = 16). For integral x, cfsim(x, 8) returns zero, cfsim(x,16) returns x - sgn(x). In summary, for cfsim(x, rnd) when rnd = 8 or 16, the results are: rnd integer x half-integer x den(x) > 2 8 0 x - sgn(x)/2 approximant 16 x - sgn(x) x + sgn(x)/2 nearest From either cfsim(x, 0) and cfsim(x, 1), the other is easily determined: if one of them has value w, the other has value (num(x) - num(w))/(den(x) - den(w)). From x and w one may find other optimal rational numbers near x; for example, the smallest- denominator number between x and w is (num(x) + num(w))/(den(x) + den(w)). If x = n/d and cfsim(x, 8) = u/v, then for k * v < d, the k-th member of the sequence of nearest approximations to x with decreasing denominators on the other side of x is (n - k * u)/(d - k * v). This is nearer to or further from x than u/v according as 2 * k * v < or > d. Iteration of cfsim(x,8) until an integer is obtained gives a sequence of "good" approximations to x with decreasing denominators and correspondingly decreasing accuracy; each denominator is less than half the preceding denominator. (Unlike the "forward" sequence of continued-fraction approximants these are not necessarily alternately greater than and less than x.) Some other properties: For rnd = 0 or 1 and any x, or rnd = 8 or 16 and x with den(x) > 2: cfsim(n + x, rnd) = n + cfsim(x, rnd). This equation also holds for the other values of rnd if n + x and x have the same sign. For rnd = 2, 3, 8 or 16, and any x: cfsim(-x, rnd) = -cfsim(x, rnd). If rnd = 8 or 16, except for integer x or 1/x for rnd = 8, and zero x for rnd = 16: cfsim(1/x, rnd) = 1/cfsim(x, rnd). EXAMPLE ; c = config("mode", "frac"); ; print cfsim(43/30, 0), cfsim(43/30, 1), cfsim(43/30, 8), cfsim(43/30,16) 10/7 33/23 10/7 33/23 ; x = pi(1e-20); c = config("mode", "frac"); ; while (!isint(x)) {x = cfsim(x,8); if (den(x) < 1e6) print x,:;} 1146408/364913 312689/99532 104348/33215 355/113 22/7 3 LIMITS none LINK LIBRARY NUMBER *qcfsim(NUMBER *x, long rnd) SEE ALSO cfappr ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: cfsim,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cfsim,v $ ## ## Under source code control: 1994/09/30 01:29:45 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME freestatics - free memory used for static variables SYNOPSIS freestatics() TYPES return null value DESCRIPTION This function frees the memory used for the values of all unscoped static variables by in effect assigning null values to them. As this will usually have significant effects of any functions in whose definitions these variables have been used, it is primarily intended for use when these functions are being undefined or redefined.. EXAMPLE ; static a = 5 ; define f(x) = a++ * x; f() defined ; global a ; f(1) 5 ; show statics Name Scopes Type ---- ------ ----- a 1 0 real = 6 Number: 1 ; freestatics() ; f(1) Error 10005 ; strerror(.) "Bad arguments for *" LIMITS none LINK LIBRARY none SEE ALSO free, freeglobals, freeredc ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: freestatics,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freestatics,v $ ## ## Under source code control: 1997/09/06 20:03:35 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME tanh - hyperbolic tangent SYNOPSIS tanh(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the tanh of x to the nearest or next to nearest multiple of epsilon, with absolute error less than .75 * abs(eps). tanh(x) = (exp(2*x) - 1)/(exp(2*x) + 1) EXAMPLE ; print tanh(1, 1e-5), tanh(1, 1e-10), tanh(1, 1e-15), tanh(1, 1e-20) .76159 .761594156 .761594155955765 .76159415595576488812 LIMITS unlike sin and cos, x must be real eps > 0 LINK LIBRARY NUMBER *qtanh(NUMBER *x, NUMBER *eps) SEE ALSO sinh, cosh, sech, csch, coth, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: tanh,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/tanh,v $ ## ## Under source code control: 1994/03/19 01:40:30 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME makelist - create a list with a specified number of null members SYNOPSIS makelist(x) TYPES x int return list DESCRIPTION For non-negative integer x, makelist(x) returns a list of size x all members of which have null value. EXAMPLE ; A = makelist(4) ; A list (4 members, 4 nonzero): [[0]] = NULL [[1]] = NULL [[2]] = NULL [[3]] = NULL LIMITS 0 <= x < 2^31 LINK LIBRARY none SEE ALSO modify ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: makelist,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/makelist,v $ ## ## Under source code control: 1995/07/10 02:09:31 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME rsearch - reverse search for an element satisfying a specified condition SYNOPSIS rsearch(a, b [, [c] [, [d] ] ]) TYPES a matrix, list, association, or file open for reading b string if a is a file, otherwise any c integer, defaults to zero, size(a) or the current file-position d integer, defaults to size(a) or current file-position return nonnegative integer or null DESCRIPTION Negative values of c and nonpositive values of d are treated as offsets from size(a), i.e. as if c were replaced by size(a) + c and d by size(a) + d. Any such adjustment is assumed to have been made. The nature of the search depends on whether the rsearch() is called with or without the fourth argument d. Four argument case: The search interval is as for search(a,b,c,d), i.e. the indices i to be examined are to satisfy c <= i < d and 0 <= i < size(a) for non-file a, and c <= i <= d - strlen(b), 0 <= i <= size(a) - strlen(b) if a is a file stream. The difference from search(a,b,c,d) is that the indices i, if any, are examined in decreasing order, so that if a match is found, the returned integer i is the largest in the search interval. The null value is returned if no match is found. The default value for d is size(a) for non-file cases, and the current file-position if a is a file. The default for c is zero except if a is a file and d is an integer. For non-file a, the search is for a[[i]] == b, except that if the function accept() as been defined, it is for i such that accept(a[[i]], b) tests as nonzero. Since the addresses (rather than values) of a[[i]] and b are passed to accept(), the values of one or both of a[[i]] and b may be changed during a call to rsearch(). In the file-stream case, if strlen(b) = n, a match at file-position i corresponds to the n characters in the file starting at position i matching those of the string b. The null value is returned if no match is found. The final file position will correspond to the last character if a match is found, or the start (lowest) position of the search interval if no match is found, except that if no reading of characters is required (e.g. if start > end), the original file-position is not changed. Two- or Three-argument case: If a is not a file, the default value for c is size(a). If a is a file, rsearch(a,b) = rsearch(a, b, ftell(a)), and rsearch(a,b,) = rsearch(a, b, size(a)). If a is not a file, the search starts, if at all, at the largest non-negative index i for which i <= c and i < size(a), and continues until a match a[[i]] == b is found, or if accept() has been defined, accept(a[[i]], b) tests as nonzero; if no such i is found and returned, the null value is returned. If a is a file, the first, if any, file-position tested has the greatest nonnegative position i such that i <= c and i <= size(a) - strlen(b). The returned value is either the first i at which a match is found or the null value if no match with the string b is found. The final file-position will correspond to the last character of b, or the zero position, according as a match is found or not found. EXAMPLE ; L = list(2,"three",4i) ; rsearch(L,"three") 1 ; rsearch(L,"threes") ; rsearch(L, 4i, 4) ; rsearch(L, 4i, 1) 2 ; f = fopen("foo", "w+") ; fputs(f, "This file has 28 characters.") ; fflush(f) ; rsearch(f, "ha") 18 ; ftell(f) 19 ; rsearch(f, "ha", 17) 10 ; rsearch(f, "ha", 9) ; ftell(f) 0 ; rsearch(f, "ha") 18 ; rsearch(f, "ha", 5, 500) 18 LIMITS none LINK LIBRARY none SEE ALSO append, delete, insert, islist, pop, push, remove, search, select, size, assoc, list, mat ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: rsearch,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rsearch,v $ ## ## Under source code control: 1994/03/19 03:13:21 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME printf - formatted print to standard output SYNOPSIS printf(fmt, x_1, x_2, ...) TYPES fmt string x_1, x_2, ... any return null DESCRIPTION The function printf() is similar to the C function with the same name. The most significant difference is that there is no requirement that the types of values of the arguments x_i match the corresponding format specifier in fmt. Thus, whatver the format specifier, a number is printed as a number, a string as a string, a list as a list, a matrix as a matrix, an xx-object as an xx-object, etc. Except when a '%' is encountered, characters of the string fmt are printed in succession to the standard output. Occurrence of a '%' indicates the intention to build a format specifier. This is completed by a succession of characters as follows: an optional '-' zero or more decimal digits an optional '. followed by zero or more decimal deigits an optional 'l' one of the letters: d, s, c, f, e, r, o, x, b, If any other character is read, the '%' and any characters between '%' and the character are ignored and no specifier is formed. E.g. "%+f" prints as if only "f" were read; "% 10s" prints as "10s", "%X" prints as "X", "%%" prints as "%". The characters in a format specifier are interpreted as follows: a minus sign sets the right-pad flag; the first group of digits determines the width w; w = 0 if there are no digits a dot indicates the precision is to be read from the following digits; if there is no dot, precision = config("display"). any digits following the . determines the precision p; p = 0 if there are no digits any 'l' before the final letter is ignored the final letter determines the mode as follows: d, s, c current config("mode") f real (decimal, floating point) e exponential r fractional o octal x hexadecimal b binary If the number of arguments after fmt is less than the number of format specifiers in fmt, the "missing" arguments may be taken to be null values - these contribute nothing to the output; if a positive width w has been specified, the effect is to produce w spaces, e.g. printf("abc%6dxyz") prints "abc xyz". If i <= the number of specifiers in fmt, the value of argument x_i is printed in the format specified by the i-th specifier. If a positive width w has been specified and normal printing of x_i does not include a '\n' character, what is printed will if necessary be padded with spaces so that the length of the printed output is at least the w. Note that control characters like '\t', '\b' each count as one character. If the 'right-pad' flag has been set, the padding is on the right; otherwise it is on the left. If i > the number of specifiers in fmt, the value of argument x_i does not contribute to the printing. However, as all arguments are evaluated before printing occurs, side-effects of the evaluation of x_i might affect the result. If the i-th specifier is of numerical type, any numbers in the printing of x_i will be printed in the specified format, unless this is modified by the printing procedure for x_i's type. Any specified precision will be ignored except for floating-point mode. In the case of floating-point (f) format the precision determines the maximum number of decimal places to be displayed. Other aspects of this printing may be affected by the configuration parameters "outround", "tilde", "fullzero", "leadzero". EXAMPLE ; c = config("epsilon", 1e-6); c = config("display", 6); ; c = config("tilde", 1); c = config("outround", 0); ; c = config("fullzero", 0); ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; a = sqrt(3); ; printf(fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. ; c = config("tilde", 0); c = config("outround",24); ; c = config("fullzero", 1); ; printf(fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , 1.7321,1.7321,2. ; mat A[4] = {sqrt(2), 3/7, "undefined", null()}; ; printf("%f%r",A,A); mat [4] (4 elements, 4 nonzero): [0] = 1.414214 [1] = .428571 [2] = "undefined" [3] = NULL mat [4] (4 elements, 4 nonzero): [0] = 707107/500000 [1] = 3/7 [2] = "undefined" [3] = NULL LIMITS The number of arguments of printf() is not to exceed 1024. LINK LIBRARY none SEE ALSO fprintf, strprintf, print ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: printf,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/printf,v $ ## ## Under source code control: 1996/03/12 22:50:41 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME sinh - hyperbolic sine SYNOPSIS sinh(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the sinh of x to the nearest or next to nearest multiple of epsilon, with absolute error less than .75 * abs(eps). sinh(x) = (exp(x) - exp(-x))/2 EXAMPLE ; print sinh(1, 1e-5), sinh(1, 1e-10), sinh(1, 1e-15), sinh(1, 1e-20) 1.1752 1.1752011936 1.175201193643801 1.17520119364380145688 LIMITS unlike sin and cos, x must be real eps > 0 LINK LIBRARY NUMBER *qsinh(NUMBER *x, NUMBER *eps) SEE ALSO cosh, tanh, sech, csch, coth, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: sinh,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sinh,v $ ## ## Under source code control: 1994/03/19 01:40:29 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME isblk - whether or not a value is a block SYNOPSIS isblk(val) TYPES val any return 0, 1, or 2 DESCRIPTION isblk(val) returns 1 if val is an unnamed block, 2 if val is a named block, 0 otherwise. Note that a named block B retains its name after its data block is freed by rmblk(B). That a named block B has null data block may be tested using sizeof(B); this returns 0 if and only if the memory has been freed. EXAMPLE ; A = blk() ; isblk(A) 1 ; B = blk("beta") ; isblk(B) 2 ; isblk(3) 0 LIMITS none LINK LIBRARY none SEE ALSO blk, blocks, blkfree, isassoc, isatty, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isblk,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isblk,v $ ## ## Under source code control: 1997/04/06 03:03:23 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME matdim - matrix dimension SYNOPSIS matdim(m) TYPES m matrix return 1, 2, 3, or 4 DESCRIPTION Returns the number of indices required to specify elements of the matrix. EXAMPLE ; mat A[3]; mat B[2,3]; mat C[1, 2:3, 4]; mat D[2, 3, 4, 5] ; print matdim(A), matdim(B), matdim(C), matdim(D) 1 2 3 4 LIMITS none LINK LIBRARY none SEE ALSO mat, ismat, matmax, matmin, mattrans, mattrace, matsum, matfill, det, inverse, isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp, randperm, sort ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: matdim,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matdim,v $ ## ## Under source code control: 1995/10/25 04:03:45 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME gcdrem - result of removing factors of integer common to a specified integer SYNOPSIS gcdrem(x, y) TYPES x integer y integer return non-negative integer DESCRIPTION If x and y are not zero, gcdrem(x, y) returns the greatest integer divisor d of x relatively prime to y, i.e. for which gcd(d,y) = 1. In particular, gcdrem(x,y) = abs(x) if x and y are relatively prime. For all x, gcdrem(x, 0) = 1. For all nonzero y, gcdrem(0, y) = 0. PROPERTIES gcdrem(x,y) = gcd(abs(x), abs(y)). If x is not zero, gcdrem(x,y) = gcdrem(x, gcd(x,y)) = gcdrem(x, y % x). For fixed nonzero x, gcdrem(x,y) is periodic with period abs(x). gcdrem(x,y) = 1 if and only if every prime divisor of x is a divisor of y. If x is not zero, gcdrem(x,y) == abs(x) if and only if gcd(x,y) = 1. If y is not zero and p_1, p_2, ..., p_k are the prime divisors of y, gcdrem(x,y) = frem(...(frem(frem(x,p_1),p_2)...,p_k) EXAMPLE ; print gcdrem(6,15), gcdrem(15,6), gcdrem(72,6), gcdrem(6,72) 2 5 1 1 ; print gcdrem(630,6), gcdrem(6,630) 35 1 LIMITS none LINK LIBRARY NUMBER *qgcdrem(NUMBER *x, NUMBER *y) SEE ALSO gcd, frem, isrel ## Copyright (C) 1999 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: gcdrem,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gcdrem,v $ ## ## Under source code control: 1995/12/18 12:03:02 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME fact - factorial SYNOPSIS fact(x) TYPES x int return int DESCRIPTION Return the factorial of a number. Factorial is defined as: x! = 1 * 2 * 3 * ... * x-1 * x 0! = 1 EXAMPLE ; print fact(10), fact(5), fact(2), fact(1), fact(0) 3628800 120 2 1 1 ; print fact(40) 815915283247897734345611269596115894272000000000 LIMITS 2^24 > x >= 0 y < 2^24 LINK LIBRARY void zfact(NUMBER x, *ret) SEE ALSO comb, perm, randperm ## Copyright (C) 1999-2006 Landon Curt Noll ## ## 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 ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fact,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fact,v $ ## ## Under source code control: 1994/10/20 04:03:02 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME config - configuration parameters 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 are the accuracy of some calculations, the displayed format of results, the choice from possible alternative algorithms, and whether or not debugging information is displayed. The parameters are read or set using the "config" built-in function; they remain in effect until their values are changed by a config or equivalent instruction. The following parameters can be specified: "all" all configuration values listed below "trace" turns tracing features on or off "display" sets number of digits in prints. "epsilon" sets error value for transcendentals. "maxprint" sets maximum number of elements printed. "mode" sets printout mode. "mode2" sets 2nd base printout mode. "mul2" sets size for alternative multiply. "sq2" sets size for alternative squaring. "pow2" sets size for alternate powering. "redc2" sets size for alternate REDC. "tilde" enable/disable printing of the roundoff '~' "tab" enable/disable printing of leading tabs "quomod" sets rounding mode for quomod "quo" sets rounding mode for //, default for quo "mod" sets "rounding" mode for %, default for mod "sqrt" sets rounding mode for sqrt "appr" sets rounding mode for appr "cfappr" sets rounding mode for cfappr "cfsim" sets rounding mode for cfsim "round" sets rounding mode for round and bround "outround" sets rounding mode for printing of numbers "leadzero" enables/disables printing of 0 as in 0.5 "fullzero" enables/disables padding zeros as in .5000 "maxscan" maximum number of scan errors before abort "prompt" default interactive prompt "more" default interactive multi-line input prompt "blkmaxprint" number of block octets to print, 0 means all "blkverbose" TRUE => print all lines, FALSE=>skip duplicates "blkbase" block output base "blkfmt" block output format "calc_debug" controls internal calc debug information "resource_debug" controls resource file debug information "user_debug" for user defined debug information "verbose_quit" TRUE => print message on empty quit or abort "ctrl_d" The interactive meaning of ^D (Control D) "program" Read-only calc program or shell script path "basename" Read-only basename of the program value "windows" Read-only indicator of MS windows "cygwin" TRUE=>calc compiled with cygwin, Read-only "compile_custom" TRUE=>calc was compiled with custom functions "allow_custom" TRUE=>custom functions are enabled "version" Read-only calc version "baseb" bits in calculation base, a read-only value "redecl_warn" TRUE => warn when redeclaring "dupvar_warn" TRUE => warn when variable names collide "hz" Read-only operating system tick rate or 0 The "all" config value allows one to save/restore the configuration set of values. The return of: config("all") is a CONFIG type which may be used as the 2rd arg in a later call. One may save, modify and restore the configuration state as follows: oldstate = config("all") ... config("tab", 0) config("mod", 10) ... config("all", oldstate) This save/restore method is useful within functions. It allows functions to control their configuration without impacting the calling function. There are two configuration state aliases that may be set. To set the backward compatible standard configuration: config("all", "oldstd") The "oldstd" will restore the configuration to the default at startup. A new configuration that some people prefer may be set by: config("all", "newstd") The "newstd" is not backward compatible with the historic configuration. Even so, some people prefer this configuration and place the config("all", "newstd") command in their CALCRC startup files; newstd may also be established by invoking calc with the flag -n. The following are synonyms for true: "on" "true" "t" "yes" "y" "set" "1" any non-zero number The following are synonyms for false: "off" "false" "f" "no" "n" "unset" "0" the number zero (0) Examples of setting some parameters are: config("mode", "exp"); exponential output config("display", 50); 50 digits of output epsilon(epsilon() / 8); 3 bits more accuracy config("tilde", 0) disable roundoff tilde printing config("tab", "off") disable leading tab printing =-= config("trace", bitflag) When nonzero, the "trace" parameter activates one or more features that may be useful for debugging. These features correspond to powers of 2 which contribute additively to config("trace"): 1: opcodes are displayed as functions are evaluated 2: disables the inclusion of debug lines in opcodes for functions whose definitions are introduced with a left-brace. 4: the number of links for real and complex numbers are displayed when the numbers are printed; for real numbers "#" or for complex numbers "##", followed by the number of links, are printed immediately after the number. 8: the opcodes for a new functions are displayed when the function is successfully defined. See also resource_debug, calc_debug and user_debug below for more debug levels. =-= config("display", int) The "display" parameter specifies the maximum number of digits after the decimal point to be printed in real or exponential mode in normal unformatted printing (print, strprint, fprint) or in formatted printing (printf, strprintf, fprintf) when precision is not specified. The initial value for oldstd is 20, for newstd 10. The parameter may be changed to the value d by either config("display", d) or by display (d). This parameter does not change the stored value of a number. Where rounding is necessary to display up to d decimal places, the type of rounding to be used is controlled by config("outround"). =-= config("epsilon", real) epsilon(real) The "epsilon" parameter specifies the default accuracy for the calculation of functions for which exact values are not possible or not desired. For most functions, the remainder = exact value - calculated value has absolute value less than epsilon, but, except when the sign of the remainder is controlled by an appropriate parameter, the absolute value of the remainder usually does not exceed epsilon/2. Functions which require an epsilon value accept an optional argument which overrides this default epsilon value for that single call. The value v can be assigned to the "epsilon" parameter by either config("epsilon", v) or epsilon(v); each of these functions return the current epsilon value; config("epsilon") or epsilon() returns but does not change the epsilon value. For the transcendental functions and the functions sqrt() and appr(), the calculated value is always a multiple of epsilon. =-= config("mode", "mode_string") config("mode2", "mode_string") The "mode" parameter is a string specifying the mode for printing of numbers by the unformatted print functions, and the default ("%d" specifier) for formatted print functions. The initial mode is "real". The available modes are: config("mode") meaning equivalent string base() call "binary" base 2 fractions base(2) "bin" "octal" base 8 fractions base(8) "oct" "real" base 10 floating point base(10) "float" "default" "integer" base 10 integer base(-10) "int" "hexadecimal" base 16 fractions base(16) "hex" "fraction" base 10 fractions base(1/3) "frac" "scientific" base 10 scientific notation base(1e20) "sci" "exp" Where multiple strings are given, the first string listed is what config("mode") will return. The "mode2" controls the double base output. When set to a value other than "off", calc outputs files in both the "base" mode as well as the "base2" mode. The "mode2" value may be any of the "mode" values with the addition of: "off" disable 2nd base output mode base2(0) The base() builtin function sets and returns the "mode" value. The base2() builtin function sets and returns the "mode2" value. The default "mode" is "real". The default "mode2" is "off". =-= config("maxprint", int) The "maxprint" parameter specifies the maximum number of elements to be displayed when a matrix or list is printed. The initial value is 16. =-= config("mul2", int) config("sq2", int) Mul2 and sq2 specify the sizes of numbers at which calc switches from its first to its second algorithm for multiplying and squaring. The first algorithm is the usual method of cross multiplying, which runs in a time of O(N^2). The second method is a recursive and complicated method which runs in a time of O(N^1.585). The argument for these parameters is the number of binary words at which the second algorithm begins to be used. The minimum value is 2, and 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 slow since the recursion overhead is high. If a number such as 1000000 is used, then the recursive algorithm is almost never used, causing calculations for large numbers to slow down. 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("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 decimal 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 decimal 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. =-= config("pow2", int) Pow2 specifies the sizes of numbers at which calc switches from its first to its second algorithm for calculating powers modulo another number. The first algorithm for calculating modular powers is by repeated squaring and multiplying and dividing by the modulus. The second method uses the REDC algorithm given by Peter Montgomery which avoids divisions. The argument for pow2 is the size of the 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 decimal digits) use the 1st algorithm, for calculating powers modulo another number. A value of zero resets the parameter back to their default values. The ÑÑÑÑÑÑÑÑÑ Ñ Ñ Ñ Ñ ÑÑÑÑÑÑÑÑÑ