urred, the memory allocated in B = blk(len, chunk) is freed when B is assigned another value. With a string str as its first argument, blk(str [, len, chunk]) when called for the first time creates a block with str as its name. Here there no restriction on the characters used in str; thus the string may include white space or characters normally used for punctuation or operators. Any subsequent call to blk(str, ...) with the same str will refer to the same named block. A named block is assigned length and chunksize and consequent maximum size in the same way as unnamed blocks. A major difference is that in assignments, a named block is not copied. Thus, if a block A has been created by: A = blk("foo") any subsequent: B = A or: B = blk("foo") will give a second variable B referring to the same block as A. Either A[i] = x or B[i] = x may then be used to assign a value to an octet in the block. Its length or chunksize may be changed by instructions like: blk(A, len, chunk); A = blk(A, len, chunk); null(blk(A, len, chunk)). These have the same effect on A; when working interactively, the last two avoid printing of the new value for A. Named blocks are assigned index numbers 0, 1, 2, ..., in the order of their creation. The block with index id is returned by blocks(id). With no argument, blocks() returns the number of current unfreed named blocks. The memory allocated to a named block is freed by the blkfree() function with argument the named block, its name, or its id number. The block remains in existence but with a null data pointer, its length and size being reduced to zero. A new block of memory may be allocated to it, with possibly new length and chunksize by: blk(val [, len, chunk]) where val is either the named block or its name. The printing output for a named block is in three lines, the first line displaying its id number and name, the other two as for an unnamed block, except that "NULL" is printed if the memory has been freed. The identifying numbers and names of the current named blocks are displayed by: show blocks If A and B are named blocks, A == B will be true only if they refer to the same block of memory. Thus, blocks with the same data and datalen will be considered unequal if they have different names. If A is a named block, str(A) returns the name of the block. Values may be assigned to the early octets of a named or unnamed block by use of = { } initialization as for matrices. EXAMPLE ; B = blk(15,10) ; B[7] = 0xff ; B chunksize = 10, maxsize = 20, datalen = 15 00000000000000ff00000000000000 ; B[18] = 127 ; B chunksize = 10, maxsize = 20, datalen = 18 00000000000000ff0000000000000000007f ; B[20] = 2 Index out of bounds for block ; print size(B), sizeof(B) 18 20 ; B = blk(B, 100, 20) ; B chunksize = 20, maxsize = 120, datalen = 100 00000000000000ff0000000000000000007f000000000000000000000000... ; C = blk(B, 10} = {1,2,3} ; C chunksize = 20, maxsize = 20, datalen = 10 01020300000000ff0000 ; A1 = blk("alpha") ; A1 block 0: alpha chunksize = 256, maxsize = 256, datalen = 0 ; A1[7] = 0xff ; A2 = A1 ; A2[17] = 127 ; A1 block 0: alpha chunksize = 256, maxsize = 256, datalen = 18 00000000000000ff0000000000000000007f ; A1 = blk(A1, 1000) ; A1 block 0: alpha chunksize = 256, maxsize = 1024, datalen = 1000 00000000000000ff0000000000000000007f000000000000000000000000... ; A1 = blk(A1, , 16) ; A1 block 0: alpha chunksize = 16, maxsize = 1008, datalen = 1000 00000000000000ff0000000000000000007f000000000000000000000000... LIMITS 0 <= len < 2^31 1 <= chunk < 2^31 LINK LIBRARY BLOCK *blkalloc(int len, int chunk) void blk_free(BLOCK *blk) BLOCK *blkrealloc(BLOCK *blk, int newlen, int newchunk) void blktrunc(BLOCK *blk) BLOCK *blk_copy(BLOCK *blk) int blk_cmp(BLOCK *a, BLOCK *b) void blk_print(BLOCK *blk) void nblock_print(NBLOCK *nblk) NBLOCK *reallocnblock(int id, int len, int chunk) NBLOCK *createnblock(char *name, int len, int chunk) int findnblockid(char * name) int removenblock(int id) int countnblocks(void) void shownblocks(void) NBLOCK *findnblock(int id) BLOCK *copyrealloc(BLOCK *blk, int newlen, int newchunk) SEE ALSO blocks, blkfree ## 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: blk,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blk,v $ ## ## Under source code control: 1997/04/05 13:07:13 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ For more information while running calc, type help followed by one of the following topics: topic description ----- ----------- intro introduction to calc overview overview of calc help this file assoc using associations builtin builtin functions command top level commands config configuration parameters custom information about the custom builtin interface define how to define functions environment how environment variables effect calc errorcodes calc generated error codes expression expression sequences file using files history command history interrupt how interrupts are handled list using lists mat using matrices obj user defined data types operator math, relational, logic and variable access operators statement flow control and declaration statements types builtin data types unexpected unexpected syntax/usage surprises for C programmers usage how to invoke the calc command variable variables and variable declarations bindings input & history character bindings custom_cal information about custom calc resource files libcalc using the arbitrary precision routines in a C program new_custom information about how to add new custom functions resource standard calc resource files script using calc shell scripts cscript info on the calc shell scripts supplied with calc archive where to get the latest versions of calc bugs known bugs and mis-features changes recent changes to calc contrib how to contribute scripts, code or custom functions todo list of priority action items for calc wishlist wish list of future enhancements of calc credit who wrote calc and who helped copyright calc copyright and the GNU LGPL copying details on the Calc GNU Lesser General Public License copying-lgpl calc GNU Lesser General Public License text full all of the above (in the above order) For example: help usage will print the calc command usage information. One can obtain calc help without invoking any startup code by running calc as follows: calc -q help topic where 'topic' is one of the topics listed above. You can also ask for help on a particular builtin function name. For example: help asinh help round See: help builtin for a list of builtin functions. Some calc operators have their own help pages: help = help -> help * help . help % help // help # If the -m mode disallows opening files for reading or execution of programs, then the help facility will be disabled. See: help usage for details of the -m mode. The help command is able to display installed help files for custom builtin functions. However, if the custom name is the same as a standard help file, the standard help file will be displayed instead. The custom help builtin should be used to directly access the custom help file. For example, the custom help builtin has the same name as the standard help file. That is: help help will print this file only. However the custom help builtin will print only the custom builtin help file: custom("help", "help"); will by-pass a standard help file and look for the custom version directly. As a hack, the following: help custhelp/anything as the same effect as: custom("help", "anything"); ## Copyright (C) 1999-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: help,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/help,v $ ## ## Under source code control: 1991/07/21 04:37:20 ## 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 random - Blum-Blum-Shub pseudo-random number generator SYNOPSIS random([[min, ] beyond]) TYPES min integer beyond integer return integer DESCRIPTION Generate a pseudo-random number using a Blum-Blum-Shub generator. We return a pseudo-random number over the half closed interval: [min,beyond) ((min <= return < beyond)) By default, min is 0 and beyond is 2^64. While the Blum-Blum-Shub generator is not painfully slow, it is not a fast generator. For a faster, but lesser quality generator (non-cryptographically strong) see the additive 55 generator (see the rand help page). Other arg forms: random() Same as random(0, 2^64) random(beyond) Same as random(0, beyond) The random generator generates the highest order bit first. Thus: random(256) will produce the save value as: (random(8) << 5) + random(32) when seeded with the same seed. The basic idea behind the Blum-Blum-Shub generator is to use the low bit bits of quadratic residues modulo a product of two 3 mod 4 primes. The lowest int(log2(log2(p*q))) bits are used where log2() is log base 2 and p,q are two primes 3 mod 4. The Blum-Blum-Shub generator is described in the papers: Blum, Blum, and Shub, "Comparison of Two Pseudorandom Number Generators", in Chaum, D. et. al., "Advances in Cryptology: Proceedings Crypto 82", pp. 61-79, Plenum Press, 1983. Blum, Blum, and Shub, "A Simple Unpredictable Pseudo-Random Number Generator", SIAM Journal of Computing, v. 15, n. 2, 1986, pp. 364-383. U. V. Vazirani and V. V. Vazirani, "Trapdoor Pseudo-Random Number Generators with Applications to Protocol Design", Proceedings of the 24th IEEE Symposium on the Foundations of Computer Science, 1983, pp. 23-30. U. V. Vazirani and V. V. Vazirani, "Efficient and Secure Pseudo-Random Number Generation", Proceedings of the 24th IEEE Symposium on the Foundations of Computer Science, 1984, pp. 458-463. U. V. Vazirani and V. V. Vazirani, "Efficient and Secure Pseudo-Random Number Generation", Advances in Cryptology - Proceedings of CRYPTO '84, Berlin: Springer-Verlag, 1985, pp. 193-202. Sciences 28, pp. 270-299. Bruce Schneier, "Applied Cryptography", John Wiley & Sons, 1st edition (1994), pp 365-366. This generator is considered 'strong' in that it passes all polynomial-time statistical tests. The sequences produced are random in an absolutely precise way. There is absolutely no better way to predict the sequence than by tossing a coin (as with TRULY random numbers) EVEN IF YOU KNOW THE MODULUS! Furthermore, having a large chunk of output from the sequence does not help. The BITS THAT FOLLOW OR PRECEDE A SEQUENCE ARE UNPREDICTABLE! Of course the Blum modulus should have a long period. The default Blum modulus as well as the compiled in Blum moduli have very long periods. When using your own Blum modulus, a little care is needed to avoid generators with very short periods. See the srandom() help page for information for more details. To compromise the generator, an adversary must either factor the modulus or perform an exhaustive search just to determine the next (or previous) bit. If we make the modulus hard to factor (such as the product of two large well chosen primes) breaking the sequence could be intractable for todays computers and methods. The Blum generator is the best generator in this package. It produces a cryptographically strong pseudo-random bit sequence. Internally, a fixed number of bits are generated after each generator iteration. Any unused bits are saved for the next call to the generator. The Blum generator is not too slow, though seeding the generator via srandom(seed,plen,qlen) can be slow. Shortcuts and pre-defined generators have been provided for this reason. Use of Blum should be more than acceptable for many applications. The goals of this package are: all magic numbers are explained I distrust systems with constants (magic numbers) and tables that have no justification (e.g., DES). I believe that I have done my best to justify all of the magic numbers used. full documentation You have this source file, plus background publications, what more could you ask? large selection of seeds Seeds are not limited to a small number of bits. A seed may be of any size. the strength of the generators may be tuned to meet the need By using the appropriate seed and other arguments, one may increase the strength of the generator to suit the need of the application. One does not have just a few levels. For a detailed discussion on seeds, see the srandom help page. It should be noted that the factors of the default Blum modulus is given in the source. While this does not reduce the quality of the generator, knowing the factors of the Blum modulus would help someone determine the next or previous bit when they did not know the seed. If this bothers you, feel free to use one of the other compiled in Blum moduli or provide your own. See the srandom help page for details. EXAMPLE ; print srandom(0), random(), random(), random() RANDOM state 9203168135432720454 13391974640168007611 13954330032848846793 ; print random(123), random(123), random(123), random(123), random(123) 22 83 66 88 67 ; print random(2,12), random(2^50,3^50), random(0,2), random(-400000,120000) 10 483381144668580304003305 0 -70235 LIMITS min < beyond LINK LIBRARY void zrandom(long cnt, ZVALUE *res) void zrandomrange(ZVALUE low, ZVALUE beyond, ZVALUE *res) long irandom(long beyond) SEE ALSO seed, srand, randbit, isrand, rand, srandom, israndom ## Copyright (C) 1999-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.3 $ ## @(#) $Id: random,v 30.3 2007/09/21 02:16:29 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/random,v $ ## ## Under source code control: 1997/02/17 01:18:22 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME issimple - whether a value is a simple type SYNOPSIS issimple(x) TYPES x any, &any return int DESCRIPTION Determine if x is a simple type. This function will return 1 if x is a simple type, 0 otherwise. Simple types are real numbers, complex numbers, strings and null values. EXAMPLE ; print issimple(2.0), issimple(1), issimple("0") 1 1 1 ; print issimple(2i), issimple(1e20), issimple(1/3), issimple(null()) 1 1 1 1 ; mat a[2] ; b = list(1,2,3) ; c = assoc() ; obj chongo {was, here} d; ; print issimple(a), issimple(b), issimple(c), issimple(d) 0 0 0 0 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, 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: issimple,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/issimple,v $ ## ## Under source code control: 1994/10/21 02:21:30 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME pi - evaluate pi to specified accuracy SYNOPSIS pi([eps]) TYPES eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns a multiple of eps differing from the true value of pi by less than 0.75 eps, and in nearly all cases by less than 0.5 eps. EXAMPLE ; print pi(1e-5), pi(1e-10), pi(1e-15), pi(1e-20) 3.14159 3.1415926536 3.141592653589793 3.14159265358979323846 LIMITS eps > 0 LINK LIBRARY NUMBER *qpi(NUMBER *eps) SEE ALSO atan2 ## 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: pi,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pi,v $ ## ## Under source code control: 1995/10/25 04:03:46 ## 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 freopen - close (if necessary) and reopen a filestream SYNOPSIS freopen(fs, mode [,filename]) TYPES fs open or closed file stream mode one of the strings "r", "w", "a", "r+", "w+, "a+" filename string return null or error value DESCRIPTION With two arguments, this function closes the file stream fs and attempts to reopen it with the specified mode. A non-null value is returned only if the attempt fails. With three arguments, fs, if open, is closed, and an attempt is made to open the file with the specified name and assign it to the stream fs. A non-null value is returned only if the attempt fails. EXAMPLE ; f = fopen("/tmp/junk", "w") ; fputs(f, "Leonard Euler") ; freopen(f, "r") ; fgets(f) "Leonard Euler" ; !chmod u-w /tmp/junk ; freopen(f, "w") Error 10013 LIMITS none LINK LIBRARY none SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt ## Copyright (C) 1999-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: freopen,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freopen,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 strcmp - compare two strings in the customary ordering of strings SYNOPSIS strcmp(s1, s2) TYPES s1 string s2 string return integer (1, 0 or -1) DESCRIPTION Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2). This function compares up to m values of consecutive characters in the strings s1 and s2. If an inequality is encountered, the function returns 1 or -1 according as the greater character is in s1 or s2. If there has been no inequality, the function returns 1, 0, or -1 according as n1 is greater than, equal to, or less than n2. Note that null characters within the strings are included in the comparison. EXAMPLE strcmp("ab", "abc") == -1 strcmp("abc", "abb") == 1 strcmp("abc", "abc") == 0 strcmp("abc", "abd") == -1 strcmp("abc\0", "abc") == 1 strcmp("a\0b", "a\0c") == -1 LIMITS none LINK LIBRARY FLAG stringrel(STRING *s1, STRING *s2) SEE ALSO strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos, strprintf, strscan, strscanf, substr ## 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. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: strcmp,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strcmp,v $ ## ## Under source code control: 2006/03/03 03:32:44 ## File existed as early as: 2006 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME ceil - ceiling SYNOPSIS ceil(x) TYPES x real, complex, list, matrix return real or complex, list, matrix DESCRIPTION For real x, ceil(x) is the least integer not less than x. For complex, ceil(x) returns the real or complex number v for which re(v) = ceil(re(x)), im(v) = ceil(im(x)). For list or matrix x, ceil(x) returns the list or matrix of the same structure as x for which each element t of x has been replaced by ceil(t). EXAMPLE ; print ceil(27), ceil(1.23), ceil(-4.56), ceil(7.8 - 9.1i) 27 2 -4 8-9i LIMITS none LINK LIBRARY none SEE ALSO floor, int ## 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: ceil,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ceil,v $ ## ## Under source code control: 1994/09/30 01:12:01 ## 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 rcmul - REDC multiplication SYNOPSIS rcmul(x, y, m) TYPES x integer y 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 rcmul(x,y,m) returns the value of B^-N * x * y % 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 rcmul() may be said to be that of multiplying modulo m values encoded by rcin() and REDC functions, as in: rcin(x * y, m) = rcmul(rcin(x,m), rcin(y,m), m), or with only one factor encoded: x * y % m = rcmul(rcin(x,m), y, m). RUNTIME If the value of m in rcmul(x,y,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 rcmul(x,y,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 x and y have both been reduced modulo m, the runtime required for rcmul(x,y,m) is at most about f times the runtime required for an N-word by N-word multiplication, where f increases from about 1.3 for N = 1 to near 3 for N > 90. More runtime may be required if x and y have to be reduced modulo m. EXAMPLE Using a 64-bit machine with B = 2^32: ; print rcin(4 * 5, 9), rcmul(rcin(4,9), rcin(5,9), 9), rcout(8, 9); 8 8 2 LIMITS none LINK LIBRARY void zredcmul(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res) SEE ALSO rcin, rcout, rcsq, 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: rcmul,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcmul,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 highbit - index of highest bit in binary representation of integer SYNOPSIS highbit(x) TYPES x nonzero integer return integer DESCRIPTION If x is a nonzero integer, highbit(x) returns the index of the highest bit in the binary representation of abs(x). Equivalently, highbit(x) = n if 2^n <= abs(x) < 2^(n + 1); the binary representation of x then has n + 1 digits. EXAMPLE ; print highbit(2), highbit(3), highbit(4), highbit(-15), highbit(2^27) 1 1 2 3 27 LIMITS none LINK LIBRARY LEN zhighbit(ZVALUE x); SEE ALSO lowbit, 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: highbit,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/highbit,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 isstr - whether a value is a string SYNOPSIS isstr(x) TYPES x any, &any return int DESCRIPTION Determine if x is a string. This function will return 1 if x is a string, 0 otherwise. EXAMPLE ; print isstr("1"), isstr(1), isstr("") 1 0 1 LIMITS none LINK LIBRARY none SEE ALSO isassoc, 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, 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: isstr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isstr,v $ ## ## Under source code control: 1994/10/21 02:21:31 ## 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 frem - remove specified integer factors from specified integer SYNOPSIS frem(x,y) TYPES x integer y integer return non-negative integer DESCRIPTION If x and y are not zero and n is the largest non-negative integer for which y^n is a divisor of x, frem(x,y) returns abs(x/y^n). In particular, abs(x) is returned if x is not divisible by y or if abs(y) = 1. If abs(y) > 1, frem(x,y) is the greatest divisor of x not divisible by y. For all x, frem(x,0) is defined to equal abs(x). For all y, frem(0,y) is defined to be zero. For all x and y, abs(x) = frem(x,y) * abs(y) ^ fcnt(x,y). EXAMPLE ; print frem(7,4), frem(24,4), frem(48,4), frem(-48,4) 7 6 3 3 LIMITS none LINK LIBRARY NUMBER *qfacrem(NUMBER *x, NUMBER *y); SEE ALSO fcnt, gcdrem ## 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: frem,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/frem,v $ ## ## Under source code control: 1995/12/18 12:03:02 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME saveval - enable or disable saving of values SYNOPSIS saveval(arg) TYPES arg any return null value DESCRIPTION When evaluation of a line of statements at top level starts, a "saved value" for that line is assigned the null value. When saving is enabled (the initial state) and a statement being evaluated is an expression or a return statement, the value returned by that expression or statement replaces the current saved value; on completion of evaluation of the line, the saved value, if it is not null, updates the "oldvalue". This saving of values is enabled or disabled by calling saveval(arg) with an argument arg that tests as nonzero or zero, Whether saving is enabled or disabled does not affect the operation of eval(str). EXAMPLE ; saveval(1); ; a = 27; . 27 ; saveval(0); ; a = 45 . 27 ; saveval(1); ; a = 63 . 63 LIMITS none LINK LIBRARY none SEE ALSO oldvalue, eval ## 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: saveval,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/saveval,v $ ## ## Under source code control: 1997/09/06 20:03:35 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME fscan - scan a file for possible assignment to variables SYNOPSIS fscan(fs, x_1, x_2, ..., x_n) TYPES fs file stream open for reading x_1, x_2, ... any return integer DESCRIPTION Starting at the current position on fs and while values remain in the x_i arguments, fields of non-whitespace characters are read and evaluated in succession and if the corresponding x_i is an lvalue, the value of the field is assigned to x_i. Scanning ceases when no x_i remain or when the stream reaches end-of-file. The function returns the number of fields evaluated. EXAMPLE ; global a, b, c, d; ; f = fopen("/tmp/junk", "w+"); ; fputs(f, "\t3+4\t\ta-2i d=a^2 'word'") ; rewind(f) ; fscan(f, a, b, , c) 4 ; print a, b, c, d 7 a-2i word 49 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY none SEE ALSO scan, strscan, fscanf, scanf, strscanf, printf, fprintf, strprintf ## 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: fscan,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fscan,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 pmod - integral power of an integer modulo a specified integer SYNOPSIS pmod(x, n, md) TYPES x integer n nonnegative integer md integer return integer DESCRIPTION pmod(x, n, md) returns the integer value of the canonical residue of x^n modulo md, where the set of canonical residues is determined by md and bits 0, 2, and 4 of config("mod") (other bits are ignored). If md is zero, the value is simply x^n. For nonzero md, the canonical residues v modulo md are as follows: config("mod") md > 0 md < 0 0 0 < v < md md < v < 0 1 -md < v < 0 0 < v < -md 4 0 < v < md 0 < v < -md 5 -md < v < 0 md < v < 0 16 -md/2 < v <= md/2 md/2 <= v < -md/2 17 -md/2 <= v < md/2 md/2 < v <= -md/2 20 -md/2 < v <= md/2 md/2 < v <= -md/2 21 -md/2 <= v < md/2 md/2 <= v < -md/2 EXAMPLE ; c = config("mod",0) ; print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pod(2,5,-10) 8 2 -2 -8 ; c = config("mod",16) ; print pmod(2,3,10), pmod(2,5,10), pmod(2,3,-10), pmod(2,5,-10) -2 2 -2 2 LIMITS none LINK LIBRARY NUMBER *qpowermod(NUMBER *x, NUMBER *n, NUMBER *md) SEE ALSO mod, minv ## 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: pmod,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pmod,v $ ## ## Under source code control: 1995/11/09 03:27:51 ## 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 push - push one or more values into the front of a list SYNOPSIS push(x, y_0, y_1, ...) TYPES x lvalue whose value is a list y_0, ... any return null value DESCRIPTION If after evaluation of y_0, y_1, ..., x is a list with contents (x_0, x_1, ...), then after push(x, y_0, y_1, ..., y_n-1), x has contents (y_n-1, ..., y_1, y_0, x_0, x_1, ...), i.e. the values of y_0, y_1, ... are inserted in succession at the beginning of the list. This function is equivalent to insert(x, 0, y_n-1, ..., y_1, y_0). EXAMPLE ; A = list(2,"three") ; print A list (2 elements, 2 nonzero): [[0]] = 2 [[1]] = "three" ; push(A, 4i, 7^2) ; print A list (4 elements, 4 nonzero): [[0]] = 49 [[1]] = 4i [[2]] = 2 [[3]] = "three" ; push (A, pop(A), pop(A)) ; print A list (4 elements, 4 nonzero): [[0]] = 4i [[1]] = 49 [[2]] = 2 [[3]] = "three" LIMITS push() can have at most 100 arguments LINK LIBRARY none SEE ALSO append, delete, insert, islist, pop, 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: push,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/push,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 ctime - current local time SYNOPSIS ctime() TYPES return string DESCRIPTION The ctime() builtin returns the string formed by the first 24 characters returned by the C library function, ctime(): E.g. "Mon Oct 28 00:47:00 1996" The 25th ctime() character, '\n' is removed. EXAMPLE ; printf("The time is now %s.\n", ctime()) The time is now Mon Apr 15 12:41:44 1996. LIMITS none LINK LIBRARY none SEE ALSO runtime, time ## 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: ctime,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ctime,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 ptest - probabilistic test of primality SYNOPSIS ptest(n [,count [,skip]]) TYPES n integer count integer with absolute value less than 2^24, defaults to 1 skip integer, defaults to 1 return 0 or 1 DESCRIPTION In ptest(n, ...) the sign of n is ignored; here we assume n >= 0. ptest(n, count, skip) always returns 1 if n is prime; equivalently, if 0 is returned then n is not prime. If n is even, 1 is returned only if n = 2. If count >= 0 and n < 2^32, ptest(n,...) essentially calls isprime(n) and returns 1 only if n is prime. If count >= 0, n > 2^32, and n is divisible by a prime <= 101, then ptest(n,...) returns 0. If count is zero, and none of the above cases have resulted in 0 being returned, 1 is returned. In other cases (which includes all cases with count < 0), tests are made for abs(count) bases b: if n - 1 = 2^s * m where m is odd, the test for base b of possible primality is passed if b is a multiple of n or b^m = 1 (mod n) or b^(2^j * m) = n - 1 (mod n) for some j where 0 <= j < s; integers that pass the test are called strong probable primes for the base b; composite integers that pass the test are called strong pseudoprimes for the base b; Since the test for base b depends on b % n, and bases 0, 1 and n - 1 are trivial (n is always a strong probable prime for these bases), it is sufficient to consider 1 < b < n - 1. The bases for ptest(n, count, skip) are selected as follows: skip = 0: random in [2, n-2] skip = 1: successive primes 2, 3, 5, ... not exceeding min(n, 65536) otherwise: successive integers skip, skip + 1, ..., skip+abs(count)-1 In particular, if m > 0, ptest(n, -m, 2) == 1 shows that n is either prime or a strong pseudoprime for all positive integer bases <= m + 1. If 1 < b < n - 1, ptest(n, -1, b) == 1 if and only if n is a strong pseudoprime for the base b. For the random case (skip = 0), the probability that any one test with random base b will return 1 if n is composite is always less than 1/4, so with count = k, the probability is less than 1/4^k. For most values of n the probability is much smaller, possible zero. RUNTIME If n is composite, ptest(n, 1, skip) is usually faster than ptest(n, -1, skip), much faster if n is divisible by a small prime. If n is prime, ptest(n, -1, skip) is usually faster than ptest(n, 1, skip), possibly much faster if n < 2^32, only slightly faster if n > 2^32. If n is a large prime (say 50 or more decimal digits), the runtime for ptest(n, count, skip) will usually be roughly K * abs(count) * ln(n)^3 for some constant K. For composite n with highbit(n) = N, the compositeness is detected quickly if n is divisible by a small prime and count >= 0; otherwise, if count is not zero, usually only one test is required to establish compositeness, so the runtime will probably be about K * N^3. For some rare values of composite n, high values of count may be required to establish the compositeness. If the word-count for n is less than conf("redc2"), REDC algorithms are used in evaluating ptest(n, count, skip) when small-factor cases have been eliminated. For small word-counts (say < 10) this may more than double the speed of evaluation compared with the standard algorithms. EXAMPLE ; print ptest(103^3 * 3931, 0), ptest(4294967291,0) 1 1 In the first example, the first argument > 2^32; in the second the first argument is the largest prime less than 2^32. ; print ptest(121,-1,2), ptest(121,-1,3), ptest(121,-2,2) 0 1 0 121 is the smallest strong pseudoprime to the base 3. ; x = 151 * 751 * 28351 ; print x, ptest(x,-4,1), ptest(x,-5,1) 3215031751 1 0 The integer x in this example is the smallest positive integer that is a strong pseudoprime to each of the first four primes 2, 3, 5, 7, but not to base 11. The probability that ptest(x,-1,0) will return 1 is about .23. ; for (i = 0; i < 11; i++) print ptest(91,-1,0),:; print; 0 0 0 1 0 0 0 0 0 0 1 The results for this example depend on the state of the random number generator; the expectation is that 1 will occur twice. ; a = 24444516448431392447461 * 48889032896862784894921; ; print ptest(a,11,1), ptest(a,12,1), ptest(a,20,2), ptest(a,21,2) 1 0 1 0 These results show that a is a strong pseudoprime for all 11 prime bases less than or equal to 31, and for all positive integer bases less than or equal to 21, but not for the bases 37 and 22. The probability that ptest(a,-1,0) (or ptest(a,1,0)) will return 1 is about 0.19. LIMITS none LINK LIBRARY BOOL qprimetest(NUMBER *n, NUMBER *count, NUMBER *skip) BOOL zprimetest(ZVALUE n, long count, long skip) SEE ALSO factor, isprime, lfactor, nextcand, nextprime, prevcand, prevprime, pfact, pix ## 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.2 $ ## @(#) $Id: ptest,v 30.2 2007/09/01 19:53:15 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ptest,v $ ## ## Under source code control: 1996/02/25 00:27:43 ## 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 cos - cosine SYNOPSIS cos(x [,eps]) TYPES x number (real or complex) eps nonzero real, defaults to epsilon() return number DESCRIPTION Calculate the cosine of x to a multiple of eps with error less in absolute value than .75 * eps. EXAMPLE ; print cos(1, 1e-5), cos(1, 1e-10), cos(1, 1e-15), cos(1, 1e-20) .5403 .5403023059 .54030230586814 .5403023058681397174 ; print cos(2 + 3i, 1e-5), cos(2 + 3i, 1e-10) -4.18963-9.10923i -4.189625691-9.1092278938i ; pi = pi(1e-20) ; print cos(pi/3, 1e-10), cos(pi/2, 1e-10), cos(pi, 1e-10) .5 0 -1 LIMITS none LINK LIBRARY NUMBER *qcos(NUMBER *x, NUMBER *eps) COMPLEX *c_cos(COMPLEX *x, NUMBER *eps) SEE ALSO sin, tan, 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: cos,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cos,v $ ## ## Under source code control: 1994/03/19 01:40: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/