NAME asec - inverse trigonometric secant SYNOPSIS asec(x [,eps]) TYPES x real, with absolute value >= 1 eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the asec of x to a multiple of eps with error less in absolute value than .75 * eps. v = asec(x) is the number in [0, pi] for which sec(v) = x. EXAMPLE ; print asec(2, 1e-5), asec(2, 1e-10), asec(2, 1e-15), asec(2, 1e-20) 1.0472 1.0471975512 1.047197551196598 1.04719755119659774615 LIMITS none LINK LIBRARY NUMBER *qasec(NUMBER *x, NUMBER *eps) SEE ALSO asin, acos, atan, acsc, acot, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: asec,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asec,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 sqrt - evaluate exactly or approximate a square root SYNOPSIS sqrt(x [, eps[, z]]) TYPES If x is an object of type tt, or if x is not an object but y is an object of type tt, and the user-defined function tt_round has been defined, the types for x, y, z are as required for tt_round, the value returned, if any, is as specified in tt_round. For object x or y, z defaults to a null value. For other argument types: x real or complex eps nonzero real z integer return real or complex DESCRIPTION For real or complex x, sqrt(x, y, z) returns either the exact value of a square root of x (which is possible only if this square root is rational) or a number for which the real and imaginary parts are either exact or the nearest below or nearest above to the exact values. The argument, eps, specifies the epsilon/error value to be used during calculations. By default, this value is epsilon(). The seven lowest bits of z are used to control the signs of the result and the type of any rounding: z bit 6 ((z & 64) > 0) 0: principal square root 1: negative principal square root z bit 5 ((z & 32) > 0) 0: return aprox square root 1: return exact square root when real & imaginary are rational z bits 5-0 (z & 31) 0: round down or up according as y is positive or negative, sgn(r) = sgn(y) 1: round up or down according as y is positive or negative, sgn(r) = -sgn(y) 2: round towards zero, sgn(r) = sgn(x) 3: round away from zero, sgn(r) = -sgn(x) 4: round down 5: round up 6: round towards or from zero according as y is positive or negative, sgn(r) = sgn(x/y) 7: round from or towards zero according as y is positive or negative, sgn(r) = -sgn(x/y) 8: a/y is even 9: a/y is odd 10: a/y is even or odd according as x/y is positive or negative 11: a/y is odd or even according as x/y is positive or negative 12: a/y is even or odd according as y is positive or negative 13: a/y is odd or even according as y is positive or negative 14: a/y is even or odd according as x is positive or negative 15: a/y is odd or even according as x is positive or negative The value of y and lowest 5 bits of z are used in the same way as y and z in appr(x, y, z): for either the real or imaginary part of the square root, if this is a multiple of y, it is returned exactly; otherwise the value returned for the part is the multiple of y nearest below or nearest above the true value. For z = 0, the remainder has the sign of y; changing bit 0 changes to the other possibility; for z = 2, the remainder has the sign of the true value, i.e. the rounding is towards zero; for z = 4, the remainder is always positive, i.e. the rounding is down; for z = 8, the rounding is to the nearest even multiple of y; if 16 <= z < 32, the rounding is to the nearest multiple of y when this is uniquely determined and otherwise is as if z were replaced by z - 16. With the initial default values, 1e-20 for epsilon() and 24 for config("sqrt"), sqrt(x) returns the principal square root with real and imaginary parts rounded to 20 decimal places, the 20th decimal digit being even when the part differs from a multiple of 1e-20 by 1/2 * 1e-20. EXAMPLE ; eps = 1e-4 ; print sqrt(4,eps,0), sqrt(4,eps,64), sqrt(8i,eps,0), sqrt(8i, eps, 64) 2 -2 2+2i -2-2i ; print sqrt(2,eps,0), sqrt(2,eps,1), sqrt(2,eps,24) 1.4142 1.4143 1.4142 ; x = 1.2345678^2 ; print sqrt(x,eps,24), sqrt(x,eps,32), sqrt(x,eps,96) 1.2346 1.2345678 -1.2345678 ; print sqrt(.00005^2, eps, 24), sqrt(.00015^2, eps, 24) 0 .0002 LIMITS none LINK LIBRARY COMPLEX *c_sqrt(COMPLEX *x, NUMBER *ep, long z) NUMBER *qisqrt(NUMBER *q) NUMBER *qsqrt(NUMBER *x, NUMBER *ep, long z) FLAG zsqrt(ZVALUE x, ZVALUE *result, long z) SEE ALSO appr, 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: sqrt,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sqrt,v $ ## ## Under source code control: 1995/09/18 03:54:32 ## 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 mne - test for inequality of real numbers modulo a specifed number SYNOPSIS mne(x, y, md) TYPES x real number y real number md real number return 0 or 1 DESCRIPTION Returns 1 if and only if x is not congruent to y modulo md, i.e. for every integer n, x - y != n * md. EXAMPLE print mne(5, 33, 7), mne(5, -23, 7), mne(5, 15, 7), mne(5, 7, 0) 0 0 1 1 LIMITS none LINK LIBRARY none SEE ALSO meq ## 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: mne,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mne,v $ ## ## Under source code control: 1995/11/09 03:27:51 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME list - create list of specified values SYNOPSIS list([x, [x, ... ]]) TYPES x any, &any return list DESCRIPTION This function returns a list that is composed of the arguments x. If no args are given, an empty list is returned. Lists are a sequence of values which are doubly linked so that elements can be removed or inserted anywhere within the list. The function 'list' creates a list with possible initial elements. For example, x = list(4, 6, 7); creates a list in the variable x of three elements, in the order 4, 6, and 7. The 'push' and 'pop' functions insert or remove an element from the beginning of the list. The 'append' and 'remove' functions insert or remove an element from the end of the list. The 'insert' and 'delete' functions insert or delete an element from the middle (or ends) of a list. The functions which insert elements return the null value, but the functions which remove an element return the element as their value. The 'size' function returns the number of elements in the list. Note that these functions manipulate the actual list argument, instead of returning a new list. Thus in the example: push(x, 9); x becomes a list of four elements, in the order 9, 4, 6, and 7. Lists can be copied by assigning them to another variable. An arbitrary element of a linked list can be accessed by using the double-bracket operator. The beginning of the list has index 0. Thus in the new list x above, the expression x[[0]] returns the value of the first element of the list, which is 9. Note that this indexing does not remove elements from the list. Since lists are doubly linked in memory, random access to arbitrary elements can be slow if the list is large. However, for each list a pointer is kept to the latest indexed element, thus relatively sequential accesses to the elements in a list will not be slow. Lists can be searched for particular values by using the 'search' and 'rsearch' functions. They return the element number of the found value (zero based), or null if the value does not exist in the list. EXAMPLE ; list(2,"three",4i) list (3 elements, 3 nonzero): [[0]] = 2 [[1]] = "three" [[2]] = 4i ; list() list (0 elements, 0 nonzero) LIMITS none LINK LIBRARY none SEE ALSO append, delete, insert, islist, pop, push, remove, rsearch, search, size ## 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: list,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/list,v $ ## ## Under source code control: 1994/03/19 03:13:19 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Command history There is a command line editor and history mechanism built into calc, which is active when stdin is a terminal. When stdin is not a terminal, then the command line editor is disabled. Lines of input to calc are always terminated by the return (or enter) key. When the return key is typed, then the current line is executed and is also saved into a command history list for future recall. Before the return key is typed, the current line can be edited using emacs-like editing commands. As examples, ^A moves to the beginning of the line, ^F moves forwards through the line, backspace removes characters from the line, and ^K kills the rest of the line. Previously entered commands can be recalled by using the history list. The history list functions in a LRU manner, with no duplicated lines. This means that the most recently entered lines are always at the end of the history list where they are easiest to recall. Typing h lists all of the commands in the command history and numbers the lines. The most recently executed line is always number 1, the next most recent number 2, and so on. The numbering for a particular command therefore changes as lines are entered. Typing a number at the beginning of a line followed by g will recall that numbered line. So that for example, 2g will recall the second most recent line that was entered. The ^P and ^N keys move up and down the lines in the history list. If they attempt to go off the top or bottom of the list, then a blank line is shown to indicate this, and then they wrap around to the other end of the list. Typing a string followed by a ^R will search backwards through the history and recall the most recent command which begins with that string. Typing ^O inserts the current line at the end of the history list without executing it, and starts a new line. This is useful to rearrange old history lines to become recent, or to save a partially completed command so that another command can be typed ahead of it. If your terminal has arrow keys which generate escape sequences of a particular kind ([A and so on), then you can use those arrow keys in place of the ^B, ^F, ^P, and ^N keys. The actual keys used for editing are defined in a bindings file, usually called /usr/local/lib/calc/bindings. Changing the entries in this file will change the key bindings used for editing. If the file is not readable, then a message will be output and command line editing is disabled. In this case you can only edit each line as provided by the terminal driver in the operating system. A shell command can be executed by typing '!cmd', where cmd is the command to execute. If cmd is not given, then a shell command level is started. ## 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: history,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/history,v $ ## ## Under source code control: 1991/07/21 04:37:20 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME ferror - determine if an error has occurred for file SYNOPSIS ferror(fd) TYPES fd file return int DESCRIPTION This function determines whether the error condition was detected while performing some operation on the file associated with fd. The error need not have been the previous file operation. If an error was previously reported 1 will be returned, otherwise 0 is returned. EXAMPLE ; fd = fopen("/etc/motd", "r") ; ferror(fd) 0 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: ferror,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ferror,v $ ## ## Under source code control: 1994/10/27 03:04:17 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME isptr - whether a value is a pointer SYNOPSIS isptr(x) TYPES x any return 0, 1, 2, 3, or 4 DESCRIPTION isptr(x) returns: 0 if x is a not pointer 1 if x is an octet-pointer 2 if x is a value-pointer 3 if x is a string-pointer 4 if x is a number-pointer Pointers are initially defined by using the addreess (&) operator with an "addressable" value; currently, these are octets, lvalues, strings and real numbers. EXAMPLE ; a = "abc", b = 3, B = blk() ; p1 = &B[1] ; p2 = &a ; p3 = &*a ; p4 = &*b ; print isptr(a), isptr(p1), isptr(p2), isptr(p3), isptr(p4) 0 1 2 3 4 LIMITS none LINK LIBRARY none SEE ALSO isnum, isstr, isblk, isoctet ## 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: isptr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isptr,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 cmp - compare two values of certain simple or object types SYNOPSIS cmp(x, y) TYPES If x is an object of type xx, or x is not an object and y is an object of type xx, the function xx_rel has to have been defined; any further conditions on x and y, and the type of the returned value depends on the definition of xx_rel. For non-object x and y: x any y any return if x and y are both real: -1, 0, or 1 if x and y are both numbers but not both real: -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i, or 1-1i if x and y are both strings: -1, 0, or 1 all other cases: the null value DESCRIPTION x and y both real: cmp(x, y) = sgn(x - y), i.e. -1, 0, or 1 according as x < y, x == y, or x > y x and y both numbers, at least one being complex: cmp(x,y) = sgn(re(x) - re(y)) + sgn(im(x) - im(y)) * 1i x and y both strings: successive characters are compared until either different characters are encountered or at least one string is completed. If the comparison ends because of different characters, cmp(x,y) = 1 or -1 according as the greater character is in x or y. If all characters compared in both strings are equal, then cmp(x,y) = -1, 0 or 1 according as the length of x is less than, equal to, or greater than the length of y. (This comparison is performed via the strcmp() libc function.) objects: comparisons of objects are usually intended for some total or partial ordering and appropriate definitions of cmp(a,b) may make use of comparison of numerical or string components. definitions using comparison of numbers or strings are usually appropriate. For example, after obj point {x,y}; if points with real components are to be partially ordered by their euclidean distance from the origin, an appropriate point_rel function may be that given by define point_rel(a,b) = sgn(a.x^2 + a.y^2 - b.x^2 - b.y^2); A total "lexicographic" ordering is that given by: define point_rel(a,b) { if (a.y != b.y) return sgn(a.y - b.y); return (a.x - b.x); } A comparison function that compares points analogously to cmp(a,b) for real and complex numbers is that given by define point_rel(P1, P2) { return obj point = {sgn(P1.x-P2.x), sgn(P1.y-P2.y)}; } The range of this function is the set of nine points with zero or unit components. Some properties of cmp(a,b) for real or complex a and b are: cmp(a + c, b + c) = cmp(a, b) cmp(a, b) == 0 if and only if a == b cmp(b, a) = -cmp(a, b) if c is real or pure imaginary, cmp(c * a, c * b) = c * cmp(a,b) Then a function that defines "b is between a and c" in an often useful sense is define between(a,b,c) = (cmp(a,b) == cmp(b,c)). For example, in this sense, 3 + 4i is between 1 + 5i and 4 + 2i. Note that using cmp to compare non-object values of different types, for example, cmp(2, "2"), returns the null value. EXAMPLE ; print cmp(3,4), cmp(4,3), cmp(4,4), cmp("a","b"), cmp("abcd","abc") -1 1 0 -1 1 ; print cmp(3,4i), cmp(4,4i), cmp(5,4i), cmp(-5,4i), cmp(-4i,5), cmp(-4i,-5) 1-1i 1-1i 1-1i -1-1i -1-1i 1-1i ; print cmp(3i,4i), cmp(4i,4i), cmp(5i,4i), cmp(3+4i,5), cmp(3+4i,-5) -1i 0 1i -1+1i 1+1i ; print cmp(3+4i,3+4i), cmp(3+4i,3-4i), cmp(3+4i,2+3i), cmp(3+4i,-4-5i) 0 1i 1+1i 1+1i LIMITS none LINK LIBRARY FLAG qrel(NUMBER *q1, NUMBER *q2) FLAG zrel(ZVALUE z1, ZVALUE z2) SEE ALSO sgn, test, operator ## 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: cmp,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cmp,v $ ## ## Under source code control: 1994/10/20 02:52:30 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME memsize - number of bytes required for value including overhead SYNOPSIS memsize(x) TYPES x any return integer DESCRIPTION This is analogous to the C operator sizeof. It attempts to assess the number of bytes in memory used to store a value and all its components plus all of the related structue overhead. Unlike sizeof(x), this builtin includes overhead. Unlike size(x), this builtin incldues the trailing \0 byte on the end of strings. Unlike sizeof(x), this builtin includes the size demonitor for integers and the imaginary part for complex values. Storage for holding 0, 1 and -1 values are also included. The number returned by memsize(x) may be less than the actual number used because, for example, more memory may have been allocated for a string than is used: only the characters up to and including the first '\0' are counted in calculating the contribution of the string to memsize(x). The number returned by memsize(x) may be greater (and indeed substantially greater) than the number of bytes actually used. For example, after: a = sqrt(2); mat A[3] = {a, a, a}; the numerical information for a, A[0], A[1], A[2] are stored in the same memory, so the memory used for A is the same as if its 3 elements were null values. The value returned by memsize(A) is calculated as A were defined by: mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. Similar sharing of memory occurs with literal strings. For associative arrays, both the name part and the value part of the name/value pair are counted. The minimum value for memsize(x) occurs for the null and error values. EXAMPLES The results for examples like these will depend to some extent on the system being used. The following were for an SGI R4k machine in 32-bit mode: ; print memsize(null()) 8 ; print memsize(0), memsize(3), memsize(2^32 - 1), memsize(2^32) 68 68 68 72 ; x = sqrt(2, 1e-100); print memsize(x), memsize(num(x)), memsize(den(x)) 148 108 108 ; print memsize(list()), memsize(list(1)), memsize(list(1,2)) 28 104 180 ; print memsize(list()) 28 ; print ,memsize(list(1)),memsize(list(1,2)),memsize(list(1,2,3)) 104 180 256 ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100]; ; print memsize(A), memsize(B), memsize(C), memsize(D) 124 192 260 680056 ; obj point {x,y,z} ; obj point P = {1,2,3}; print memsize(P) 274 LIMITS It is assumed memsize(x) will fit into a system long integer. LINK LIBRARY none SEE ALSO size, sizeof, fsize, strlen, digits ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: memsize,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/memsize,v $ ## ## Under source code control: 1997/03/23 20:28:02 ## 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 fseek - set a file position SYNOPSIS fseek(fd, offset [, whence]) TYPES fd open file stream pos integer whence 0, 1 or 2, defaulting to 0 return null or error value DESCRIPTION This function sets the file position indicator for the stream by adding offset to zero, the current value, or the size of the file, according as whence is 0, 1 or 2. The effect is equivalent to moving the signed distance offset from the beginning, the current position, or the end of the file. The function also clears the end-of-file flag and flushes any buffered data waiting to be output to the stream. An implementation-defined error occurs if the effect would be to give a negative value to the position indicator; on some systems, the file position will be set to end-of-file. The file position indicator may have a value greater than the file size. If characters are then written to the file, the gap is filled by null ('\0') characters. EXAMPLE ; fd = fopen("/tmp/curds", "w") ; fputs(fd, "0123456789abcdef") ; freopen(fd, "r") ; fsize(fd) 16 ; fseek(fd, 5) ; fgets(fd) "56789abcdef" ; fseek(fd, 0) ; fscanf(fd, "%*5c") 0 ; fseek(fd, 5, 1) ; fgets(fd) "abcdef" ; ftell(fd) 16 ; fseek(fd, -5, 2) ; fgets(fd) "bcdef" ; fseek(fd, -2) System error 22 ; ftell(fd) 16 The results for the last four lines may be different for different systems. LIMITS Some details of the operation of this function may be implementation- dependent, particularly for older systems. LINK LIBRARY none SEE ALSO ftell, fgetpos, fsetpos, rewind, strerror ## 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: fseek,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fseek,v $ ## ## Under source code control: 1995/03/04 11:33:20 ## 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 asinh - inverse hyperbolic sine SYNOPSIS asinh(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the asinh of x to a multiple of eps with error less in absolute value than .75 * eps. asinh(x) is the real number v for which sinh(v) = x. It is given by asinh(x) = ln(x + sqrt(1 + x^2)) EXAMPLE ; print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20) 1.44363 1.4436354752 1.44363547517881 1.44363547517881034249 LIMITS none LINK LIBRARY NUMBER *qasinh(NUMBER *x, NUMBER *eps) SEE ALSO acosh, 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: asinh,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asinh,v $ ## ## Under source code control: 1994/03/19 01:40:25 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME ssq - sum of squares SYNOPSIS ssq(x1, x2, ...) TYPES x1, x2, ... lists or values for which required operations are defined return as determined by the operations on x1, x2, ... DESCRIPTION Null values are ignored; ssq() returns the null value. If no argument is a list, returns x1^2 + x2^2 + ... If an argument = list(t1, t2, ...) it contributes ssq(t1, t2, ...) to the result. EXAMPLE ; print ssq(1,2,3), ssq(1+2i, 3-4i, 5 +6i) 14 -21+40i ; mat A[2,2] = {1,2,3,4}; mat B[2,2] = {5,6,7,8} ; print ssq(A, B, A + B) mat [2,2] (4 elements, 4 nonzero): [0,0] = 190 [0,1] = 232 [1,0] = 286 [1,1] = 352 ; ssq(list(2,3,5),7) 87 ; ssq(1,2,3,4,5,6,7,8) 204 ; ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) 204 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY none SEE ALSO sum, max, min ## 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: ssq,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/ssq,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/ CALC - An arbitrary precision calculator. by David I. Bell This is a calculator program with arbitrary precision arithmetic. All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. Real or exponential format numbers can be input and are converted to the equivalent fraction. Hex, binary, or octal numbers can be input by using numbers with leading '0x', '0b' or '0' characters. Complex numbers can be input using a trailing 'i', as in '2+3i'. Strings and characters are input by using single or double quotes. Commands are statements in a C-like language, where each input line is treated as the body of a procedure. Thus the command line can contain variable declarations, expressions, labels, conditional tests, and loops. Assignments to any variable name will automatically define that name as a global variable. The other important thing to know is that all non-assignment expressions which are evaluated are automatically printed. Thus, you can evaluate an expression's value by simply typing it in. Many useful built-in mathematical functions are available. Use the 'show builtins' command to list them. You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C. Functions which only need to return a simple expression can be defined using an equals sign, as in the example 'define sc(a,b) = a^3 + b^3'. Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the command line, whereas local variables are unique to each function level, and are destroyed when the function returns. Static variables are scoped within single input files, or within functions, and are never destroyed. Variables are not typed at definition time, but dynamically change as they are used. So you must supply the correct type of variable to those functions and operators which only work for a subset of types. Calc has a help command that will produce information about every builtin function, command as well as a number of other aspects of calc usage. Try the command: help help for and overview of the help system. The command: help builtin provides information on built-in mathematical functions, whereas: help asinh will provides information a specific function. The following help files: help command help define help operator help statement help variable provide a good overview of the calc language. If you are familiar with C, you should also try: help unexpected It contains information about differences between C and calc that may surprize you. To learn about calc standard resource files, try: help resource To learn how to invoke the calc command and about calc -flags, try: help usage To learn about calc shell scripts, try: help script A full and extensive overview of calc may be obtained by: help full By default, arguments to functions are passed by value (even matrices). For speed, you can put an ampersand before any variable argument in a function call, and that variable will be passed by reference instead. However, if the function changes its argument, the variable will change. Arguments to built-in functions and object manipulation functions are always called by reference. If a user-defined function takes more arguments than are passed, the undefined arguments have the null value. The 'param' function returns function arguments by argument number, and also returns the number of arguments passed. Thus functions can be written to handle an arbitrary number of arguments. The mat statement is used to create a matrix. It takes a variable name, followed by the bounds of the matrix in square brackets. The lower bounds are zero by default, but colons can be used to change them. For example 'mat foo[3, 1:10]' defines a two dimensional matrix, with the first index ranging from 0 to 3, and the second index ranging from 1 to 10. The bounds of a matrix can be an expression calculated at runtime. Lists of values are created using the 'list' function, and values can be inserted or removed from either the front or the end of the list. List elements can be indexed directly using double square brackets. The obj statement is used to create an object. Objects are user-defined values for which user-defined routines are implicitly called to perform simple actions such as add, multiply, compare, and print. Objects types are defined as in the example 'obj complex {real, imag}', where 'complex' is the name of the object type, and 'real' and 'imag' are element names used to define the value of the object (very much like structures). Variables of an object type are created as in the example 'obj complex x,y', where 'x' and 'y' are variables. The elements of an object are referenced using a dot, as in the example 'x.real'. All user-defined routines have names composed of the object type and the action to perform separated by an underscore, as in the example 'complex_add'. The command 'show objfuncs' lists all the definable routines. Object routines which accept two arguments should be prepared to handle cases in which either one of the arguments is not of the expected object type. These are the differences between the normal C operators and the ones defined by the calculator. The '/' operator divides fractions, so that '7 / 2' evaluates to 7/2. The '//' operator is an integer divide, so that '7 // 2' evaluates to 3. The '^' operator is a integral power function, so that 3^4 evaluates to 81. Matrices of any dimension can be treated as a zero based linear array using double square brackets, as in 'foo[[3]]'. Matrices can be indexed by using commas between the indices, as in foo[3,4]. Object and list elements can be referenced by using double square brackets. The print statement is used to print values of expressions. Separating values by a comma puts one space between the output values, whereas separating values by a colon concatenates the output values. A trailing colon suppresses printing of the end of line. An example of printing is 'print \"The square of\", x, \"is\", x^2\'. The 'config' function is used to modify certain parameters that affect calculations or the display of values. For example, the output display mode can be set using 'config(\"mode\", type)', where 'type' is one of 'frac', 'int', 'real', 'exp', 'hex', 'oct', or 'bin'. The default output mode is real. For the integer, real, or exponential formats, a leading '~' indicates that the number was truncated to the number of decimal places specified by the default precision. If the '~' does not appear, then the displayed number is the exact value. The number of decimal places printed is set by using 'config(\"display\", n)'. The default precision for real-valued functions can be set by using 'epsilon(x)', where x is the required precision (such as 1e-50). There is a command stack feature so that you can easily re-execute previous commands and expressions from the terminal. You can also edit the current command before it is completed. Both of these features use emacs-like commands. Files can be read in by using the 'read filename' command. These can contain both functions to be defined, and expressions to be calculated. Global variables which are numbers can be saved to a file by using the 'write filename' command. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: overview,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/overview,v $ ## ## Under source code control: 1991/07/21 04:37:23 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place sati=Ë>Ë?Ë@ËAËBËCËDËEËFËGËHËIËJËsfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the L