rsions to strings, and is useful on an error condition to restore output to a known state. You should also call math_setfp on errors if you had changed that. If you wish to mix your own output with numeric output from the math routines, then you can call math_chr, math_str, math_fill, math_fmt, or math_flush. These routines output single characters, output null-terminated strings, output strings with space filling, output formatted strings like printf, and flush the output. Output from these routines is diverted as described above. You can change the default output mode by calling math_setmode, and you can change the default number of digits printed by calling math_setdigits. These routines return the previous values. The possible modes are described in zmath.h. -------------- USING INTEGERS -------------- The arbitrary precision integer routines define a structure called a ZVALUE. This is defined in zmath.h. A ZVALUE contains a pointer to an array of integers, the length of the array, and a sign flag. The array is allocated using malloc, so you need to free this array when you are done with a ZVALUE. To do this, you should call zfree with the ZVALUE as an argument (or call freeh with the pointer as an argument) and never try to free the array yourself using free. The reason for this is that sometimes the pointer points to one of two statically allocated arrays which should NOT be freed. The ZVALUE structures are passed to routines by value, and are returned through pointers. For example, to multiply two small integers together, you could do the following: ZVALUE z1, z2, z3; itoz(3L, &z1); itoz(4L, &z2); zmul(z1, z2, &z3); Use zcopy to copy one ZVALUE to another. There is no sharing of arrays between different ZVALUEs even if they have the same value, so you MUST use this routine. Simply assigning one value into another will cause problems when one of the copies is freed. However, the special ZVALUE values _zero_ and _one_ CAN be assigned to variables directly, since their values of 0 and 1CÈDÈEÈFÈGÈHÈIÈJÈKÈLÈMÈNÈ are so common that special checks are made for them. For initial values besides 0 or 1, you need to call itoz to convert a long value into a ZVALUE, as shown in the above example. Or alternatively, for larger numbers you can use the atoz routine to convert a string which represents a number into a ZVALUE. The string can be in decimal, octal, hex, or binary according to the leading digits. Always make sure you free a ZVALUE when you are done with it or when you are about to overwrite an old ZVALUE with another value by passing its address to a routine as a destination value, otherwise memory will be lost. The following shows an example of the correct way to free memory over a long sequence of operations. ZVALUE z1, z2, z3; z1 = _one_; atoz("12345678987654321", &z2); zadd(z1, z2, &z3); zfree(z1); zfree(z2); zsquare(z3, &z1); zfree(z3); itoz(17L, &z2); zsub(z1, z2, &z3); zfree(z1); zfree(z2); zfree(z3); There are some quick checks you can make on integers. For example, whether or not they are zero, negative, even, and so on. These are all macros defined in zmath.h, and should be used instead of checking the parts of the ZVALUE yourself. Examples of such checks are: ziseven(z) (number is even) zisodd(z) (number is odd) ziszero(z) (number is zero) zisneg(z) (number is negative) zispos(z) (number is positive) zisunit(z) (number is 1 or -1) zisone(z) (number is 1) zisnegone(z) (number is -1) zistwo(z) (number is 2) zisabstwo(z) (number is 2 or -2) zisabsleone(z) (number is -1, 0 or 1) zislezero(z) (number is <= 0) zisleone(z) (number is <= 1) zge16b(z) (number is >= 2^16) zge24b(z) (number is >= 2^24) zge31b(z) (number is >= 2^31) zge32b(z) (number is >= 2^32) zge64b(z) (number is >= 2^64) Typically the largest unsigned long is typedefed to FULL. The following macros are useful in dealing with this data type: MAXFULL (largest positive FULL value) MAXUFULL (largest unsigned FULL value) zgtmaxfull(z) (number is > MAXFULL) zgtmaxufull(z) (number is > MAXUFULL) zgtmaxlong(z) (number is > MAXLONG, largest long value) zgtmaxulong(z) (number is > MAXULONG, largest unsigned long value) If zgtmaxufull(z) is false, then one may quickly convert the absolute value of number into a full with the macro: ztofull(z) (convert abs(number) to FULL) ztoulong(z) (convert abs(number) to an unsigned long) ztolong(z) (convert abs(number) to a long) If the value is too large for ztofull(), ztoulong() or ztolong(), only the low order bits converted. There are two types of comparisons you can make on ZVALUEs. This is whether or not they are equal, or the ordering on size of the numbers. The zcmp function tests whether two ZVALUEs are equal, returning TRUE if they differ. The zrel function tests the relative sizes of two ZVALUEs, returning -1 if the first one is smaller, 0 if they are the same, and 1 if the first one is larger. --------------- USING FRACTIONS --------------- The arbitrary precision fractional routines define a structure called NUMBER. This is defined in qmath.h. A NUMBER contains two ZVALUEs for the numerator and denominator of a fraction, and a count of the number of uses there are for this NUMBER. The numerator and denominator are always in lowest terms, and the sign of the number is contained in the numerator. The denominator is always positive. If the NUMBER is an integer, the denominator has the value 1. Unlike ZVALUEs, NUMBERs are passed using pointers, and pointers to them are returned by functions. So the basic type for using fractions is not really (NUMBER), but is (NUMBER *). NUMBERs are allocated using the qalloc routine. This returns a pointer to a number which has the value 1. Because of the special property of a ZVALUE of 1, the numerator and denominator of this returned value can simply be overwritten with new ZVALUEs without needing to free them first. The following illustrates this: NUMBER *q; q = qalloc(); itoz(55L, &q->num); A better way to create NUMBERs with particular values is to use the itoq, iitoq, or atoq functions. Using itoq makes a long value into a NUMBER, using iitoq makes a pair of longs into the numerator and denominator of a NUMBER (reducing them first if needed), and atoq converts a string representing a number into the corresponding NUMBER. The atoq function accepts input in integral, fractional, real, or exponential formats. Examples of allocating numbers are: NUMBER *q1, *q2, *q3; q1 = itoq(66L); q2 = iitoq(2L, 3L); q3 = atoq("456.78"); Also unlike ZVALUEs, NUMBERs are quickly copied. This is because they contain a link count, which is the number of pointers there are to the NUMBER. The qlink macro is used to copy a pointer to a NUMBER, and simply increments the link count and returns the same pointer. Since it is a macro, the argument should not be a function call, but a real pointer variable. The qcopy routine will actually make a new copy of a NUMBER, with a new link count of 1. This is not usually needed. NUMBERs are deleted using the qfree routine. This decrements the link count in the NUMBER, and if it reaches zero, then it will deallocate both of the ZVALUEs contained within the NUMBER, and then puts the NUMBER structure onto a free list for quick reuse. The following is an example of allocating NUMBERs, copying them, adding them, and finally deleting them again. NUMBER *q1, *q2, *q3; q1 = itoq(111L); q2 = qlink(q1); q3 = qqadd(q1, q2); qfree(q1); qfree(q2); qfree(q3); Because of the passing of pointers and the ability to copy numbers easily, you might wish to use the rational number routines even for integral calculations. They might be slightly slower than the raw integral routines, but are more convenient to program with. The prototypes for the fractional routines are defined in qmath.h. Many of the definitions for integer functions parallel the ones defined in zmath.h. But there are also functions used only for fractions. Examples of these are qnum to return the numerator, qden to return the denominator, qint to return the integer part of, qfrac to return the fractional part of, and qinv to invert a fraction. There are some transcendental functions in the link library, such as sin and cos. These cannot be evaluated exactly as fractions. Therefore, they accept another argument which tells how accurate you want the result. This is an "epsilon" value, and the returned value will be within that quantity of the correct value. This is usually an absolute difference, but for some functions (such as exp), this is a relative difference. For example, to calculate sin(0.5) to 100 decimal places, you could do: NUMBER *q, *ans, *epsilon; q = atoq("0.5"); epsilon = atoq("1e-100"); ans = qsin(q, epsilon); There are many convenience macros similar to the ones for ZVALUEs which can give quick information about NUMBERs. In addition, there are some new ones applicable to fractions. These are all defined in qmath.h. Some of these macros are: qiszero(q) (number is zero) qisneg(q) (number is negative) qispos(q) (number is positive) qisint(q) (number is an integer) qisfrac(q) (number is fractional) qisunit(q) (number is 1 or -1) qisone(q) (number is 1) qisnegone(q) (number is -1) qistwo(q) (number is 2) qiseven(q) (number is an even integer) qisodd(q) (number is an odd integer) qistwopower(q) (number is a power of 2 >= 1) The comparisons for NUMBERs are similar to the ones for ZVALUEs. You use the qcmp and qrel functions. There are four predefined values for fractions. You should qlink them when you want to use them. These are _qzero_, _qone_, _qnegone_, and _qonehalf_. These have the values 0, 1, -1, and 1/2. An example of using them is: NUMBER *q1, *q2; q1 = qlink(&_qonehalf_); q2 = qlink(&_qone_); --------------------- USING COMPLEX NUMBERS --------------------- The arbitrary precision complex arithmetic routines define a structure called COMPLEX. This is defined in cmath.h. This contains two NUMBERs for the real and imaginary parts of a complex number, and a count of the number of links there are to this COMPLEX number. The complex number routines work similarly to the fractional routines. You can allocate a COMPLEX structure using comalloc (NOT calloc!). You can construct a COMPLEX number with desired real and imaginary fractional parts using qqtoc. You can copy COMPLEX values using clink which increments the link count. And you free a COMPLEX value using cfree. The following example illustrates this: NUMBER *q1, *q2; COMPLEX *c1, *c2, *c3; q1 = itoq(3L); q2 = itoq(4L); c1 = qqtoc(q1, q2); qfree(q1); qfree(q2); c2 = clink(c1); c3 = cmul(c1, c2); cfree(c1); cfree(c2); cfree(c3); As a shortcut, when you want to manipulate a COMPLEX value by a real value, you can use the caddq, csubq, cmulq, and cdivq routines. These accept one COMPLEX value and one NUMBER value, and produce a COMPLEX value. There is no direct routine to convert a string value into a COMPLEX value. But you can do this yourself by converting two strings into two NUMBERS, and then using the qqtoc routine. COMPLEX values are always returned from these routines. To split out the real and imaginary parts into normal NUMBERs, you can simply qlink the two components, as shown in the following example: COMPLEX *c; NUMBER *rp, *ip; c = calloc(); rp = qlink(c->real); ip = qlink(c->imag); There are many macros for checking quick things about complex numbers, similar to the ZVALUE and NUMBER macros. In addition, there are some only used for complex numbers. Examples of macros are: cisreal(c) (number is real) cisimag(c) (number is pure imaginary) ciszero(c) (number is zero) cisnegone(c) (number is -1) cisone(c) (number is 1) cisrunit(c) (number is 1 or -1) cisiunit(c) (number is i or -i) cisunit(c) (number is 1, -1, i, or -i) cistwo(c) (number is 2) cisint(c) (number is has integer real and imaginary parts) ciseven(c) (number is has even real and imaginary parts) cisodd(c) (number is has odd real and imaginary parts) There is only one comparison you can make for COMPLEX values, and that is for equality. The ccmp function returns TRUE if two complex numbers differ. There are three predefined values for complex numbers. You should clink them when you want to use them. They are _czero_, _cone_, and _conei_. These have the values 0, 1, and i. ---------------- LAST THINGS LAST ---------------- If you wish, when you are all doen you can call libcalc_call_me_last() to free a small amount of storage associated with the libcalc_call_me_first() call. This is not required, but is does bring things to a closure. The function libcalc_call_me_last() takes no args and returns void. You need call libcalc_call_me_last() only once. ## Copyright (C) 1999 David I. Bell and 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: LIBRARY,v 30.1 2007/03/16 11:09:46 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/RCS/LIBRARY,v $ ## ## Under source code control: 1993/07/30 19:44:49 ## File existed as early as: 1993 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME indices - indices for specified matrix or association element SYNOPSIS indices(V, index) TYPES V matrix or association index integer return list with up to 4 elements DESCRIPTION For 0 <= index < size(V), indices(V, index) returns list(i_0, i_1, ...) for which V[i_0, i_1, ...] is the same lvalue as V[[index]]. For other values of index, a null value is returned. This function can be useful for determining those elements for which the indices satisfy some condition. This is particularly so for associations since these have no simple relation between the double-bracket index and the single-bracket indices, which may be non-integer numbers or strings or other types of value. The information provided by indices() is often required after the use of search() or rsearch() which, when successful, return the double-bracket index of the item found. EXAMPLE ; mat M[2,3,1:5] ; indices(M, 11) list (3 elements, 2 nonzero): [[0]] = 0 [[1]] = 2 [[2]] = 2 ; A = assoc(); ; A["cat", "dog"] = "fight"; ; A[2,3,5,7] = "primes"; ; A["square", 3] = 9 ; indices(A, search(A, "primes")) list (4 elements, 4 nonzero): [[0]] = 2 [[1]] = 3 [[2]] = 5 [[3]] = 7 LIMITS abs(index) < 2^31 LINK LIBRARY LIST* associndices(ASSOC *ap, long index) LIST* matindices(MATRIX *mp, long index) SEE ALSO assoc, 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: indices,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/indices,v $ ## ## Under source code control: 1999/11/16 08:02:03 ## File existed as early as: 1999 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME argv - count or value of a calc command line supplied argument SYNOPSIS argv([n]) TYPES n nonnegative integer return any DESCRIPTION Without args, this builtin returns the number of calc command line strings available. If the numeric arg is supplied, then the corresponding command line string is return, if it exists. Otherwise a nul() value is returned. In keeping with the argc/argv convention of C, argv(0) will refer to the 1st argv string, and argv(argv()-1) will refer to the last. This differs from the way the param() builtin works. By default, calc will evaluate all of its command line arguments. However, if calc is invoked with -s, all non-dashed options will be left as unevaluated strings. Thus: calc -i 2+2 will cause calc to print 4 and enter interactive mode. In this case argv() will return 0. On the other hand: calc -i -s 2+2 will cause calc to interactive mode. The argv() builtin will return 1 and argv(0) will return the string "2+2". EXAMPLE $ calc -s a bb ccc ; argc = argv(); ; for (i = 0; i < argc; i++) print "argv[": i : '] = "': argv(i) : '"'; argv[0] = "a" argv[1] = "bb" argv[2] = "ccc" LIMITS 0 <= n < 2^31 LINK LIBRARY none SEE ALSO param, system, usage ## 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: argv,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/argv,v $ ## ## Under source code control: 1999/11/23 19:45:05 ## File existed as early as: 1999 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Using files The calculator provides some functions which allow the program to read or write text files. These functions use stdio internally, and the functions appear similar to some of the stdio functions. Some differences do occur, as will be explained here. Names of files are subject to ~ expansion just like the C or Korn shell. For example, the file name: ~/.rc.cal refers to the file '.rc.cal' under your home directory. The file name: ~chongo/.rc.cal refers to the a file 'rc.cal' under the home directory of 'chongo'. A file can be opened for either reading, writing, or appending. To do this, the 'fopen' function is used, which accepts a filename and an open mode, both as strings. You use 'r' for reading, 'w' for writing, and 'a' for appending. For example, to open the file 'foo' for reading, the following could be used: fd = fopen('foo', 'r'); If the open is unsuccessful, the numeric value of errno is returned. If the open is successful, a value of type 'file' will be returned. You can use the 'isfile' function to test the return value to see if the open succeeded. You should assign the return value of fopen to a variable for later use. File values can be copied to more than one variable, and using any of the variables with the same file value will produce the same results. If you overwrite a variable containing a file value or don't save the result of an 'fopen', the opened file still remains open. Such 'lost' files can be recovered by using the 'files' function. This function either takes no arguments or else takes one integer argument. If no arguments are given, then 'files' returns the maximum number of opened files. If an argument is given, then the 'files' function uses it as an index into an internal table of open files, and returns a value referring to one the open files. If that entry in the table is not in use, then the null value is returned instead. Index 0 always refers to standard input, index 1 always refers to standard output, and index 2 always refers to standard error. These three files are already open by the calculator and cannot be closed. As an example of using 'files', if you wanted to assign a file value which is equivalent to stdout, you could use: stdout = files(1); The 'fclose' function is used to close a file which had been opened. When this is done, the file value associated with the file remains a file value, but appears 'closed', and cannot be used in further file-related calls (except fclose) without causing errors. This same action occurs to all copies of the file value. You do not need to explicitly close all the copies of a file value. The 'fclose' function returns the numeric value of errno if there had been an error using the file, or the null value if there was no error. The builtin 'strerror' can be use to convert an errno number into a slightly more meaningful error message: badfile = fopen("not_a_file", "r"); if (!isfile(badfile)) { print "error #" : badfile : ":", strerror(badfile); } File values can be printed. When this is done, the filename of the opened file is printed inside of quote marks. If the file value had been closed, then the null string is printed. If a file value is the result of a top-level expression, then in addition to the filename, the open mode, file position, and possible EOF, error, and closed status is also displayed. File values can be used inside of 'if' tests. When this is done, an opened file is TRUE, and a closed file is FALSE. As an example of this, the following loop will print the names of all the currently opened non-standard files with their indexes, and then close them: for (i = 3; i < files(); i++) { if (files(i)) { print i, files(i); fclose(files(i)); } } The functions to read from files are 'fgetline' and 'fgetc'. The 'fgetline' function accepts a file value, and returns the next input line from a file. The line is returned as a string value, and does not contain the end of line character. Empty lines return the null string. When the end of file is reached, fgetline returns the null value. (Note the distinction between a null string and a null value.) If the line contained a numeric value, then the 'eval' function can then be used to convert the string to a numeric value. Care should be used when doing this, however, since eval will generate an error if the string doesn't represent a valid expression. The 'fgetc' function returns the next character from a file as a single character string. It returns the null value when end of file is reached. The 'printf' and 'fprintf' functions are used to print results to a file (which could be stdout or stderr). The 'fprintf' function accepts a file variable, whereas the 'printf' function assumes the use of 'files(1)' (stdout). They both require a format string, which is used in almost the same way as in normal C. The differences come in the interpretation of values to be printed for various formats. Unlike in C, where an unmatched format type and value will cause problems, in the calculator nothing bad will happen. This is because the calculator knows the types of all values, and will handle them all reasonably. What this means is that you can (for example), always use %s or %d in your format strings, even if you are printing a non- string or non-numeric value. For example, the following is valid: printf("Two values are %d and %s\n", "fred", 4567); and will print "Two values are fred and 4567". Using particular format characters, however, is still useful if you wish to use width or precision arguments in the format, or if you wish to print numbers in a particular format. The following is a list of the possible numeric formats: %d print in currently defined numeric format %f print as floating point %e print as exponential %r print as decimal fractions %x print as hex fractions %o print as octal fractions %b print as binary fractions Note then, that using %d in the format makes the output configurable by using the 'config' function to change the output mode, whereas the other formats override the mode and force the output to be in the specified format. Using the precision argument will override the 'config' function to set the number of decimal places printed. For example: printf("The number is %.100f\n", 1/3); will print 100 decimal places no matter what the display configuration value is set to. The %s and %c formats are identical, and will print out the string representation of the value. In these cases, the precision argument will truncate the output the same way as in standard C. If a matrix or list is printed, then the output mode and precision affects the printing of each individual element. However, field widths are ignored since these values print using multiple lines. Field widths are also ignored if an object value prints on multiple lines. The functions 'fputc' and 'fputs' write a character and string to a file respectively. The final file-related functions are 'fflush', 'ferror', and 'feof'. The 'fflush' function forces buffered output to a file. The 'ferror' function returns nonzero if an error had occurred to a file. The 'feof' function returns nonzero if end of file has been reached while reading a file. The 'strprintf' function formats output similarly to 'printf', but the output is returned as a string value instead of being printed. ## 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: file,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/file,v $ ## ## Under source code control: 1991/07/21 04:37:19 ## 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 sizeof - number of bytes required for value SYNOPSIS sizeof(x) TYPES x any return integer DESCRIPTION This is analogous to the C operator sizeof for the value only. It attempts to assess the number of bytes in memory used to store a value and all of its components. Unlike memsize(x), this builtin does not include the size of the overhead. Unlike size(x), this builtin incldues the trailing \0 byte on the end of strings. For numeric values, sizeof(x) ignores the demoninator if 'x' is an integer. For complex values, sizeof(x) ignores the imaginary part if 'x' is real. Because the 0, 1 and -1 numeric values are shared static values, sizeof(x) reports such values as having 0 bytes of storage. The number returned by sizeof(x) may be less than the actual number used because, for example, more memory may have been allocated for a string than is used: only the characters up to and including the first '\0' are counted in calculating the contribution of the string to sizeof(x). The number returned by sizeof(x) may be greater (and indeed substantially greater) than the number of bytes actually used. For example, after: a = sqrt(2); mat A[3] = {a, a, a}; the numerical information for a, A[0], A[1], A[2] are stored in the same memory, so the memory used for A is the same as if its 3 elements were null values. The value returned by sizeof(A) is calculated as A were defined by: mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. Similar sharing of memory occurs with literal strings. For associative arrays, only the value part of the name/value pair is counted. The minimum value for sizeof(x) occurs for the null and error values. EXAMPLES The results for examples like these will depend to some extent on the system being used. The following were for an SGI R4k machine in 32-bit mode: ; print sizeof(null()), sizeof(0), sizeof(3), sizeof(2^32 - 1), sizeof(2^32) 8 68 68 68 72 ; x = sqrt(2, 1e-100); print sizeof(x), sizeof(num(x)), sizeof(den(x)) 148 108 108 ; print sizeof(list()), sizeof(list(1)), sizeof(list(1,2)) 28 104 180 ; print sizeof(list()),sizeof(list(1)),sizeof(list(1,2)),sizeof(list(1,2,3)) 28 104 180 256 ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; ; print sizeof(A), sizeof(B), sizeof(C), sizeof(D) 124 192 260 680056 ; obj point {x,y,z} ; obj point P = {1,2,3}; print sizeof(P) 274 LIMITS It is assumed sizeof(x) will fit into a system long integer. LINK LIBRARY none SEE ALSO size, fsize, strlen, digits ## 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: sizeof,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sizeof,v $ ## ## Under source code control: 1996/05/24 02:04:04 ## 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 factor - smallest prime factor not exceeding specified limit SYNOPSIS factor(n [, limit [, err]]) TYPES n integer limit integer with abs(limit) < 2^32, defaults to 2^32 - 1 err integer return positive integer or err DESCRIPTION This function ignores the signs of n and limit, so here we shall assume n and limit are both nonnegative. If n has a prime proper factor less than or equal to limit, then factor(n, limit) returns the smallest such factor. NOTE: A proper factor of n>1 is a factor < n. In other words, for n>1 is not a proper factor of itself. The value 1 is a special case because 1 is a proper factor of 1. When every prime proper factor of n is greater than limit, 1 is returned. In particular, if limit < 2, factor(n, limit) always returns 1. Also, factor(n,2) returns 2 if and only if n is even and n > 2. If 1 < n < nextprime(limit)^2, then f(n, limit) == 1 <==> n is prime. For example, if 1 < n < 121, n is prime if and only if f(n,7) == 1. If limit >= 2^32, factor(n, limit) causes an error and factor(n, limit, err) returns the value of err. EXAMPLE ; print factor(35,4), factor(35,5), factor(35), factor(-35) 1 5 5 5 ; print factor(2^32 + 1), factor(2^47 - 1), factor(2^59 - 1) 641 2351 179951 LIMITS limit < 2^32 LINK LIBRARY FLAG zfactor(ZVALUE n, ZVALUE limit, ZVALUE *res) SEE ALSO isprime, lfactor, nextcand, nextprime, prevcand, prevprime, pfact, pix, ptest ## 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: factor,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/factor,v $ ## ## Under source code control: 1995/12/18 12:34:57 ## 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 cfappr - approximate a real number using continued fractions SYNOPSIS cfappr(x [,eps [,rnd]]) or cfappr(x, n [,rnd]) TYPES x real eps real with abs(eps) < 1, defaults to epsilon() n real with n >= 1 rnd integer, defaults to config("cfappr") return real DESCRIPTION If x is an integer or eps is zero, either form returns x. If abs(eps) < 1, cfappr(x, eps) returns the smallest-denominator number in one of the three intervals, [x, x + abs(eps)], [x - abs(eps], x], [x - abs(eps)/2, x + abs(eps)/2]. If n >= 1 and den(x) > n, cfappr(x, n) returns the nearest above, nearest below, or nearest, approximation to x with denominator less than or equal to n. If den(x) <= n, cfappr(x,n) returns x. In either case when the result v is not x, how v relates to x is determined by bits 0, 1, 2 and 4 of the argument rnd in the same way as these bits are used in the functions round() and appr(). In the following y is either eps or n. rnd sign of remainder x - v 0 sgn(y) 1 -sgn(y 2 sgn(x), "rounding to zero" 3 -sgn(x), "rounding from zero" 4 +, "rounding down" 5 -, "rounding up" 6 sgn(x/y) 7 -sgn(x/y) If bit 4 of rnd is set, the other bits are irrelevant for the eps case; thus for 16 <= rnd < 24, cfappr(x, eps, rnd) is the smallest-denominator number differing from x by at most abs(eps)/2. If bit 4 of rnd is set and den(x) > 2, the other bits are irrelevant for the bounded denominator case; in the case of two equally near nearest approximations with denominator less than n, cfappr(x, n, rnd) returns the number with smaller denominator. If den(x) = 2, bits 0, 1 and 2 of rnd are used as described above. If -1 < eps < 1, cfappr(x, eps, 0) may be described as the smallest denominator number in the closed interval with end-points x and x - eps. It follows that if abs(a - b) < 1, cfappr(a, a - b, 0) gives the smallest denominator number in the interval with end-points a and b; the same result is returned by cfappr(b, b - a, 0) or cfappr(a, b - a, 1). If abs(eps) < 1 and v = cfappr(x, eps, rnd), then cfappr(x, sgn(eps) * den(v), rnd) = v. If 1 <= n < den(x), u = cfappr(x, n, 0) and v = cfappr(x, n, 1), then u < x < v, den(u) <= n, den(v) <= n, den(u) + den(v) > n, and v - u = 1/(den(u) * den(v)). If x is not zero, the nearest approximation with numerator not exceeding n is 1/cfappr(1/x, n, 16). EXAMPLE ; c = config("mode", "frac") ; x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1); ; print u, v, x - u, v - x, v - u, cfappr(x, 10, 16) 10/7 13/9 1/210 1/90 1/63 10/7 ; pi = pi(1e-10) ; print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16) 311/99 22/7 355/113 ; x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1); ; print u, v, x - u, v - x, cfappr(x,4,16) 4/3 3/2 1/12 1/12 3/2 LIMITS none LINK LIBRARY NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R) SEE ALSO appr, cfsim ## 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: cfappr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cfappr,v $ ## ## Under source code control: 1994/09/30 01:23:59 ## 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 rcsq - REDC squaring SYNOPSIS rcsq(x, m) TYPES x integer m odd positive integer return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines) and N the number of words (base-B digits) in the representation of m. Then rcsq(x,m) returns the value of B^-N * x^2 % m, where the inverse implicit in B^-N is modulo m and the modulus operator % gives the least non-negative residue. The normal use of rcsq() may be said to be that of squaring modulo m a value encoded by rcin() and REDC functions, as in: rcin(x^2, m) = rcsq(rcin(x,m), m) from which we get: x^2 % m = rcout(rcsq(rcin(x,m), m), m) Alternatively, x^2 % m may be evaluated usually more quickly by: x^2 % m = rcin(rcsq(x,m), m). RUNTIME If the value of m in rcsq(x,m) is being used for the first time in a REDC function, the information required for the REDC algorithms is calculated and stored for future use, possibly replacing an already stored valued, in a table covering up to 5 (i.e. MAXREDC) values of m. The runtime required for this is about two times that required for multiplying two N-word integers. Two algorithms are available for evaluating rcsq(x, m), the one which is usually faster for small N is used when N < config("redc2"); the other is usually faster for larger N. If config("redc2") is set at about 90 and 0 <= x < m, the runtime required for rcsq(x, m)i is at most about f times the runtime required for an N-word by N-word multiplication, where f increases from about 1.1 for N = 1 to near 2.8 for N > 90. More runtime may be required if x has to be reduced modulo m. EXAMPLE Using a 64-bit machine with B = 2^32: ; for (i = 0; i < 9; i++) print rcsq(i,9),:; print; 0 7 1 0 4 4 0 1 7 ; for (i = 0; i < 9; i++) print rcin((rcsq(i,9),:; print; 0 1 4 0 7 7 0 4 1 LIMITS none LINK LIBRARY void zredcsquare(REDC *rp, ZVALUE z1, ZVALUE *res) SEE ALSO rcin, rcout, rcmul, rcpow ## 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: rcsq,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcsq,v $ ## ## Under source code control: 1996/02/25 02:22:21 ## 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 isassoc - whether a value is an association. SYNOPSIS isassoc(x) TYPES x any, &any return int DESCRIPTION Determine if x is an association. This function will return 1 if x is an association, 0 otherwise. EXAMPLE ; a = assoc() ; print isassoc(a), isassoc(1) 1 0 LIMITS none LINK LIBRARY none SEE ALSO assoc, isatty, isblk, 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 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: isassoc,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isassoc,v $ ## ## Under source code control: 1994/10/21 02:21:27 ## 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 fflush - flush output to file SYNOPSIS fflush(fd) TYPES fd file return nil DESCRIPTION This function forces a buffered output to the file associated with fd. EXAMPLE ; fd = fopen("/tmp/file", "w") ; fputc(fd, "@"); ; fflush(fd) LIMITS fd must be associated with an open file 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: fflush,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fflush,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 # SYNOPSIS #!/usr/local/src/cmd/calc/calc -q -f # x x # y ## comment TYPES x, y integer or real return integer (uniary operator case) integer or real (binary operator case) DESCRIPTION The pound sign or sharp sign "#" has special meaning in calc. As a uniary operator: # value returns the number of 1 bits, or pop-count of the absolute value of the numerator (abs(num(value))). Therefore when x is a non-negative integer , # x is the pop-count of x. And thus when x is a negative integer, # x returns the pop-count of abs(x). And in the general case when x is a real, # x returns the pop-count of abs(num(x)). As a binary operator: x # y returns abs(x-y), the absolute value of the difference. When two or more pound signs in a row start a comment: ## this is a comment ### this is also a comment print "this will print"; ## but this will not because it is a comment A pound sign followed by a bang also starts a comment: #! strictly speaking, this is a comment print "this is correct but not recommended" #! acts like ## On POSIX / Un*X / Linux / BSD conforming systems, when an executable starts with the two bytes # and !, the remainder of the 1st line (up to an operating system imposed limit) is taken to be the path to the shell (plus shell arguments) that is to be executed. The kernel appends the filename of the executable as a final argument to the shell. For example, of an executable file contains: #!/usr/local/src/cmd/calc/calc -q -f /* NOTE: The #! above must start in column 1 of the 1st line */ /* The 1st line must end with -f */ ## Single # shell comments don't work, use two or more print "2+2 =", 2+2; When the above file it is executed by the kernel, it will print: 2+2 = 4 Such files are known to calc as cscripts. See "help cscript" for examples. It is suggested that the -q be added to the first line to disable the reading of the startup scripts. It is not mandatory. The last argument of the first line must be -f without the filename because the kernel will supply the cscript filename as a final argument. The final -f also implies -s. See "help usage" for more information. EXAMPLE ; #3 2 ; #3.5 3 ; 4 # 5 1 ; 5 # 4 1 ; pi() # exp(1) 0.4233108251307480031 ; exp(1) # pi() 0.4233108251307480031 ; ## this is a comment LIMITS none LINK LIBRARY none SEE ALSO cscript, unexpected, usage ## Copyright (C) 2007 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: pound,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pound,v $ ## ## Under source code control: 2007/02/06 14:09 ## File existed as early as: 2007 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME atan - inverse trigonometric tangent SYNOPSIS atan(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the atan of x to a multiple of eps with error less in absolute value than .75 * eps. v = atan(x) is the number in (-pi/2, pi/2) for which tan(v) = x. EXAMPLE ; print atan(2, 1e-5), atan(2, 1e-10), atan(2, 1e-15), atan(2, 1e-20) 1.10715 1.1071487178 1.107148717794091 1.10714871779409050302 LIMITS none LINK LIBRARY NUMBER *qatan(NUMBER *x, NUMBER *eps) SEE ALSO asin, acos, asec, acsc, acot, 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: atan,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/atan,v $ ## ## Under source code control: 1994/03/19 01:40:25 ## 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 putenv - set the value of an environment variable SYNOPSIS putenv(env [,val]) TYPES env str val str return int DESCRIPTION This function will set or change the value of an environment variable. Zero is returned if the environment variable was successfully set, otherwise a non-zero result is returned. When called with 1 arg, env must be a string of the form: "envname=envval" This sets the environment variable "envname" to the value "envval". The 2 arg form is equivalent to: putenv(strcat(env, "=", val)) EXAMPLE ; putenv("name", "value") 0 ; getenv("name") "value" ; putenv("name=val2") 0 ; getenv("name") "val2" ; isnull(getenv("unknown")) 1 LIMITS With 1 arg, env must contain at least 1 '=' character. LINK LIBRARY none SEE ALSO getenv ## 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: putenv,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/putenv,v $ ## ## Under source code control: 1995/07/09 03:48:57 ## 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 remove - remove the last member of a list SYNOPSIS remove(lst) TYPES lst lvalue whose current value is a list return any DESCRIPTION If lst has no members, remove(lst) returns the null value and does not change lst. If lst has n members where n > 0, remove(lst) returns the value of lst[[n-1]] and deletes this value from the end of the lst, so that lst now has n - 1 members and for 0 <= i < n - 1, lst[[i]] returns what it would have returned before the remove operation. EXAMPLE ; lst = list(2,"three") list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" ; remove(lst) "three" ; print lst list (1 elements, 1 nonzero): [[0]] = 2 ; remove(lst) 2 ; print lst list (0 elements, 0 nonzero) ; remove(lst) ; print lst list (0 elements, 0 nonzero) LIMITS none LINK LIBRARY none SEE ALSO append, delete, insert, islist, pop, push, rsearch, search, select, size ## 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: remove,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/remove,v $ ## ## Under source code control: 1996/03/12 23:10:01 ## 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 xor - bitwise exclusive or of a set of integers SYNOPSIS xor(x1, x2, ...) TYPES x1, x2, ... integer return integer DESCRIPTION Compute the bitwise exclusive or of a set of integers. For one argument xor(x1) returns x1. For two arguments, xor(x1,x2) returns the bitwise exclusive or of x1 and x2. For each bit pair: 0 0 xor returns 0 0 1 xor returns 1 1 0 xor returns 1 1 1 xor returns 0 For more than two arguments, xor(x1,x2,x3, ..., xn) returns: xor(...xor(xor(x1,x2), x3), ... xn) EXAMPLE ; print xor(2), xor(5, 3, -7, 2, 9) 2 10 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY NUMBER *qxor(NUMBER *x1, NUMBER *x2) SEE ALSO operator ## 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: xor,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/xor,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 errno - return or set a stored error-number SYNOPSIS errno([errnum]) TYPES errnum integer, 0 <= errnum <= 32767 return integer DESCRIPTION Whenever an operation or evaluation of function returns an error-value, the numerical code for that value is stored as calc_errno. errno() returns the current value of calc_errno. errno(errnum) sets calc_errno to the value errnum and returns its previous value. To detect whether an error occurs during some sequence of operations, one may immediately before that sequence set the stored error-number to zero by errno(0), and then after the operations, whether or not an error has occurred will be indicated by errno() being nonzero or zero. If a non-zero value is returned, that value will be the code for the most recent error encountered. The default argument for the functions error() and strerror() is the currently stored error-number; in particular, if no error-value has been returned after