(2^50,3^50), rand(0,2), rand(-400000, 120000) 2 658186291252503497642116 1 -324097 LIMITS min < beyond LINK LIBRARY void zrand(long cnt, ZVALUE *res) void zrandrange(ZVALUE low, ZVALUE beyond, ZVALUE *res) long irand(long beyond) SEE ALSO seed, srand, randbit, isrand, random, 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: rand,v 30.3 2007/09/21 02:16:29 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rand,v $ ## ## Under source code control: 1996/01/01 02:16:09 ## 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 test - whether a value is deemed to be true or false SYNOPSIS test(x) TYPES x any return 0 or 1 DESCRIPTION This function returns 1 or 0 according as x tests as "true" or "false". Conditions under which a value x is considered to be false are: Numbers (real or complex): x is zero String: x == "" Matrix: every component of x tests as false List: every element of x tests as false Association: x has no element File: x is not open Null: always Object of type xx: if xx_test has been defined, xx_test(x) returns zero; if xx_test has not been defined, every element of x tests as false. Error-value or other types: never EXAMPLE ; print test(27), test(0), test("abc"), test("") 1 0 1 0 ; print test(mat[3] = {1,,2}), test(mat[2][2]) 1 0 ; A = list(0, 2, 0) ; print test(A), test(pop(A)), test(A), test(pop(A)), test(A) 1 0 1 1 0 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isfile, isident, isnum, isint, islist, ismat, isnull, isobj, isreal, isstr, issimple, istype ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: test,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/test,v $ ## ## Under source code control: 1996/07/11 01:05:13 ## 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 inverse - inverse of value SYNOPSIS inverse(x) TYPES If x is an object of type xx, the function xx_inv has to have been defined; any conditions on x and the nature of the returned value will depend on the definition of xx_inv. For non-object x: x nonzero number (real or complex) or nonsingular matrix return number or matrix DESCRIPTION For real or complex x, inverse(x) returns the value of 1/x. If x is a nonsingular n x n matrix and its elements are numbers or objects for which the required arithmetic operations are defined, inverse(x) returns the matrix m for which m * x = x * m = the unit n x n matrix. The inverse m will have the same index limits as x. EXAMPLE ; print inverse(5/4), inverse(-2/7), inverse(3 + 4i) .8 -3.5 .12-.16i ; mat A[2,2] = {2,3,5,7} ; print inverse(A) mat [2,2] (4 elements, 4 nonzero): [0,0] = -7 [0,1] = 3 [1,0] = 5 [1,1] = -2 LIMITS none LINK LIBRARY void invertvalue(VALUE *x, VALUE *vres) NUMBER *qinv(NUMBER *x) COMPLEX *c_inv(COMPLEX *x) MATRIX *matinv(MATRIX *x) SEE ALSO ## 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: inverse,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/inverse,v $ ## ## Under source code control: 1996/03/12 23:10:01 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME mattrace - trace of a square matrix SYNOPSIS mattrace(m) TYPES m square matrix with summable diagonal elements return determined by addition of elements DESCRIPTION For a two-dimensional square matrix, mattrace(m) returns the sum of the elements on the principal diagonal. In particular, if m has been created by mat m[N,N] where N > 0, mattrace(m) returns m[0,0] + m{1,1] + ... + m[N-1,N-1] EXAMPLE ; mat m[2,2] = {1,2,3,4} ; print mattrace(m), mattrace(m^2) 5 29 LIMITS none LINK LIBRARY none SEE ALSO mat, mattrans ## 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: mattrace,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mattrace,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/ isnullstrncmpaddressjacobi imacosh typecatalan unexpected freeglobals stoponerrorfputstrhmeanarchiveismultrewindintro fcntsystem environment strprintfinsert int inputlevelblocks cscasech polyrandperm agdcalcpathistypeusage mat max feofbroundcfsim freestatics tanhmakelistrsearchprintf sinhisblkmatdimgcdrem factconfigvariablecountisrel sortversion seed rcin sec eval arg tailtscaleNAME isnull - whether a value is a null value SYNOPSIS isnull(x) TYPES x any, &any return int DESCRIPTION Determine if x is a null value. This function will return 1 if x is a null value, 0 otherwise. EXAMPLE ; mat a[2] ; print isnull(a), isnull(1) 1 0 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isnull,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isnull,v $ ## ## Under source code control: 1994/10/21 02:21:28 ## 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 strncmp - compare two strings up to a specified number of characters SYNOPSIS strncmp(s1, s2, n) TYPES s1 string s2 string n nonnegative integer return integer (1, 0 or -1) DESCRIPTION Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2, n). 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 min(n1, n) is greater than, equal to, or less than min(n2, n); in particular, if n1 and n2 are both greater than equal to n, 0 is returned. EXAMPLE strncmp("abc", "xyz", 0) == 0 strncmp("abc", "xyz", 1) == -1 strncmp("abc", "", 1) == 1 strncmp("a", "b", 2) == -1 strncmp("ab", "ac", 2) == -1 strncmp("\0ac", "\0b", 2) == -1 strncmp("ab", "abc", 2) == 0 strncmp("abc", "abd", 2) == 0 LIMITS none LINK LIBRARY This function uses FLAG stringrel(STRING *s1, STRING *s2), temporarily replacing the string sizes by min(n1,n) and min(n2,n). SEE ALSO strcat, strcpy, strerror, strlen, 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: strncmp,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strncmp,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 & - address operator SYNOPSIS &X TYPES X expression specifying an octet, lvalue, string or number return pointer DESCRIPTION &X returns the address at which information for determining the current value of X is stored. After an assignment as in p = &X, the value of X is accessible by *p so long as the connection between p and the value is not broken by relocation of the information or by the value ceasing to exist. Use of an address after the connection is broken is unwise since the calculator may use that address for other purposes; the consequences of attempting to write data to, or otherwise accessing, such a vacated address may be catastrophic. An octet is normally expressed by B[i] where B is a block and 0 <= i < sizeof(B). &B[i] then returns the address at which this octet is located until the block is freed or relocated. Freeing of an unnamed block B occurs when a new value is assigned to B or when B ceases to exist; a named block B is freed by blkfree(B). A block is relocated when an operation like copying to B requires a change of sizeof(B). An lvalue may be expressed by an identifier for a variable, or by such an identifier followed by one or more qualifiers compatible with the type of values associated with the variable and earlier qualifiers. If an identifier A specifies a global or static variable, the address &A is permanently associated with that variable. For a local variable or function parameter A, the association of the variable with &A is limited to each occasion when the function is called. If X specifies a component or element of a matrix or object, connection of &X with that component or element depends only on the continued existence of the matrix or object. For example, after ; mat A[3] the addresses &A[0], &A[1], &A[2] locate the three elements of the matrix specified by A until another value is assigned to A, etc. Note one difference from C in that &A[0] is not the same as A. An element of a list has a fixed address while the list exists and the element is not removed by pop(), remove(), or delete(); the index of the element changes if an element is pushed onto the list, or if earlier elements are popped or deleted. Elements of an association have fixed addresses so long as the association exists. If A[a,b,...] has not been defined for the association A, &A[a,b,...] returns the constant address of a particular null value. Some other special values have fixed addresses; e.g. the old value (.). Some arithmetic operations are defined for addresses but these should be used only for octets or components of a matrix or object where the results refer to octets in the same block or existing components of the same matrix or object. For example, immediately after ; mat A[10] ; p = &A[5] it is permitted to use expressions like p + 4, p - 5, p++ . Strings defined literally have fixed addresses, e.g., after ; p = &"abc" ; A = "abc" the address &*A of the value of A will be equal to p. Except in cases like strcat(A, "") when *A identified with a literal string as above, definitions of string values using strcat() or substr() will copy the relevant strings to newly allocated addresses which will be useable only while the variables retain these defined values. For example, after ; B = C = strcat("a", "bc"); &*B and &*C will be different. If p is defined by p = &*B, p should not be used after a new value is assigned to B, or B ceases to exist, etc. When compilation of a function encounters for the first time a particular literal number or the result of simple arithmetic operations (like +, -, *, or /) on literal numbers, that number is assigned to a particular address which is then used for later similar occurrences of that number so long as the number remains associated with at least one function or lvalue. For example, after ; x = 27; ; y = 3 * 9; ; define f(a) = 27 + a; the three occurrences of 27 have the same address which may be displayed by any of &27, &*x, &*y and &f(0). If x and y are assigned other values and f is redefined or undefined and the 27 has not been stored elsewhere (e.g. as the "old value" or in another function definition or as an element in an association), the address assigned at the first occurrence of 27 will be freed and calc may later use it for another number. When a function returns a number value, that number value is usually placed at a newly allocated address, even if an equal number is stored elsewhere. For example calls to f(a), as defined above, with the same non-zero value for a will be assigned to different addresses as can be seen from printing &*A, &*B, &*C after ; A = f(2); B = f(2); C = f(2); (the case of f(0) is exceptional since 27 + 0 simply copies the 27 rather than creating a new number value). Here it is clearly more efficient to use ; A = B = C = f(2); which, not only performs the addition in f() only once, but stores the number values for A, B and C at the same address. Whether a value V is a pointer and if so, its type, is indicated by the value returned by isptr(V): 1, 2, 3, 4 for octet-, value-, string- and number-pointer respectively, and 0 otherwise. The output when addresses are printed consists of a description (o_ptr, v_ptr, s_ptr, n_ptr) followed by : and the address printed in %p format. Iteration of & is not permitted; &&X causes a "non-variable operand" scan error. EXAMPLE Addresses for particular systems may differ from those displayed here. ; mat A[3] ; B = blk() ; print &A, &A[0], &A[1] v-ptr: 1400470d0 v-ptr: 140044b70 v-ptr: 140044b80 ; print &B, &B[0], &B[1] v-ptr: 140047130 o-ptr: 140044d00 o-ptr: 140044d01 ; a = A[0] = 27 ; print &*a, &*A[0]. &27 n_ptr: 14003a850 n_ptr: 14003a850 n_ptr: 14003a850 ; a = A[0] = "abc" ; print &*a, &*A[0], &"abc" s_ptr: 14004cae0 s_ptr: 14004cae0 s_ptr: 14004cae0 LIMITS none LINK LIBRARY none SEE ALSO dereference, isptr ## 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: address,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/address,v $ ## ## Under source code control: 1997/09/06 20:03:34 ## 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 free - free the memory used to store values of lvalues SYNOPSIS free(a, b, ...) TYPES a, b, ... any return null value DESCRIPTION Those of the arguments a, b, ... that specify lvalues are assigned the null value, effectively freeing whatever memory is used to store their current values. Other arguments are ignored. free(.) frees the current "old value". EXAMPLE ; a = 7 ; mat M[3] = {1, list(2,3,4), list(5,6)} ; print memsize(a), memsize(M) 80 736 ; free(a, M[1]) ; print memsize(a), memsize(M) 16 424 LIMITS none LINK LIBRARY none SEE ALSO freeglobals, freestatics, freeredc ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: free,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/free,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 jacobi - Jacobi symbol function SYNOPSIS jacobi(x, y) TYPES x integer y integer return 1, -1, or 0 DESCRIPTION If y is a positive odd prime and x is an integer not divisible by y, jacobi(x,y) returns the Legendre symbol function, usually denoted by (x/y) as if x/y were a fraction; this has the value 1 or -1 according as x is or is not a quadratic residue modulo y. x is a quadratic residue modulo y if for some integer u, x = u^2 (mod y); if for all integers u, x != u^2 (mod y), x is said to be a quadratic nonresidue modulo y. If y is a positive odd prime and x is divisible by y, jacobi(x,y) returns the value 1. (This differs from the zero value usually given in number theory books for (x/y) when x and y are not relatively prime.) assigned to (x/y) O If y is an odd positive integer equal to p_1 * p_2 * ... * p_k, where the p_i are primes, not necessarily distinct, the jacobi symbol function is given by jacobi(x,y) = (x/p_1) * (x/p_2) * ... * (x/p_k). where the functions on the right are Legendre symbol functions. This is also often usually by (x/y). If jacobi(x,y) = -1, then x is a quadratic nonresidue modulo y. Equivalently, if x is a quadratic residue modulo y, then jacobi(x,y) = 1. If jacobi(x,y) = 1 and y is composite, x may be either a quadratic residue or a quadratic nonresidue modulo y. If y is even or negative, jacobi(x,y) as defined by calc returns the value 0. EXAMPLE ; print jacobi(2,3), jacobi(2,5), jacobi(2,15) -1 -1 1 ; print jacobi(80,199) 1 LIMITS none LINK LIBRARY NUMBER *qjacobi(NUMBER *x, NUMBER *y) FLAG zjacobi(ZVALUE z1, ZVALUE z2) SEE ALSO ## 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: jacobi,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/jacobi,v $ ## ## Under source code control: 1995/12/18 12:34:57 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME im - imaginary part of a real or complex number SYNOPSIS im(x) TYPES x real or complex return real DESCRIPTION If x = u + v * 1i where u and v are real, im(x) returns v. EXAMPLE ; print im(2), im(2 + 3i), im(-4.25 - 7i) 0 3 -7 LIMITS none LINK LIBRARY COMPLEX *c_imag(COMPLEX *x) SEE ALSO re ## 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: im,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/im,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/ NAME acosh - inverse hyperbolic cosine SYNOPSIS acosh(x [,eps]) TYPES x real, x >= 1 eps nonzero real, defaults to epsilon() return nonnegative real DESCRIPTION Returns the acosh of x to a multiple of eps with error less in absolute value than .75 * eps. acosh(x) is the nonnegative real number v for which cosh(v) = x. It is given by acosh(x) = ln(x + sqrt(x^2 - 1)) EXAMPLE ; print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20) 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 LIMITS none LINK LIBRARY NUMBER *qacosh(NUMBER *x, NUMBER *eps) SEE ALSO asinh, atanh, asech, acsch, acoth, 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: acosh,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/acosh,v $ ## ## Under source code control: 1994/03/19 01:40:24 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Builtin types The calculator has the following built-in types. null value This is the undefined value type. The function 'null' returns this value. Functions which do not explicitly return a value return this type. If a function is called with fewer parameters than it is defined for, then the missing parameters have the null type. The null value is false if used in an IF test. rational numbers This is the basic data type of the calculator. These are fractions whose numerators and denominators can be arbitrarily large. The fractions are always in lowest terms. Integers have a denominator of 1. The numerator of the number contains the sign, so that the denominator is always positive. When a number is entered in floating point or exponential notation, it is immediately converted to the appropriate fractional value. Printing a value as a floating point or exponential value involves a conversion from the fractional representation. Numbers are stored in binary format, so that in general, bit tests and shifts are quicker than multiplies and divides. Similarly, entering or displaying of numbers in binary, octal, or hex formats is quicker than in decimal. The sign of a number does not affect the bit representation of a number. complex numbers Complex numbers are composed of real and imaginary parts, which are both fractions as defined above. An integer which is followed by an 'i' character is a pure imaginary number. Complex numbers such as "2+3i" when typed in, are processed as the sum of a real and pure imaginary number, resulting in the desired complex number. Therefore, parenthesis are sometimes necessary to avoid confusion, as in the two values: 1+2i ^2 (which is -3) (1+2i) ^2 (which is -3+4i) Similar care is required when entering fractional complex numbers. Note the differences below: 3/4i (which is -(3/4)i) 3i/4 (which is (3/4)i) The imaginary unit itself is input using "1i". strings Strings are a sequence of zero or more characters. They are input using either of the single or double quote characters. The quote mark which starts the string also ends it. Various special characters can also be inserted using back-slash. Example strings: "hello\n" "that's all" 'lots of """"' 'a' "" There is no distinction between single character and multi-character strings. The 'str' and 'ord' functions will convert between a single character string and its numeric value. The 'str' and 'eval' functions will convert between longer strings and the corresponding numeric value (if legal). The 'strcat', 'strlen', and 'substr' functions are also useful. matrices These are one to four dimensional matrices, whose minimum and maximum bounds can be specified at runtime. Unlike C, the minimum bounds of a matrix do not have to start at 0. The elements of a matrix can be of any type. There are several built-in functions for matrices. Matrices are created using the 'mat' statement. associations These are one to four dimensional matrices which can be indexed by arbitrary values, instead of just integers. These are also known as associative arrays. The elements of an association can be of any type. Very few operations are permitted on an association except for indexing. Associations are created using the 'assoc' function. lists These are a sequence of values, which are linked together so that elements can be easily be inserted or removed anywhere in the list. The values can be of any type. Lists are created using the 'list' function. files These are text files opened using stdio. Files may be opened for sequential reading, writing, or appending. Opening a file using the 'fopen' function returns a value which can then be used to perform I/O to that file. File values can be copied by normal assignments between variables, or by using the result of the 'files' function. Such copies are indistinguishable from each other. ## 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: types,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/types,v $ ## ## Under source code control: 1991/07/21 04:37:24 ## 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 catalan - Catalan number SYNOPSIS catalan(n) TYPES n integer return integer DESCRIPTION If n >= 0, this returns the Catalan number for index n: catalan(n) = comb(2*n,n)/(n + 1) Zero is returned for negative n. The Catalan numbers occur in solutions of several elementary combinatorial problems, e.g. for n >= 1, catalan(n) is the number of ways of using parentheses to express a product of n + 1 letters in terms of binary products; it is the number of ways of dissecting a convex polygon with n + 2 sides into triangles by nonintersecting diagonals; it is the number of integer-component-incrementing paths from (x,y) = (0,0) to (x,y) = (n,n) for which always y <= x. EXAMPLE ; print catalan(2), catalan(3), catalan(4), catalan(20) 2 5 14 6564120420 LIMITS none LINK LIBRARY NUMBER *qcatalan(NUMBER *n) SEE ALSO 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: catalan,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/catalan,v $ ## ## Under source code control: 2000/12/14 01:33:00 ## File existed as early as: 2000 ## ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Unexpected While calc is C-like, users of C will find some unexpected surprises in calc syntax and usage. Persons familiar with C should review this file. Persons familiar with shell scripting may want to review this file as well, particularly notes dealing with command line evaluation and execution. The Comma ========= The comma is also used for continuation of obj and mat creation expressions and for separation of expressions to be used for arguments or values in function calls or initialization lists. The precedence order of these different uses is: continuation, separator, comma operator. For example, assuming the variables a, b, c, d, e, and object type xx have been defined, the arguments passed to f in: f(a, b, c, obj xx d, e) are a, b, c, and e, with e having the value of a newly created xx object. In: f((a, b), c, (obj xx d), e) the arguments of f are b, c, d, e, with only d being a newly created xx object. In combination with other operators, the continuation use of the comma has the same precedence as [] and ., the separator use the same as the comma operator. For example, assuming xx.mul() has been defined: f(a = b, obj xx c, d = {1,2} * obj xx e = {3,4}) passes two arguments: a (with value b) and the product d * e of two initialized xx objects. ^ is not xor ** is exponentiation ==================== In C, ^ is the xor operator. The expression: a ^ b yields "a to the b power", NOT "a xor b". Unlike in C, calc evaluates the expression: a ** b also yields "a to the b power". Here "a" and "b" can be a real value or a complex value: 2^3 3i^4 2.5 ^ 3.5 0.5i ^ 0.25 2.5 ^ 2.718i 3.13145i ^ 0.30103i In addition, "a" can be matrix. In this case "b" must be an integer: mat a[2,2] = {1,2,3,4}; a^3 Note that 'a' == 0 and 'b' is real, then is must be >= 0 as well. Also 0^0 and 0**0 return the value 1. Be careful about the precedence of operators. Note that: -1 ^ 0.5 == -1 whereas: (-1) ^ 0.5 == 1i because the above expression in parsed as: -(1 ^ 0.5) == -1 whereas: (-1) ^ 0.5 == 1i op= operators associate left to right ===================================== Operator-with-assignments: += -= *= /= %= //= &= |= <<= >>= ^= **= associate from left to right instead of right to left as in C. For example: a += b *= c has the effect of: a = (a + b) * c where only 'a' is required to be an lvalue. For the effect of: b *= c; a += b when both 'a' and 'b' are lvalues, use: a += (b *= c) || yields values other than 0 or 1 ================================== In C: a || b will produce 0 or 1 depending on the logical evaluation of the expression. In calc, this expression will produce either 'a' or 'b' and is equivalent to the expression: a ? a : b In other words, if 'a' is true, then 'a' is returned, otherwise 'b' is returned. && yields values other than 0 or 1 ================================== In C: a && b will produce 0 or 1 depending on the logical evaluation of the expression. In calc, this expression will produce either 'a' or 'b' and is equivalent to the expression: a ? b : a In other words, if 'a' is true, then 'b' is returned, otherwise 'a' is returned. / is fractional divide, // is integral divide ============================================= In C: x/y performs integer division when 'x' and 'y' are integer types. In calc, this expression yields a rational number. Calc uses: x//y to perform division with integer truncation and is the equivalent to: int(x/y) | and & have higher precedence than ==, +, -, *, / and % ======================================================== Is C: a == b | c * d is interpreted as: (a == b) | (c * d) and calc it is interpreted as: a == ((b | c) * d) calc always evaluates terms from left to right ============================================== Calc has a definite order for evaluation of terms (addends in a sum, factors in a product, arguments for a function or a matrix, etc.). This order is always from left to right. but skipping of terms may occur for ||, && and ? : . Consider, for example: A * B + C * D In calc above expression is evaluated in the following order: A B A * B C D C * D A * B + C * D This order of evaluation is significant if evaluation of a term changes a variable on which a later term depends. For example: x++ * x++ + x++ * x++ in calc returns the value: x * (x + 1) + (x + 2) * (x + 3) and increments x as if by x += 4. Similarly, for functions f, g, the expression: f(x++, x++) + g(x++) evaluates to: f(x, x + 1) + g(x + 2) and increments x three times. In an other example, this expression: 1<<8/2 evalues to 128, not 16, because <<8 is performed before the /2. &A[0] and A are different things in calc ======================================== In calc, value of &A[0] is the address of the first element, whereas A is the entire array. *X may be used to to return the value of X ========================================== If the current value of a variable X is an octet, number or string, *X may be used to to return the value of X; in effect X is an address and *X is the value at X. freeing a variable has the effect of assigning the null value to it =================================================================== The freeglobals(), freestatics(), freeredc() and free() free builtins to not "undefine" the variables, but have the effect of assigning the null value to them, and so frees the memory used for elements of a list, matrix or object. Along the same lines: undefine * undefines all current user-defined functions. After executing all the above freeing functions (and if necessary free(.) to free the current "old value"), the only remaining numbers as displayed by show numbers should be those associated with epsilon(), and if it has been called, qpi(). #! is also a comment ==================== In addition to the C style /* comment lines */, lines that begin with #! are treated as comments. A single # is an calc operator, not a comment. However two or more ##'s in a row is a comment. See "help pound" for more information. #!/usr/local/src/cmd/calc/calc -q -f /* a correct comment */ ## another correct comment ### two or more together is also a comment /* * another correct comment */ print "2+2 =", 2+2; ## yet another comment This next example is WRONG: #!/usr/local/src/cmd/calc/calc -q -f # This is not a calc calc comment because it has only a single # # You must to start comments with ## or /* print "This example has invalid comments" See "help cscript" and "help usage" for more information. The { must be on the same line as an if, for, while or do ========================================================= When statement is of the form { ... }, the leading { MUST BE ON THE SAME LINE as the if, for, while or do keyword. This works as expected: if (expr) { ... } However this WILL NOT WORK AS EXPECTED: if (expr) { ... } because calc will parse the if being terminated by an empty statement followed by a if (expr) ; { ... } In the same way, use these forms: for (optionalexpr ; optionalexpr ; optionalexpr) { ... } while (expr) { ... } do { ... while (expr); where the initial { is on the SAME LINE as the if, while, for or do keyword. NOTE: See "help statement", "help todo", and "help bugs". Shell evaluation of command line arguments ========================================== In most interactive shells: calc 2 * 3 will frequently produce a "Missing operator" error because the '*' is evaluated as a "shell glob". To avoid this you must quote or escape argument with characters that your interactive shell interprets. For example, bash / ksh / sh shell users should use: calc '2 * 3' or: calc 2 \* 3 or some other form of shell meta-character escaping. Calc reads standard input after processing command line args ============================================================ The shell command: seq 5 | while read i; do calc "($i+3)^2"; done FYI: The command "seq 5" will write 1 through 5 on separate lines on standard output, while read i sets $i to the value of each line that is read from stdin. will produce: 16 2 3 4 5 The reason why the last 4 lines of output are 2 through 5 is that after calc evaluates the first line and prints (1+3)^2 (i.e., 16), calc continues to read stdin and slurps up all of the remaining data on the pipe. To avoid this problem, use: seq 5 | while read i; do calc "($i+3)^2" /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME freeglobals - free memory used for values of global variables SYNOPSIS freeglobals() TYPES return null value DESCRIPTION This function frees the memory used for the values of all global and not unscoped static variables by assigning null values. The oldvalue (.) is not freed by this function. EXAMPLE ; global a = 1, b = list(2,3,4), c = mat[3] ; static a = 2 ; show globals Name Level Type ---- ----- ----- a 1 real = 2 a 0 real = 1 b 0 list c 0 matrix Number: 4 ; freeglobals() ; show globals Name Level Type ---- ----- ----- a 1 null a 0 null b 0 null c 0 null Number: 4 LIMITS none LINK LIBRARY none SEE ALSO free, freestatics, freeredc ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: freeglobals,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeglobals,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 stoponerror - controls when / if calc stops calculations based on errors SYNOPSIS stoponerror([n]) TYPES n integer return null value or error value DESCRIPTION The stoponerror controls when or if calc stops based on the number of errors: n == -1 do not stop n == 0 stop on error unless calc was invoked with -c n > 0 stop when n errors are encountered When no arguments are given, stoponerror() returns the current stoponerror value. When 1 argument is given, stoponerror() returns the previous stoponerror value. EXAMPLE ; stoponerror() 0 LIMITS -1 <= stoponerror < 2147483647 LINK LIBRARY none SEE ALSO errcount, errmax, errorcodes, iserror, errno, strerror, newerror ## Copyright (C) 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. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: stoponerror,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/stoponerror,v $ ## ## Under source code control: 2006/05/21 00:50:59 ## 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 fputstr - send one or more null-terminated strings to a file SYNOPSIS fputstr(fs, s_1, s_2, ...) TYPES fs file stream open for writing s_1, ... string return null or error value DESCRIPTION If the stream cannot be written to or an argument is of the wrong type, an error value is returned. Otherwise the strings s_1, s_2, ..., including the terminating null characters ('\0') are written to the file stream fs. EXAMPLE ; f = fopen("/tmp/junk", "w") ; fputstr(f, "Alpha", "Beta") ; freopen(f, "r") ; fgetstr(f) "Alpha" ; fgetstr(f) "Beta" ; fgetstr(f) ; fputstr(f, "Gamma") Error 72 LIMITS none LINK LIBRARY none SEE ALSO fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf ## 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: fputstr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fputstr,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 hmean - harmonic mean of a number of values SYNOPSIS hmean(x_1, x_2, ...) TYPES x_1, ... arithmetic or list return determined by types of arguments, or null DESCRIPTION The null value is returned if there are no arguments. If there are n non-list arguments x_1, x_2, ... and the required operations are defined, hmean(x_1, x_2, ...) returns the value of: n/(inverse(x_1) + inverse(x_2) + ... + inverse(x_n)). If an argument x_i is a list as defined by list(y_1, ..., y_m) this is treated as if in (x_1, x_2, ...), x_i is replaced by y_1, ..., y_m. EXAMPLE ; c = config("mode", "frac") ; print hmean(1), hmean(1,2), hmean(1,2,3), hmean(1,2,3,4), hmean(1,2,0,3) 1 4/3 18/11 48/25 0 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY none SEE ALSO avg ## 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: hmean,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/hmean,v $ ## ## Under source code control: 1995/12/18 03:30:59 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Where to get the the latest versions of calc Landon Noll maintains the official calc home page at: http://www.isthe.com/chongo/tech/comp/calc/ See: http://www.isthe.com/chongo/tech/comp/calc/calc-download.html for information on how to obtain up a recent version of calc. Landon Curt Noll http://www.isthe.com/chongo/ chongo /\../\ ## 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: archive,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/archive,v $ ## ## Under source code control: 1996/06/13 02:51:48 ## 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 ismult - whether a value is a multiple of another SYNOPSIS ismult(x, y) TYPES x real y real return int DESCRIPTION Determine if x exactly divides y. If there exists an integer k such that: x == y * k then return 1, otherwise return 0. EXAMPLE ; print ismult(6, 2), ismult(2, 6), ismult(7.5, 2.5) 1 0 1 ; print ismult(4^67, 2^59), ismult(13, 4/67), ismult(13, 7/56) 1 0 1 LIMITS none LINK LIBRARY BOOL qdivides(NUMBER *x, *y) BOOL zdivides(ZVALUE x, y) SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: ismult,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ismult,v $ ## ## Under source code control: 1994/10/21 02:21:28 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/