the last errno(0), strerror() will return "No error". EXAMPLE Assuming there is no file with name "not_a_file" ; errno(0) 0 ; errmax(errcount()+4) 20 ; badfile = fopen("not_a_file", "r") ; print errno(), error(), strerror() 2 System error 2 No such file or directory ; a = 1/0 ; print errno(), error(), strerror() 10001 Error 10001 Division by zero LIMITS none LINK LIBRARY none SEE ALSO errmax, errcount, error, strerror, iserror, newerror, errorcodes, stoponerror ## 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: errno,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/errno,v $ ## ## Under source code control: 1994/10/27 03:05:08 ## 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 strscanf - formatted scan of a string SYNOPSIS strscanf(str, fmt, x_1, x_2, ...) TYPES str string fmt string x_1, x_2, ... lvalues return null, nonnegative integer, or error value DESCRIPTION If the str is "", the null value is returned. Otherwise, until the terminating null character of either fmt or str is reached, characters other than '%' and whitespace are read from fmt and compared with the corresponding characters read from str. If the characters match, reading continues. If they do not match an integer value is returned. If whitespace is encountered in fmt, starting at the current positions in fmt and str, any whitespace characters are skipped and reading and comparison begins as before if neither fmt nor str has reached its end. When a '%' is encountered in fmt, if this is immediately followed by another '%', the pair formed is considered as if one '%' were read and reading from fmt and fs continues if and only if fs has a matching '%'. A single '%' read from fmt is taken to indicate the beginning of a conversion specification field consisting in succession of: an optional '*', optional decimal digits, one of 'c', 's', 'n', 'f', 'e', 'i' or a scanset specifier. A scanset specifier starts with '[' and an optional '^', then an optional ']', then optional other characters, and ends with ']'. If any other sequence of characters follows the '%', characters before the first exceptional character (which could be the terminating null character of the fmt string) are ignored, e.g. the sequence " %*3d " does the same as " d ". If there is no '*' at the beginning of the specifier, and the list x_1, x_2, ... has not been exhausted, a value will be assigned to the next lvalue in the list; if no lvalue remains, the reading of fs stops and the function returns the number of assignments that have been made. Occurrence of '*' indicates that characters as specified are to be read but no assignment will be made. The digits, if any, read in the specifier are taken to be decimal digits of an integer which becomes the maximum "width" (number of characters to be read from str for string-type assignments); absence of digits or all zero digits in the 'c' case are taken to mean width = 1. Zero width for the other cases are treated as if infinite. Fewer characters than the specifier width may be read if end-of-file is reached or in the case of scanset specification, an exceptional character is encountered. If the ending character is 'c', characters are read from fs to form a string, which will be ignored or in the non-'*' case, assigned to the next lvalue. In the 's' case, reading to form the string starts at the first non-white character (if any) and ceases when end-of-file or further white space is encountered or the specified width has been attained. The cases 'f', 'e', 'r', 'i' may be considered to indicate expectation of floating-point, exponential, ratio, or integer representation of the number to be read. For example, 'i' might be taken to suggest a number like +2345; 'r' might suggest a representation like -27/49; 'e' might suggest a representation like 1.24e-7; 'f' might suggest a representation like 27.145. However, there is no test that the the result conforms to the specifier. Whatever the specifier in these cases, the result depends on the characters read until a space or other exceptional character is read. The characters read may include one or more occurrences of +, -, * as well as /, interpreted in the usual way, with left-to-right associativity for + and -, and for * and /. Also acceptable is a trailing i to indicate an imaginary number. For example the expression 2+3/4*7i+3.15e7 would be interpreted as for an ordinary evaluation. A decimal fraction may have more than one dot: dots after the first, which is taken to be the decimal point, are ignored. Thus "12.3..45e6.7" is interpreted as if it were "12.345e67". For the number specifiers 'f', 'e', 'r', 'i', any specified width is ignored. For the specifier 'n', the index of the next character to b e read is assigned to the corresponding lvalue. (Any width or skip specification is ignored.) EXAMPLE ; global a, b, c, d ; A = "abc xyz 234.6 alpha" ; strscanf(A, "%s%*[^0123456789]%f%n", a, b, c) 3 ; print a, b, c ; abc 234.6 13 ; strscanf(A, "%*13c%s", d); 1 ; print d ; alpha LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY int fscanfid(FILEID id, char *fmt, int count, VALUE **vals); SEE ALSO strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos, strprintf, strscan, substr ## Copyright (C) 1999-2006 Ernest Bowen ## ## 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: strscanf,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strscanf,v $ ## ## Under source code control: 1996/04/30 03:05:18 ## 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 sleep - suspend operation for a specified time SYNOPSIS sleep([n]) TYPES n non-negative real, defaults to 1 return integer or null value DESCRIPTION This uses the C-library sleep (if n is integral) or usleep (for non-integral n) to suspend operation for n seconds. If n is an integer and the sleep is stopped by an interruption, the number of seconds remaining is returned. One kind of use is to slow down output to permit easier reading of results, as in: ; for (i = 0; i < 100; i++) { ;; print sqrt(i); ;; sleep(1/2); ;; } The following illustrates what happens if ctrl-C is hit 5 seconds after the first command: ; print sleep(20) [Abort level 1] 15 EXAMPLE ; sleep(1/3); ; sleep(20); LIBRARY none SEE ALSO none ## Copyright (C) 2000-2006 Ernest Bowen ## ## 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: sleep,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $ ## ## Under source code control: 2000/12/14 01:33:00 ## File existed as early as: 2000 ## ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME quomod - assign quotient and remainder to two lvalues SYNOPSIS quomod(x, y, Q, R [, rnd]) TYPES x real y real Q null-or-real-valued lvalue with assign-to permission R null-or-real-valued lvalue with assign-to permission rnd nonnegative integer, defaults to config("quomod") return 0 or 1 DESCRIPTION If y is nonzero and x/y is an integer q, this function assigns q to Q and zero to R, and returns zero. If y is zero, zero is assigned to Q, x to R and 0 or 1 returned according as x is zero or nonzero. In the remaining case, y nonzero and x/y not an intger, there are two pairs (q,r) for which x = q * y + r, q is an integer, and abs(r) < abs(y). Depending on the low 5 bits of rnd, the q and r of one of these pairs will be assigned to Q and R respectively, and the number 1 returned. The effects of rnd can be described in terms of the way q is related to x/y, e.g. by rounding down, rounding towards zero, rounding to a nearest integeri, etc. or by properties of the remainder r, e.g. positive, negative, smallest, etc. The effects of the most commonly used values of rnd are described in the following table: rnd q r 0 round down. q = floor(x/y) same sign as y 1 round up, q = ceil(x/y) opposite sign to y 2 round to zero, q = int(x/y) same sign as x, r = y * frac(x/y) 3 round from zero oppsite sign to x 4 positive 5 negative 6 same sign as x/y 7 opposite sigh to x/y 8 to nearest even 9 to nearest odd For 16 <= rnd < 32, the rounding is to the nearest integer and r is the smallest (in absolute value) remainder except when x/y is halfway between consecutive integers, in which case the rounding is as given by the 4 low bits of rnd. Using rnd = 24 gives the cpmmonly used principle of rounding: round to the nearest integer, but take the even integer when there are two equally close integers. For more detail on the effects of rnd for values other than those listed above, see "help quo" and "help mod". In all cases, the values assigned to Q and R by quomod(x, y, Q, R, rnd) are the same as those given by Q = quo(x,y,rnd), R = mod(x,y,rnd). If config("quo") == rnd, Q is also given by quo(x,y) or x // y. If config("mod") == rnd, R is also given by mod(x,y) or x % y. The rounding used by the C language for x / y and x % y corresponds to rnd = 2. An error values is returned and the values of Q and R are not changed if Q and R are not both lvalues, or if the current value of any argument is not as specified above, or if Q or R has no-assign-to prptection, e.g. after protect(Q,1). EXAMPLE ; global u, v; ; global mat M[2]; ; print quomod(13,5,u,v), u, v, quomod(15.6,5.2,M[0],M[1]), M[0], M[1]; 1 2 3 0 3 0 ; A = assoc(); ; print quomod(13, 5, A[1], A[2]), A[1], A[2] ; 1 2 3 ; print quomod(10, -3, u, v), u, v; 1 -4 -2 ; print quomod(10, -3, u, v, 0), u, v; 1 -4 -2 ; print quomod(10, -3, u, v, 1), u, v; 1 -3 1 ; print quomod(10, -3, u, v, 2), u, v; 1 -3 1 ; print quomod(-10, -3, u, v, 2), u, v; 1 3 -1 LIMITS rnd < 2^31 LINK LIBRARY BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod) SEE ALSO //, %, quo, mod, floor. ceil, int. frac ## 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: quomod,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/quomod,v $ ## ## Under source code control: 1995/05/07 03:17:03 ## 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 re - real part of a real or complex number SYNOPSIS re(x) TYPES x real or complex return real DESCRIPTION If x = u + v * 1i where u and v are real, re(x) returns u. EXAMPLE ; print re(2), re(2 + 3i), re(-4.25 - 7i) 2 2 -4.25 LIMITS none LINK LIBRARY COMPLEX *c_imag(COMPLEX *x) SEE ALSO im ## 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: re,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/re,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 prevprime - nearest prime less than specified number SYNOPSIS prevprime(n [,err]) TYPES n real err integer return positive integer or err DESCRIPTION If n is an integer and 2 < n < 2^32, prevprime(n) returns the nearest prime less than n. If n <= 2 or >= 2^32 or n is fractional, prevprime(n, err) returns the value of err. Other cases cause a runtime error. EXAMPLE ; print prevprime(10), prevprime(100), prevprime(1e6) 7 97 999983 ; print prevprime(2,-99), prevprime(2^32,-99) -99 -99 ; print prevprime(2) pprime arg 1 is <= 2 LIMITS 2 < n < 2^32 LINK LIBRARY FULL zpprime(ZVALUE z) SEE ALSO factor, isprime, lfactor, nextcand, nextprime, prevcand, 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: prevprime,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/prevprime,v $ ## ## Under source code control: 1995/12/18 12:34:58 ## 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 strpos - print the first occurrence of a string in another string SYNOPSIS strpos(s, t) TYPES s str t str return int DESCRIPTION This function returns the location of the first occurance of the string t in the string s. If t is not found within s, 0 is returned. If t is found at the beginning of s, 1 is returned. EXAMPLE ; strpos("abcdefg", "c") 3 ; strpos("abcdefg", "def") 4 ; strpos("abcdefg", "defg") 4 ; strpos("abcdefg", "defgh") 0 ; strpos("abcdefg", "abc") 1 ; strpos("abcdefg", "xyz") 0 LIMITS none LINK LIBRARY none SEE ALSO strcat, strcpy, strerror, strlen, strncmp, strncpy, strprintf, strscan, strscanf, substr ## Copyright (C) 1999-2006 Ernest Bowen ## ## 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: strpos,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strpos,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 time - number of seconds since the Epoch SYNOPSIS time() TYPES return int DESCRIPTION The time() builtin returns the number of seconds since the Epoch, which according to Posix is: Thr Jan 1 00:00:00 UTC 1970 EXAMPLE ; print time(); 831081380 LIMITS none LINK LIBRARY none SEE ALSO ctime, runtime ## 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: time,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/time,v $ ## ## Under source code control: 1996/05/01 16:57:20 ## 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 lowbit - index of lowest nonzero bit in binary representation of integer SYNOPSIS lowbit(x) TYPES x nonzero integer return integer DESCRIPTION If x is a nonzero integer, lowbit(x) returns the index of the lowest nonzero bit in the binary representation of abs(x). Equivalently, lowbit(x) is the greatest integer for which x/2^n is an integer; the binary representation of x then ends with n zero bits. EXAMPLE ; print lowbit(2), lowbit(3), lowbit(4), lowbit(-15), lowbit(2^27) 1 0 2 0 27 LIMITS none LINK LIBRARY long zlowbit(ZVALUE x); SEE ALSO highbit, 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: lowbit,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/lowbit,v $ ## ## Under source code control: 1995/10/03 10:40: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 srand - seed the subtractive 100 shuffle pseudo-random number generator SYNOPSIS srand([seed]) TYPES seed integer, matrix of integers or rand state return rand state DESCRIPTION Seed the pseudo-random number using an subtractive 100 shuffle generator. For integer seed != 0: Any buffered rand generator bits are flushed. The subtractive table for the rand generator is loaded with the default subtractive table. The low order 64 bits of seed is xor-ed against each table value. The subtractive table is shuffled according to seed/2^64. The following calc code produces the same effect on the internal subtractive table: /* reload default subtractive table xor-ed with low 64 seed bits */ seed_xor = seed & ((1<<64)-1); for (i=0; i < 100; ++i) { subtractive[i] = xor(default_subtractive[i], seed_xor); } /* shuffle the subtractive table */ seed >>= 64; for (i=100; seed > 0 && i > 0; --i) { quomod(seed, i+1, seed, j); swap(subtractive[i], subtractive[j]); } Seed must be >= 0. All seed values < 0 are reserved for future use. The subtractive table pointers are reset to subtractive[36] and subtractive[99]. Last the shuffle table is loaded with successive values from the subtractive 100 generator. There is no limit on the size of a seed. On the other hand, extremely large seeds require large tables and long seed times. Using a seed in the range of [2^64, 2^64 * 100!) should be sufficient for most purposes. An easy way to stay within this range to to use seeds that are between 21 and 178 digits, or 64 to 588 bits long. To help make the generator produced by seed S, significantly different from S+1, seeds are scrambled prior to use. The internal function randreseed64 maps [0,2^64) into [0,2^64) in a 1-to-1 and onto fashion for every 64 bits of S. The purpose of the randreseed64() is not to add security. It simply helps remove the human perception of the relationship between the seed and the production of the generator. The randreseed64 process does not reduce the security of the rand generator. Every seed is converted into a different unique seed. No seed is ignored or favored. See the rand help file for details. For integer seed == 0: Restore the initial state and modulus of the rand generator. After this call, the rand generator is restored to its initial state after calc started. The subtractive 100 pointers are reset to subtractive[36] and subtractive[99]. Last the shuffle table is loaded with successive values from the subtractive 100 generator. The call: srand(0) restores the rand generator to the initial conditions at calc startup. For matrix arg: Any buffered random bits are flushed. The subtractive table with the first 100 entries of the matrix mod 2^64. The subtractive 100 pointers are reset to subtractive[36] and subtractive[99]. Last the shuffle table is loaded with successive values from the subtractive 100 generator. This form allows one to load the internal subtractive 100 generator with user supplied values. The randreseed64 process is NOT applied to the matrix values. For rand state arg: Restore the rand state and return the previous state. Note that the argument state is a rand state value (isrand(state) is true). Any internally buffered random bits are restored. All calls to srand(seed) return the previous state or current state in case of srand(). Their return value can be supplied to srand in restore the generator to that previous state: state = srand(123456789); newstate = srand(); /* save state */ x = rand(); ... srand(newstate); /* restore state to after srand(123456789) */ x1 = rand(); /* produces the same value as x */ ... srand(state); /* restore original state */ For no arg given: Return current s100 generator state. This call does not alter the generator state. This call allows one to take a snapshot of the current generator state. See the rand help file for details on the generator. EXAMPLE ; srand(0x8d2dcb2bed3212844f4ad31) RAND state ; state = srand(); ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 80 95 41 78 100 27 ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 122 109 12 95 80 32 ; state2 = srand(state); ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 80 95 41 78 100 27 ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 122 109 12 95 80 32 ; state3 = srand(); ; print state3 == state2; 1 ; print rand(); 10710588361472584495 LIMITS for matrix arg, the matrix must have at least 100 integers LINK LIBRARY RAND *zsrand(ZVALUE *pseed, MATRIX *pmat100) RAND *zsetrand(RAND *state) SEE ALSO seed, srandom, randbit, isrand, random, srandom, israndom ## 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: srand,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srand,v $ ## ## Under source code control: 1996/01/01 04:19:07 ## 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 tan - trigonometric tangent SYNOPSIS tan(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the tangent of x to a multiple of eps, with error less in absolute value than .75 * eps. EXAMPLE ; print tan(1, 1e-5), tan(1, 1e-10), tan(1, 1e-15), tan(1, 1e-20) 1.55741 1.5574077247 1.557407724654902 1.55740772465490223051 LIMITS unlike sin and cos, x must be real eps > 0 LINK LIBRARY NUMBER *qtan(NUMBER *x, NUMBER *eps) SEE ALSO sin, cos, sec, csc, cot, 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: tan,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/tan,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 iserror - test whether a value is an error value SYNOPSIS iserror(x) TYPES x any return zero or positive integer < 32768 DESCRIPTION If x is not an error value, zero is returned. If x is an error value, iserror(x) returns its error type. EXAMPLE ; a = error(99) print iserror(a), iserror(2 + a), iserror(2 + "a"), iserror(2 + 3) 99 99 3 0 LIMITS none LINK LIBRARY none SEE ALSO error, errorcodes, stoponerror, isassoc, isatty, isblk, isconfig, isdefined, 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: iserror,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/iserror,v $ ## ## Under source code control: 1995/12/18 03:30:59 ## 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 asin - inverse trigonometric sine SYNOPSIS asin(x [,eps]) TYPES x real, -1 <= x <= 1 eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the asin of x to a multiple of eps with error less in absolute value than .75 * eps. v = asin(x) is the number in [-pi/2, pi/2] for which sin(v) = x. EXAMPLE ; print asin(.5, 1e-5), asin(.5, 1e-10), asin(.5, 1e-15), asin(.5, 1e-20) .5236 .5235987756 .523598775598299 .52359877559829887308 LIMITS none LINK LIBRARY NUMBER *qasin(NUMBER *q, NUMBER *epsilon) SEE ALSO acos, atan, 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: asin,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asin,v $ ## ## Under source code control: 1994/03/19 01:40:24 ## 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 pop - pop a value from front of a list SYNOPSIS pop(lst) TYPES lst list, &list return any DESCRIPTION This function removes index 0 and returns it. This function is equivalent to calling delete(lst, 0). EXAMPLE ; lst = list(2,"three") list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" ; pop(lst) 2 ; print lst list (1 elements, 1 nonzero): [[0]] = "three" ; pop(lst) "three" ; print lst list (0 elements, 0 nonzero) ; pop(lst) ; print lst list (0 elements, 0 nonzero) LIMITS none LINK LIBRARY none SEE ALSO append, delete, insert, islist, push, remove, 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: pop,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pop,v $ ## ## Under source code control: 1994/03/19 03:13:20 ## 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 access - determine existence or accessibility of named file SYNOPSIS access(name [, mode]) TYPES name string mode integer or string containing only 'r', 'w', 'x' characters return null value or error DESCRIPTION access(name) or access(name, 0) or access(name, "") returns the null value if a file with this name exists. If non-null mode is specified, the null value is returned if there is a file with the specified name and accessibility indicated by the bits or characters of the mode argument: 'r' or bit 2 for reading, 'w' or bit 1 for writing, 'x' or bit 0 for execution. EXAMPLE The system error-numbers and messages may differ for different implementations ; !rm -f junk ; access("junk") System error 2 ; strerror(.) "No such file or directory" ; f = fopen("junk", "w") ; access("junk") ; fputs(f, "Alpha") ; fclose(f) ; !chmod u-w junk ; access("junk", "w") System error 13 ; strerror(.) "Permission denied" LIMITS There may be implementation-dependent limits inherited from the system call "access" used by this function. LINK LIBRARY none SEE ALSO fopen, fclose, isfile, files ## 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: access,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/access,v $ ## ## Under source code control: 1996/04/30 03:36:20 ## 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 estr - represent some types of value by text strings SYNOPSIS estr(x) TYPES x null, string, real or complex number, list, matrix, object. block, named block, error return string DESCRIPTION This function attempts to represent x exactly by a string s of ordinary text characters such that eval(s) == x. If x is null, estr(x) returns the string "". If x is a string, estr(x) returns the string in which occurrences of newline, tab, ", \, etc. have been converted to \n, \t, \", \\, etc., '\0' to \000 or \0 according as the next character is or is not an octal digit, and other non-text characters to their escaped hex representation, e.g. char(165) becomes \xa5. For real x, estr(x) represebts x in fractional mode. EXAMPLE ; estr("abc\0xyz\00023\n\xa5\r\n") ""abc\0xyz\00023\n\xa5\r\n"" ; estr(1.67) "167/100" ; estr(mat[3] = {2, list(3,5), "abc"}) "mat[3]={2,list(3,5),"abc"" LIMITS none LINK LIBRARY none SEE ALSO str, strprintf ## Copyright (C) 2006 Ernest Bowen ## ## 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: estr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/estr,v $ ## ## Under source code control: 2006/08/20 14:45:13 ## File existed as early as: 2006 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Builtin functions There is a large number of built-in functions. Many of the functions work on several types of arguments, whereas some only work for the correct types (e.g., numbers or strings). In the following description, this is indicated by whether or not the description refers to values or numbers. This display is generated by the 'show builtin' command. ## 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: builtin.top,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/builtin.top,v $ ## ## Under source code control: 1995/07/10 01:17:53 ## 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 Args Description abs 1-2 absolute value within accuracy b access 1-2 determine accessibility of file a for mode b acos 1-2 arccosine of a within accuracy b acosh 1-2 inverse hyperbolic cosine of a within accuracy b acot 1-2 arccotangent of a within accuracy b acoth 1-2 inverse hyperbolic cotangent of a within accuracy b acsc 1-2 arccosecant of a within accuracy b acsch 1-2 inverse csch of a within accuracy b agd 1-2 inverse gudermannian function append 1+ append values to end of list appr 1-3 approximate a by multiple of b using rounding c arg 1-2 argument (the angle) of complex number argv 0-1 calc argc or argv string asec 1-2 arcsecant of a within accuracy b asech 1-2 inverse hyperbolic secant of a within accuracy b asin 1-2 arcsine of a within accuracy b asinh 1-2 inverse hyperbolic sine of a within accuracy b assoc 0 create new association array atan 1-2 arctangent of a within accuracy b atan2 2-3 angle to point (b,a) within accuracy c atanh 1-2 inverse hyperbolic tangent of a within accuracy b avg 0+ arithmetic mean of values base 0-1 set default output base base2 0-1 set default secondary output base bernoulli 1 Bernoulli number for index a bit 2 whether bit b in value a is set blk 0-3 block with or without name, octet number, chunksize blkcpy 2-5 copy value to/from a block: blkcpy(d,s,len,di,si) blkfree 1 free all storage from a named block blocks 0-1 named block with specified index, or null value bround 1-3 round value a to b number of binary places btrunc 1-2 truncate a to b number of binary places calc_tty 0 set tty for interactivity calclevel 0 current calculation level calcpath 0 current CALCPATH search path value catalan 1 catalan number for index a ceil 1 smallest integer greater than or equal to number cfappr 1-3 approximate a within accuracy b using continued fractions cfsim 1-2 simplify number using continued fractions char 1 character corresponding to integer value cmdbuf 0 command buffer cmp 2 compare values returning -1, 0, or 1 comb 2 combinatorial number a!/b!(a-b)! config 1-2 set or read configuration value conj 1 complex conjugate of value copy 2-5 copy value to/from a block: copy(s,d,len,si,di) cos 1-2 cosine of value a within accuracy b cosh 1-2 hyperbolic cosine of a within accuracy b cot 1-2 cotangent of a within accuracy b coth 1-2 hyperbolic cotangent of a within accuracy b count 2 count listr/matrix elements satisfying some condition cp 2 cross product of two vectors csc 1-2 cosecant of a within accuracy b csch 1-2 hyperbolic cosecant of a within accuracy b ctime 0 date and time as string custom 0+ custom builtin function interface delete 2 delete element from list a at position b den 1 denominator of fraction det 1 determinant of matrix digit 2-3 digit at specified decimal place of number digits 1-2 number of digits in base b representation of a display 0-1 number of decimal digits for displaying numbers dp 2 dot product of two vectors epsilon 0-1 set or read allowed error for real calculations errcount 0-1 set or read error count errmax 0-1 set or read maximum for error count errno 0-1 set or read calc_errno error 0-1 generate error value estr 1 exact text string representation of value euler 1 Euler number eval 1 evaluate expression from string to value exp 1-2 exponential of value a within accuracy b factor 1-3 lowest prime factor < b of a, return c if error fcnt 2 count of times one number divides another fib 1 Fibonacci number F(n) forall 2 do function for all elements of list or matrix frem 2 number with all occurrences of factor removed fact 1 factorial fclose 0+ close file feof 1 whether EOF reached for file ferror 1 whether error occurred for file fflush 0+ flush output to file(s) fgetc 1 read next char from file fgetfield 1 read next white-space delimited field from file fgetfile 1 read to end of file fgetline 1 read next line from file, newline removed fgets 1 read next line from file, newline is kept fgetstr 1 read next null-terminated string from file, null character is kept files 0-1 return opened file or max number of opened files floor 1 greatest integer less than or equal to number fopen 2 open file name a in mode b fpathopen 2-3 open file name a in mode b, search for a along CALCPATH or path c fprintf 2+ print formatted output to opened file fputc 2 write a character to a file fputs 2+ write one or more strings to a file fputstr 2+ write one or more null-terminated strings to a file free 0+ free listed or all global variables freebernoulli 0 free stored Bernoulli numbers freeeuler 0 free stored Euler numbers freeglobals 0 free all global and visible static variables freeredc 0 free redc data cache freestatics 0 free all unscoped static variables freopen 2-3 reopen a file stream to a named file fscan 2+ scan a file for assignments to one or more variables fscanf 2+ formatted scan of a file for assignment to one or more variables fseek 2-3 seek to position b (offset from c) in file a fsize 1 return the size of the file ftell 1 return the file position frac 1 fractional part of value gcd 1+ greatest common divisor gcdrem 2 a divided repeatedly by gcd with b gd 1-2 gudermannian function getenv 1 value of environment variable (or NULL) hash 1+ return non-negative hash value for one or more values head 2 return list of specified number at head of a list highbit 1 high bit number in base 2 representation hmean 0+ harmonic mean of values hnrmod 4 v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1 hypot 2-3 hypotenuse of right triangle within accuracy c ilog 2 integral log of a to integral base b ilog10 1 integral log of a number base 10 ilog2 1 integral log of a number base 2 im 1 imaginary part of complex number indices 2 indices of a specified assoc or mat value inputlevel 0 current input depth insert 2+ insert values c ... into list a at position b int 1 integer part of value inverse 1 multiplicative inverse of value iroot 2 integer b'th root of a isassoc 1 whether a value is an association isatty 1 whether a file is a tty isblk 1 whether a value is a block isconfig 1 whether a value is a config state isdefined 1 whether a string names a function iserror 1 where a value is an error iseven 1 whether a value is an even integer isfile 1 whether a value is a file ishash 1 whether a value is a hash state isident 1 returns 1 if identity matrix isint 1 whether a value is an integer islist 1 whether a value is a list ismat 1 whether a value is a matrix ismult 2 whether a is a multiple of b isnull 1 whether a value is the null value isnum 1 whether a value is a number isobj 1 whether a value is an object isobjtype 1 whether a string names an object type isodd 1 whether a value is an odd integer isoctet 1 whether a value is an octet isprime 1-2 whether a is a small prime, return b if error isptr 1 whether a value is a pointer isqrt 1 integer part of square root isrand 1 whether a value is a additive 55 state israndom 1 whether a value is a Blum state isreal 1 whether a value is a real number isrel 2 whether two numbers are relatively prime isstr 1 whether a value is a string issimple 1 whether value is a simple type issq 1 whether or not number is a square istype 2 whether the type of a is same as the type of b jacobi 2 -1 => a is not quadratic residue mod b 1 => b is composite, or a is quad residue of b join 1+ join one or more lists into one list lcm 1+ least common multiple lcmfact 1 lcm of all integers up till number lfactor 2 lowest prime factor of a in first b primes links 1 links to number or string value list 0+ create list of specified values ln 1-2 natural logarithm of value a within accuracy b log 1-2 base 10 logarithm of value a within accuracy b lowbit 1 low bit number in base 2 representation ltol 1-2 leg-to-leg of unit right triangle (sqrt(1 - a^2)) makelist 1 create a list with a null elements matdim 1 number of dimensions of matrix matfill 2-3 fill matrix with value b (value c on diagonal) matmax 2 maximum index of matrix a dim b matmin 2 minimum index of matrix a dim b matsum 1 sum the numeric values in a matrix mattrace 1 return the trace of a square matrix mattrans 1 transpose of matrix max 0+ maximum value memsize 1 number of octets used by the value, including overhead meq 3 whether a and b are equal modulo c min 0+ minimum value minv 2 inverse of a modulo b mmin 2 a mod b value with smallest abs value mne 3 whether a and b are not equal modulo c mod 2-3 residue of a modulo b, rounding type c modify 2 modify elements of a list or matrix name 1 name assigned to block or file near 2-3 sign of (abs(a-b) - c) newerror 0-1 create new error type with message a nextcand 1-5 smallest value == d mod e > a, ptest(a,b,c) true nextprime 1-2 return next small prime, return b if err norm 1 norm of a value (square of absolute value) null 0+ null value num 1 numerator of fraction ord 1 integer corresponding to character value param 1 value of parameter n (or parameter count if n is zero) perm 2 permutation number a!/(a-b)! prevcand 1-5 largest value == d mod e < a, ptest(a,b,c) true prevprime 1-2 return previous small prime, return b if err pfact 1 product of primes up till number pi 0-1 value of pi accurate to wiºÈ»È¼È½È¾È¿ÈÀÈÁÈÂÈÃÈÄÈÅÈÆÈÇÈÈÈthin epsilon pix 1-2 number of primes <= a < 2^32, return b if error places 1-2 places after "decimal" point (-1 if infinite) pmod 3 mod of a power (a ^ b (mod c)) polar 2-3 complex value of polar coordinate (a * exp(b*1i)) poly 1+ evaluates a polynomial given its coefficients or coefficient-list pop 1 pop value from front of list popcnt 1-2 number of bits in a that match b (or 1) power 2-3 value a raised to the power b within accuracy c protect 1-3 read or set protection level for variable ptest 1-3 probabilistic primality test printf 1+ print formatted output to stdout prompt 1 prompt for input line using value a push 1+ push values onto front of list putenv 1-2 define an environment variable quo 2-3 integer quotient of a by b, rounding type c quomod 4-5 set c and d to quotient and remainder of a divided by b rand 0-2 additive 55 random number [0,2^64), [0,a), or [a,b) randbit 0-1 additive 55 random number [0,2^a) random 0-2 Blum-Blum-Shub random number [0,2^64), [0,a), or [a,b) randombit 0-1 Blum-Blum-Sub random number [0,2^a) randperm 1 random permutation of a list or matrix rcin 2 convert normal number a to REDC number mod b rcmul 3 multiply REDC numbers a and b mod c rcout 2 convert REDC number a mod b to normal number rcpow 3 raise REDC number a to power b mod c rcsq 2 square REDC number a mod b re 1 real part of complex number remove 1 remove value from end of list reverse 1 reverse a copy of a matrix or list rewind 0+ rewind file(s) rm 1+ remove file(s), -f turns off no-such-file errors root 2-3 value a taken to the b'th root within accuracy c round 1-3 round value a to b number of decimal places rsearch 2-4 reverse search matrix or list for value b starting at index c runtime 0 user and kernel mode cpu time in seconds saveval 1 set flag for saving values scale 2 scale value up or down by a power of two scan 1+ scan standard input for assignment to one or more variables scanf 2+ formatted scan of standard input for assignment to variables search 2-4 search matrix or list for value b starting at index c sec 1-2 sec of a within accuracy b sech 1-2 hyperbolic secant of a within accuracy b seed 0 return a 64 bit seed for a psuedo-random generator segment 2-3 specified segment of specified list select 2 form sublist of selected elements from list setbit 2-3 set specified bit in string sgn 1 sign of value (-1, 0, 1) sha1 0+ Secure Hash Algorithm (SHS-1 FIPS Pub 180-1) sin 1-2 sine of value a within accuracy b sinh 1-2 hyperbolic sine of a within accuracy b size 1 total number of elements in value sizeof 1 number of octets used to hold the value sleep 0-1 suspend operation for a seconds sort 1 sort a copy of a matrix or list sqrt 1-3 square root of value a within accuracy b srand 0-1 seed the rand() function srandom 0-4 seed the random() function ssq 1+ sum of squares of values stoponerror 0-1 assign value to stoponerror flag str 1 simple value converted to string strcat 1+ concatenate strings together strcmp 2 compare two strings strcpy 2 copy string to string strerror 0-1 string describing error type strlen 1 length of string strncmp 3 compare strings a, b to c characters strncpy 3 copy up to c characters from string to string strpos 2 index of first occurrence of b in a strprintf 1+ return formatted output as a string strscan 2+ scan a string for assignments to one or more variables strscanf 2+ formatted scan of string for assignments to variables substr 3 substring of a from position b for c chars sum 0+ sum of list or object sums and/or other terms swap 2 swap values of variables a and b (can be dangerous) system 1 call Unix command systime 0 kernel mode cpu time in seconds tail 2 retain list of specified number at tail of list tan 1-2 tangent of a within accuracy b tanh 1-2 hyperbolic tangent of a within accuracy b test 1 test that value is nonzero time 0 number of seconds since 00:00:00 1 Jan 1970 UTC trunc 1-2 truncate a to b number of decimal places ungetc 2 unget char read from file usertime 0 user mode cpu time in seconds version 0 calc version string xor 1+ logical xor The config function sets or reads the value of a configuration parameter. The first argument is a string which names the parameter to be set or read. If only one argument is given, then the current value of the named parameter is returned. If two arguments are given, then the named parameter is set to the value of the second argument, and the old value of the parameter is returned. Therefore you can change a parameter and restore its old value later. The possible parameters are explained in the next section. The scale function multiplies or divides a number by a power of 2. This is used for fractional calculations, unlike the << and >> operators, which are only defined for integers. For example, scale(6, -3) is 3/4. The quomod function is used to obtain both the quotient and remainder of a division in one operation. The first two arguments a and b are the numbers to be divided. The last two arguments c and d are two variables which will be assigned the quotient and remainder. For nonnegative arguments, the results are equivalent to computing a//b and a%b. If a is negative and the remainder is nonzero, then the quotient will be one less than a//b. This makes the following three properties always hold: The quotient c is always an integer. The remainder d is always 0 <= d < b. The equation a = b * c + d always holds. This function re