10319 Bad second argument for head 10320 Failure for strhead 10321 Bad first argument for tail 10322 Bad second argument for tail 10323 Failure for strtail 10324 Failure for strshift 10325 Non-string argument for strcmp 10326 Bad argument type for strncmp 10327 Varying types of argument for xor 10328 Bad argument type for xor 10329 Bad argument type for strcpy 10330 Bad argument type for strncpy 10331 Bad argument type for unary backslash 10332 Bad argument type for setminus 10333 Bad first argument type for indices 10334 Bad second argument for indices 10335 Too-large re(argument) for exp 10336 Too-large re(argument) for sinh 10337 Too-large re(argument) for cosh 10338 Too-large im(argument) for sin 10339 Too-large im(argument) for cos 10340 Infinite or too-large result for gd 10341 Infinite or too-large result for agd 10342 Too-large value for power 10343 Too-large value for root 10344 Non-real first arg for digit 10345 Non-integral second arg for digit 10346 Bad third arg for digit 10347 Bad first argument for places 10348 Bad second argument for places 10349 Bad first argument for digits 10350 Bad second argument for digits 10351 Bad first argument for ilog 10352 Bad second argument for ilog 10353 Bad argument for ilog10 10354 Bad argument for ilog2 10355 Non-integer second arg for comb 10356 Too-large second arg for comb 10357 Bad argument for catalan 10358 Bad argument for bern 10359 Bad argument for euler 10360 Bad argument for sleep 10361 calc_tty failure 10362 No-copy-to destination for octet assign 10363 No-copy-from source for octet assign 10364 No-change destination for octet assign 10365 Non-variable destination for assign 10366 No-assign-to destination for assign 10367 No-assign-from source for assign 10368 No-change destination for assign 10369 No-type-change destination for assign 10370 No-error-value destination for assign 10371 No-copy argument for octet swap 10372 No-assign-to-or-from argument for swap 10373 Non-lvalue argument for swap 10374 Non-lvalue argument 3 or 4 for quomod 10375 Non-real-number arg 1 or 2 or bad arg 5 for quomod 10376 No-assign-to argument 3 or 4 for quomod 10377 No-copy-to or no-change argument for octet preinc 10378 Non-variable argument for preinc 10379 No-assign-to or no-change argument for preinc 10380 No-copy-to or no-change argument for octet predec 10381 Non-variable argument for predec 10382 No-assign-to or no-change argument for predec 10383 No-copy-to or no-change argument for octet postinc 10384 Non-variable argument for postinc 10385 No-assign-to or no-change argument for postinc 10386 No-copy-to or no-change argument for octet postdec 10387 Non-variable argument for postdec 10388 No-assign-to or no-change argument for postdec 10389 Error-type structure for initialization 10390 No-copy-to structure for initialization 10391 Too many initializer values 10392 Attempt to initialize freed named block 10393 Bad structure type for initialization 10394 No-assign-to element for initialization 10395 No-change element for initialization 10396 No-type-change element for initialization 10397 No-error-value element for initialization 10398 No-assign-or-copy-from source for initialization 10399 No-relocate for list insert 10400 No-relocate for list delete 10401 No-relocate for list push 10402 No-relocate for list append 10403 No-relocate for list pop 10404 No-relocate for list remove 10405 Non-variable first argument for modify 10406 Non-string second argument for modify 10407 No-change first argument for modify 10408 Undefined function for modify 10409 Unacceptable type first argument for modify 10410 Non-string arguments for fpathopen 10411 Unrecognized mode for fpathopen 10412 Bad epsilon argument for log 10413 Non-numeric first argument for log 10414 Non-file argument for fgetfile 10415 File argument for fgetfile not open for reading 10416 Unable to set file position in fgetfile 10417 Non-representable type for estr 20000 base of user defined errors NAME conj - complex conjugate SYNOPSIS conj(x) TYPES If x is an object of type xx, conj(x) calls xx_conj(x). For non-object x: x real, complex, or matrix return real, complex, or matrix DESCRIPTION For real x, conj(x) returns x. For complex x, conj(x) returns re(x) - im(x) * 1i. For matrix x, conj(x) returns a matrix of the same structure as x in which each element t of x has been replaced by conj(t). For xx objects, xx_conj(a) may return any type of value, but for the properties usually expected of conjugates, xx_conj(a) would return an xx object in which each number component is the conjugate of the corresponding component of a. EXAMPLE ; print conj(3), conj(3 + 4i) 3 3-4i LIMITS none LINK LIBRARY void conjvalue(VALUE *x, *res) SEE ALSO norm, abs, arg ## 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: conj,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/conj,v $ ## ## Under source code control: 1995/10/03 10:40:01 ## 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 isrand - whether a value is an additive 55 state SYNOPSIS isrand(x) TYPES x any, &any return int DESCRIPTION Determine if x is an additive 55 pseudo-random number generator state. This function will return 1 if x is a file, 0 otherwise. EXAMPLE ; a = srand(0) ; print isrand(a), isrand(0); 1 0 LIMITS none LINK LIBRARY none SEE ALSO seed, rand, srand, randbit, isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isrand,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isrand,v $ ## ## Under source code control: 1995/11/11 05:09:41 ## 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 polar - specify a complex number by modulus (radius) and argument (angle) SYNOPSIS polar(r, t [, eps]) TYPES r real t real eps nonzero real, defaults to epsilon() return number (real or complex) DESCRIPTION Returns the real or complex number with real and imaginary parts multiples of epps nearest or next to nearest to r * cos(t) and r * sin(t) respectively. The error for each part will be less than 0.75 * abs(eps), but usually less than 0.5 * abs(eps). EXAMPLE ; print polar(2, 0), polar(1, 2, 1e-5), polar(1, 2, 1e-10) 2 -.41615+.9093i -.4161468365+.9092974268i ; pi = pi(1e-10); eps = 1e-5 ; print polar(2, pi/4, eps), polar(2, pi/2, eps), polar(2, 3*pi/4, eps) 1.41421+1.41421i 2i -1.414215+1.41421i LIMITS none LINK LIBRARY COMPLEX *c_polar(NUMBER *r, NUMBER *t, NUMBER *eps); SEE ALSO abs, arg, re, 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: polar,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/polar,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 base2 - set 2nd output base SYNOPSIS base2([mode]) TYPES mode real return real DESCRIPTION By default, calc will output values according to the default base as controlled by the base() builtin function. The base2() builtin function, if given a non-zero argument, enables double base output mode. In double base output mode, calc values are displayed twice, once according to base() and again according to base2(). In double base output mode, the second time a value is displayed, it is displayed within comments: 21701 /* 0x54c5 */ The arguments for base2() are identical to base() with the addition of the 0 value: base2 equivalent config("mode2")'s 2 "binary" base 2 fractions "bin" 8 "octal" base 8 fractions "oct" 10 "real" base 10 floating point "float" "default" -10 "integer" base 10 integers "int" 16 "hexadecimal" base 16 fractions "hex" 1/3 "fraction" base 10 fractions "frac" 1e20 "scientific" base 10 scientific notation "sci" "exp" 0 "off" disable double base output For convenience, any non-integer non-zero value is assumed to mean base 10 fractions and any integer >= 2^64 is assumed to mean base 10 scientific notation. These base2() calls have the same meaning as config("mode2", "fraction"): base2(1/3) base2(0.1415) base2(16/37) These base2() calls have the same meaning as config("mode2", "scientific"): base2(1e20) base2(2^64) base2(2^8191-1) However the base2() function will only return one of the base values listed in the table above. EXAMPLE ; base2() 0 ; base2(8) 0 /* 0 */ ; print 10 10 /* 012 */ ; base2(16), ; 131072 131072 /* 0x20000 */ ; 2345 2345 /* 0x929 */ LIMITS none LINK LIBRARY int math_setmode2(int newmode) NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT, MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY, MODE2_OFF SEE ALSO base, config, str ## Copyright (C) 2002 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: base2,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/base2,v $ ## ## Under source code control: 2002/12/29 00:21:07 ## File existed as early as: 2002 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME digits - return number of "decimal" digits in an integral part SYNOPSIS digits(x [,b]) TYPES x real b integer >= 2, defaults to 10 return integer DESCRIPTION Returns number of digits in the standard base-b representation when x is truncated to an integer and the sign is ignored. To be more precise: when abs(int(x)) > 0, this function returns the value 1 + ilog(x, b). When abs(int(x)) == 0, then this function returns the value 1. If omitted, b is assumed to be 10. If given, b must be an integer > 1. One should remember these special cases: digits(12.3456) == 2 computes with the integer part only digits(-1234) == 4 computes with the absolute value only digits(0) == 1 specical case digits(-0.123) == 1 combination of all of the above EXAMPLE ; print digits(100), digits(23209), digits(2^72) 3 5 22 ; print digits(0), digits(1), digits(-1) 1 1 1 ; print digits(-1234), digits(12.3456), digits(107.207) 4 2 3 ; print digits(17^463-1, 17), digits(10000, 100), digits(21701, 2) 3, 15 14 LIMITS b > 1 LINK LIBRARY long qdigits(NUMBER *q, ZVALUE base) SEE ALSO digit, places ## Copyright (C) 1999-2003 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: digits,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digits,v $ ## ## Under source code control: 1995/10/03 10:40:01 ## 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 matmax - maximum value for specified index of matrix SYNOPSIS matmax(m, i) TYPES m matrix i 0, 1, 2, 3 return integer DESCRIPTION Returns the maximum value for i-th index (i counting from zero) for the matrix m. EXAMPLE ; mat A[3]; mat B[1:3, -4:4, 5] ; print matmax(A,0), matmax(B,0), matmax(B,1), matmax(B,2) 2 3 4 4 LIMITS i < matdim(m) LINK LIBRARY none SEE ALSO mat, ismat, matdim, matmin, mattrans, mattrace, matsum, matfill, det, inverse, isident, test, config, search, rsearch, reverse, copy, blkcpy, dp, cp, randperm, sort ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: matmax,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/matmax,v $ ## ## Under source code control: 1995/10/25 04:03:45 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME acoth - inverse hyperbolic cotangent SYNOPSIS acoth(x [,eps]) TYPES x real, with abs(x) > 1 eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the acoth of x to a multiple of eps with error less in absolute value than .75 * eps. acoth(x) is the real number v for which coth(v) = x. It is given by acoth(x) = ln((x + 1)/(x - 1))/2 EXAMPLE ; print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20) .54931 .5493061443 .549306144334055 .5493061443340548457 LIMITS none LINK LIBRARY NUMBER *qacoth(NUMBER *x, NUMBER *eps) SEE ALSO asinh, acosh, atanh, asech, acsch, 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: acoth,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acoth,v $ ## ## Under source code control: 1995/11/13 03:49:01 ## 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 define - command keyword to start a function definition SYNTAX define fname([param_1 [= default_1], ...]) = [expr] define fname([param_1 [= default_1], ...]) { [statement_1 ... ] } TYPES fname identifier, not a builtin function name param_1, ... identifiers, no two the same default_1, ... expressions expr expression statement_1, ... statements DESCRIPTION The intention of a function definition is that the identifier fname becomes the name of a function which may be called by an expression of the form fname(arg_1, arg_2, ...), where arg_1, arg_2, ... are expressions (including possibly blanks, which are treated as null values). Evaluation of the function begins with evaluation of arg_1, arg_2, ...; then, in increasing order of i, if arg_i is null-valued and "= default_i" has been included in the definition, default_i is evaluated and its value becomes the value of arg_i. The instructions in expr or the listed statements are then executed with each occurrence of param_i replaced by the value obtained for arg_i. In a call, arg_i may be preceded by a backquote (`) to indicate that evaluation of arg_i is not to include a final evaluation of an lvalue. For example, suppose a function f and a global variable A have been defined by: ; define f(x) = (x = 3); ; global mat A[3]; If g() is a function that evaluates to 2: ; f(A[g()]); assigns the value of A[2] to the parameter x and then assigns the value 3 to x: ; f(`A[g()]); has essentially the effect of assigning A[2] as an lvalue to x and then assigning the value 3 to A[2]. (Very old versions of calc achieved the same result by using '&' as in f(&A[g()]).) The number of arguments arg_1, arg_2, ... in a call need not equal the number of parameters. If there are fewer arguments than parameters, the "missing" values are assigned the null value. In the definition of a function, the builtin function param(n) provides a way of referring to the parameters. If n (which may result from evaluating an expreession) is zero, it returns the number of arguments in a call to the function, and if 1 <= n <= param(0), param(n) refers to the parameter with index n. If no error occurs and no quit statement or abort statement is encountered during evaluation of the expression or the statements, the function call returns a value. In the expression form, this is simply the value of the expression. In the statement form, if a return statement is encountered, the "return" keyword is to be either immediately followed by an expression or by a statement terminator (semicolon or rightbrace); in the former case, the expression is evaluated, evaluation of the function ceases, and the value obtained for the expression is returned as the "value of the function"; in the no-expression case, evaluation ceases immediately and the null-value is returned. In the expression form of definition, the end of the expression expr is to be indicated by either a semicolon or a newline not within a part enclosed by parentheses; the definition may extend over several physical lines by ending each line with a '\' character or by enclosing the expression in parentheses. In interactive mode, that a definition has not been completed is indicated by the continuation prompt. A ctrl-C interrupt at this stage will abort the definition. If the expr is omitted from an expression definition, as in: ; define h() = ; any call to the function will evaluate the arguments and return the null value. In the statement form, the definition ends when a matching right brace completes the "block" started by the initial left brace. Newlines within the block are treated as white space; statements within the block end with a ';' or a '}' matching an earlier '{'. If a function with name fname had been defined earlier, the old definition has no effect on the new definition, but if the definition is completed successfully, the new definition replaces the old one; otherwise the old definition is retained. The number of parameters and their names in the new definiton may be quite different from those in the old definition. An attempt at a definition may fail because of scanerrors as the definition is compiled. Common causes of these are: bad syntax, using identifiers as names of variables not yet defined. It is not a fault to have in the definition a call to a function that has not yet been defined; it is sufficient that the function has been defined when a call is made to the function. After fname has been defined, the definition may be removed by the command: ; undefine fname The definitions of all user-defined functions may be removed by: ; undefine * If bit 0 of config("resource_debug") is set and the define command is at interactive level, a message saying that fname has been defined or redefined is displayed. The same message is displayed if bit 1 of config("resource_debug") is set and the define command is read from a file. The identifiers used for the parameters in a function definition do not form part of the completed definition. For example, ; define f(a,b) = a + b; ; define g(alpha, beta) = alpha + beta; result in identical code for the functions f, g. If config("trace") & 8 is nonzero, the opcodes of a newly defined function are displayed on completion of its definition, parameters being specified by names used in the definition. For example: ; config("trace", 8), ; define f(a,b) = a + b 0: PARAMADDR a 2: PARAMADDR b 4: ADD 5: RETURN f(a,b) defined The opcodes may also be displayed later using the show opcodes command; parameters will be specified by indices instead of by names. For example: ; show opco f 0: PARAMADDR 0 2: PARAMADDR 1 4: ADD 5: RETURN When a function is defined by the statement mode, the opcodes normally include DEBUG opcodes which specify statement boundaries at which SIGINT interruptions are likely to be least risky. Inclusion of the DEBUG opcodes is disabled if config("trace") & 2 is nonzero. For details, see help interrupt. While config("trace") & 1 is nonzero, the opcodes are displayed as they are being evaluated. The current function is identified by its name, or "*" in the case of a command-line and "**" in the case of an eval(str) evaluation. When a function is called, argument values may be of any type for which the operations and any functions used within the body of the definition can be executed. For example, whatever the intention at the time they were defined, the functions f1(), f2() defined above may be called with integer, fractional, or complex-number values, or with both arguments strings, or under some compatibility conditions, matrices or objects. EXAMPLE ; define f(a,b) = 2*a + b; ; define g(alpha, beta) ;; { ;; local a, pi2; ;; ;; pi2 = 2 * pi(); ;; a = sin(alpha % pi2); ;; if (a > 0.0) { ;; return a*beta; ;; } ;; if (beta > 0.0) { ;; a *= cos(-beta % pi2); ;; } ;; return a; ;; } LIMITS The number of arguments in a function-call cannot exceed 1024. LIBRARY none SEE ALSO param, variable, undefine, show ## Copyright (C) 2000-2006 David I. Bell, Landon Curt Noll and Ernest Bowen ## ## Calc is open software; you can redistribute it and/or modify it under ## 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: define,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $ ## ## ## Under source code control: 1991/07/21 04:37:18 ## 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 min - minimum, or minimum of defined minima SYNOPSIS min(x_1, x_2, ...) TYPES x_1, x_2, ... any return any DESCRIPTION If an argument x_i is a list with elements e_1, e_2, ..., e_n, it is treated as if x_i were replaced by e_1, e_2, ..., e_n; this may continue recurively if any of the e_j is a list. If an argument x_i is an object of type xx, then x_i is replaced by xx_min(x_i) if the function xx_min() has been defined. If the type xx has been defined by: obj xx = {x, y, z}, an appropriate definition of xx_min(a) is sometimes min(a.x, a.y, a.z). min(a) then returns the minimum of the elements of a. If x_i has the null value, it is ignored. Thus, sum(a, , b, , c) If x_i has the null value, it is ignored. Thus, min(a, , b, , c) will return the same as min(a, b, c). Assuming the above replacements, and that the x_1, x_2, ..., are of sufficently simple ordered types (e.g. real numbers or strings), or, if some are objects, the relevant xx_rel(a,b) has been defined and returns a real-number value for any comparison that has to be made, min(x_1, x_2, ...) returns the value determined by min(x_1) = x_1, and succesively for later arguments, by the use of the equivalent of min(a,b) = (a < b) ? a : b. If the ordering determined by < is total, min(x_1, ...) will be the minimum value among the arguments. For a preorder relation it may be one of several minimal values. For other relations, it may be difficult to predict the result. EXAMPLE ; print min(2), min(5, 3, 7, 2, 9), min(3.2, -0.5, 8.7, -1.2, 2.5) 2 2 -1.2 ; print min(list(3,5), 7, list(6, list(7,8), 2)) 2 ; print min("one", "two", "three", "four") four ; obj point {x, y} ; define point_rel(a,b) = sgn(a.x - b.x) ; obj point A = {1, 5} ; obj point B = {1, 4} ; obj point C = {3, 3} ; print min(A, B, C) obj point {1, 5} ; define point_min(a) = a.x ; print min(A, B, C) 1 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY NUMBER *qmin(NUMBER *x1, NUMBER *x2) SEE ALSO max, obj, sum, ssq ## 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: min,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/min,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 bernoulli - Bernoulli number SYNOPSIS bernoulli(n) TYPES n integer, n < 2^31 if even return rational DESCRIPTION Returns the Bernoulli number with index n, i.e. the coefficient B_n in the expansion t/(exp(t) - 1) = Sum B_n * t^n/n! bernoulli(n) is zero both for n < 0 and for n odd and > 2. When bernoulli(n) is computed for positive even n, the values for n and smaller positive even indices are stored in a table so that a later call to bernoulli(k) with 0 <= k < n will be executed quickly. Considerable runtime and memory are required for calculating bernoulli(n) for large even n. For n = 1000, the numerator has 1779 digits, the denominator 9 digits. The memory used to store calculated bernoulli numbers is freed by freebernoulli(). EXAMPLE ; config("mode", "frac"),; ; for (n = 0; n <= 6; n++) print bernoulli(n),; print; 1 -1/2 1/6 0 -1/30 0 1/42 LIMITS n < 2^31-1 LIBRARY NUMBER *qbernoulli(long n) SEE ALSO euler, catalan, comb, fact, perm ## Copyright (C) 2000 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: bernoulli,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bernoulli,v $ ## ## Under source code control: 2000/07/13 01:33:00 ## File existed as early as: 2000 ## ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME near - compare nearness of two numbers with a standard SYNOPSIS near(x, y [,eps]) TYPES x real y real eps real, defaults to epsilon() return -1, 0 or 1 DESCRIPTION Returns: -1 if abs(x - y) < abs(eps) 0 if abs(x - y) = abs(eps) 1 if abs(x - y) > abs(eps) EXAMPLE ; print near(22/7, 3.15, .01), near(22/7, 3.15, .005) -1 1 LIMITS eps >= 0 LINK LIBRARY FLAG qnear(NUMBER *x, NUMBER *y, NUMBER *eps) SEE ALSO epsilon, abs ## 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: near,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/near,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 sech - hyperbolic secant SYNOPSIS sech(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the sech of x to the nearest or next to nearest multiple of epsilon, with absolute error less than .75 * abs(eps). sech(x) = 2/(exp(x) + exp(-x)) EXAMPLE ; print sech(1, 1e-5), sech(1, 1e-10), sech(1, 1e-15), sech(1, 1e-20) .64805 .6480542737 .648054273663885 .64805427366388539958 LIMITS unlike sin and cos, x must be real eps > 0 LINK LIBRARY NUMBER *qsech(NUMBER *x, NUMBER *eps) SEE ALSO sinh, cosh, tanh, csch, coth, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: sech,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sech,v $ ## ## Under source code control: 1995/11/13 03:49:00 ## 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 getenv - get an environment variable SYNOPSIS getenv(env) TYPES env str return str or nil DESCRIPTION This function returns the value of the environment variable named by the string env. If no such environment variable exists, nil is returned. EXAMPLE ; putenv("name", "value") 0 ; getenv("name") "value" ; putenv("name=val2") 0 ; getenv("name") "val2" ; isnull(getenv("unknown")) 1 LIMITS none LINK LIBRARY none SEE ALSO putenv ## 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: getenv,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/getenv,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 fscanf - formatted scan of a file stream SYNOPSIS fscanf(fs, fmt, x_1, x_2, ...) TYPES fs file stream open for reading fmt string x_1, x_2, ... lvalues return null, nonnegative integer, or error value DESCRIPTION If the current position for fs is EOF, the null value is returned. Otherwise, until the terminating null character of fmt is encountered or end-of-file for fs is reached, characters other than '%' and white space are read from fmt and compared with the corresponding characters read from fs. If the characters match, the reading continues. If they do not match, an integer value is returned and the file position for fs is the position of the non-matching character. If white space is encountered in fmt, any white space characters read from fs are skipped until either end-of-file is reached or a non-white-space character is read and comparisons continue under the control of the next non-white character and following characters in fmt. When a '%' is encountered in fmt, if this is immediately followed by another '%', the pair is considered as if just one '%' were read and if 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 at this stage in the specifier are taken to be decimal digits of an integer which becomes the maximum "width" (i.e. for string-type values, the number of characters to be read from fs); 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 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 current value of the file-position indicator is assigned to the corresponding lvalue. (Any width or skip specification is ignored.) EXAMPLE ; global a, b, c ; f = fopen("/tmp/junk", "w+") ; fputs(f, "Alpha Beta Gamma") ; rewind(f) ; fscanf(f, "Alpha Gamma") ; fgets(f) "Beta Gamma" ; rewind(f) ; fscanf(f, "%5c", a) 1 ; a "Alpha" ; fgets(f) " Beta Gamma" ; rewind(f) ; fscanf(f, "%3c%s%[^m]", a, b, c) 3 ; print a, b Alp ha ; print c Beta Ga ; fgets(f) "mma" LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY extern int fscanfid(FILEID id, char *fmt, int count, VALUE **vals); SEE ALSO scanf, strscanf, printf, fprintf, strprintf, fscan, scan, strscan ## 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: fscanf,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fscanf,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 fgetline - read the next line from a file, newline is tossed SYNOPSIS fgetline(fd) TYPES fd file return str or nil DESCRIPTION This function reads the next line, including any trailing newline from the open file associated with fd. Unlike fgets, the trailing newline is removed from the return string. Empty lines return the null string. When the end of file is reached, fgetline returns the null value. (Note the distinction between a null string and a null value.) If the line contained a numeric value, then the 'eval' function can then be used to convert the string to a numeric value. If a line is read, is returned minus the trailing newline, otherwise (EOF or ERROR) nil is returned. EXAMPLE ; fd = fopen("/tmp/newfile", "w") ; fputs(fd, "chongo was here\n") ; fputs(fd, "123\n") ; fd2 = fopen("/tmp/newfile", "r") ; fgets(fd2) "chongo was here " ; fclose(fd2) ; fd2 = fopen("/tmp/newfile", "r") ; fgetline(fd2) "chongo was here" ; eval(fgetline(fd2)) 123 LIMITS fd must be associated with an open file LINK LIBRARY none SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fgetline,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetline,v $ ## ## Under source code control: 1995/03/04 11:33:19 ## 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 isodd - whether a value is an odd integer SYNOPSIS isodd(x) TYPES x any, &any return int DESCRIPTION Determine if x is an odd integer. This function will return 1 if x is odd integer, 0 otherwise. EXAMPLE ; print isodd(2.0), isodd(1), isodd("1") 0 1 0 ; print isodd(2i), isodd(1e20+1), isodd(1/3) 0 1 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, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isodd,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isodd,v $ ## ## Under source code control: 1994/10/21 02:21: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 cot - trigonometric cotangent SYNOPSIS cot(x [,eps]) TYPES x nonzero real acc nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the cotangent of x to a multiple of eps, with error less in absolute value than .75 * eps. EXAMPLE ; print cot(1, 1e-5), cot(1, 1e-10), cot(1, 1e-15), cot(1, 1e-20) .64209 .6420926159 .642092615934331 .64209261593433070301 LIMITS none LINK LIBRARY NUMBER *qcot(NUMBER *x, NUMBER *eps) SEE ALSO sin, cos, tan, sec, csc, 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: cot,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cot,v $ ## ## Under source code control: 1995/11/13 03:49:00 ## 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 rcout - decode for REDC algorithms SYNOPSIS rcout(x, m) TYPES x integer m odd positive integer return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines) and N the number of words (base-B digits) in the representation of m. Then rcout(x,m) returns the value of B^-N * x % m, where the inverse implicit in B^-N is modulo m and the modulus operator % gives the least non-negative residue. The functions rcin() and rcout() are inverses of each other for all x: rcout(rcin(x,m), m) = rcin(rcout(x,m),m) = x % m. The normal use of rcout() may be said to be that of decoding values encoded by rcin() and REDC functions, as in: x * y % m = rcout(rcmul(rcin(x,m),rcin(y,m),m),m), x^2 % m = rcout(rcsq(rcin(x,m),m),m), x ^ k % m = rcout(rcpow(rcin(x,m),k,m),m). RUNTIME If the value of m in rcout(x,m) is being used for the first time in a REDC function, the information required for the REDC algorithms is calculated and stored for future use, possibly replacing an already stored valued, in a table covering up to 5 (i.e. MAXREDC) values of m. The runtime required for this is about two times that required for multiplying two N-word integers. Two algorithms are available for evaluating rcout(x, m), the one which is usually faster for small N is used when N < config("pow2"); the other is usually faster for larger N. If config("pow2") is set at about 200, and x has been reduced modulo m, the runtime required for rcout(x, m) is at most about f times the runtime required for an N-word by N-word multiplication, where f increases from about 1 for N = 1 to near 2 for N > config("pow2"). More runtime may be required if x has to be reduced modulo m. EXAMPLE Using a 64-bit machine with B = 2^32: ; for (i = 0; i < 9; i++) print rcout(i,9),:; print; 0 7 5 3 1 8 6 4 2 LIMITS none LINK LIBRARY void zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res) SEE ALSO rcout, rcmul, 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: rcout,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rcout,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 gcd - greatest common divisor of a set of rational numbers SYNOPSIS gcd(x1, x2, ...) TYPES x1, x2, ... rational number return rational number DESCRIPTION If at least one xi is nonzero, gcd(x1, x2, ...) is the greatest positive number g for which each xi is a multiple of g. If all xi are zero, the gcd is zero. EXAMPLE ; print gcd(12, -24, 30), gcd(9/10, 11/5, 4/25), gcd(0,0,0,0,0) 6 .02 0 LIMITS The number of arguments may not to exceed 1024. LINK LIBRARY NUMBER *qgcd(NUMBER *x1, NUMBER *x2) SEE ALSO lcm ## 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: gcd,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gcd,v $ ## ## Under source code control: 1995/10/05 04:52:26 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/