home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / calc-2.9.0 / part15 < prev    next >
Text File  |  1993-12-07  |  61KB  |  1,586 lines

  1. Newsgroups: comp.sources.unix
  2. From: dbell@canb.auug.org.au (David I. Bell)
  3. Subject: v27i142: calc-2.9.0 - arbitrary precision C-like programmable calculator, Part15/19
  4. References: <1.755316719.21314@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: dbell@canb.auug.org.au (David I. Bell)
  9. Posting-Number: Volume 27, Issue 142
  10. Archive-Name: calc-2.9.0/part15
  11.  
  12. #!/bin/sh
  13. # this is part 15 of a multipart archive
  14. # do not concatenate these parts, unpack them in order with /bin/sh
  15. # file calc2.9.0/help/intro continued
  16. #
  17. CurArch=15
  18. if test ! -r s2_seq_.tmp
  19. then echo "Please unpack part 1 first!"
  20.      exit 1; fi
  21. ( read Scheck
  22.   if test "$Scheck" != $CurArch
  23.   then echo "Please unpack part $Scheck next!"
  24.        exit 1;
  25.   else exit 0; fi
  26. ) < s2_seq_.tmp || exit 1
  27. echo "x - Continuing file calc2.9.0/help/intro"
  28. sed 's/^X//' << 'SHAR_EOF' >> calc2.9.0/help/intro
  29. X
  30. X        fact(old)
  31. X
  32. X    and the calculator prints 13763753091226345046315979581580902400000000.
  33. X    Notice that numbers can be very large. (There is a practical limit
  34. X    of several thousand digits before calculations become too slow.)
  35. X
  36. X    The calculator can calculate transcendental functions, and accept and
  37. X    display numbers in real or exponential format. For example, typing:
  38. X
  39. X        config("display", 50)
  40. X        epsilon(1e-50)
  41. X        sin(1)
  42. X
  43. X    prints "~.84147098480789650665250232163029899962256306079837".
  44. X
  45. X    The calculator also knows about complex numbers, so that typing:
  46. X
  47. X        (2+3i) * (4-3i)
  48. X
  49. X    prints "17+6i".
  50. SHAR_EOF
  51. echo "File calc2.9.0/help/intro is complete"
  52. chmod 0644 calc2.9.0/help/intro || echo "restore of calc2.9.0/help/intro fails"
  53. set `wc -c calc2.9.0/help/intro`;Sum=$1
  54. if test "$Sum" != "1895"
  55. then echo original size 1895, current size $Sum;fi
  56. echo "x - extracting calc2.9.0/help/list (Text)"
  57. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/list &&
  58. XUsing lists
  59. X
  60. X    Lists are a sequence of values which are doubly linked so that
  61. X    elements can be removed or inserted anywhere within the list.
  62. X    The function 'list' creates a list with possible initial elements.
  63. X    For example,
  64. X
  65. X        x = list(4, 6, 7);
  66. X
  67. X    creates a list in the variable x of three elements, in the order
  68. X    4, 6, and 7.
  69. X
  70. X    The 'push' and 'pop' functions insert or remove an element from
  71. X    the beginning of the list.  The 'append' and 'remove' functions
  72. X    insert or remove an element from the end of the list.  The 'insert'
  73. X    and 'delete' functions insert or delete an element from the middle
  74. X    (or ends) of a list.  The functions which insert elements return
  75. X    the null value, but the functions which remove an element return
  76. X    the element as their value.  The 'size' function returns the number
  77. X    of elements in the list.
  78. X
  79. X    Note that these functions manipulate the actual list argument,
  80. X    instead of returning a new list.  Thus in the example:
  81. X
  82. X        push(x, 9);
  83. X
  84. X    x becomes a list of four elements, in the order 9, 4, 6, and 7.
  85. X    Lists can be copied by assigning them to another variable.
  86. X
  87. X    An arbitrary element of a linked list can be accessed by using the
  88. X    double-bracket operator.  The beginning of the list has index 0.
  89. X    Thus in the new list x above, the expression x[[0]] returns the
  90. X    value of the first element of the list, which is 9.  Note that this
  91. X    indexing does not remove elements from the list.
  92. X
  93. X    Since lists are doubly linked in memory, random access to arbitrary
  94. X    elements can be slow if the list is large.  However, for each list
  95. X    a pointer is kept to the latest indexed element, thus relatively
  96. X    sequential accesses to the elements in a list will not be slow.
  97. X
  98. X    Lists can be searched for particular values by using the 'search'
  99. X    and 'rsearch' functions.  They return the element number of the
  100. X    found value (zero based), or null if the value does not exist in
  101. X    the list.
  102. SHAR_EOF
  103. chmod 0644 calc2.9.0/help/list || echo "restore of calc2.9.0/help/list fails"
  104. set `wc -c calc2.9.0/help/list`;Sum=$1
  105. if test "$Sum" != "1880"
  106. then echo original size 1880, current size $Sum;fi
  107. echo "x - extracting calc2.9.0/help/mat (Text)"
  108. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/mat &&
  109. XUsing matrices
  110. X
  111. X    Matrices can have from 1 to 4 dimensions, and are indexed by a
  112. X    normal-sized integer.  The lower and upper bounds of a matrix can
  113. X    be specified at runtime.  The elements of a matrix are defaulted
  114. X    to zeroes, but can be assigned to be of any type.  Thus matrices
  115. X    can hold complex numbers, strings, objects, etc.  Matrices are
  116. X    stored in memory as an array so that random access to the elements
  117. X    is easy.
  118. X
  119. X    Matrices are normally indexed using square brackets.  If the matrix
  120. X    is multi-dimensional, then an element can be indexed either by
  121. X    using multiple pairs of square brackets (as in C), or else by
  122. X    separating the indexes by commas.  Thus the following two statements
  123. X    reference the same matrix element:
  124. X
  125. X        x = name[3][5];
  126. X        x = name[3,5];
  127. X
  128. X    The double-square bracket operator can be used on any matrix to
  129. X    make references to the elements easy and efficient.  This operator
  130. X    bypasses the normal indexing mechanism, and treats the array as if
  131. X    it was one-dimensional and with a lower bound of zero.  In this
  132. X    indexing mode, elements correspond to the normal indexing mode where
  133. X    the rightmost index increases most frequently.  For example, when
  134. X    using double-square bracket indexing on a two-dimensional matrix,
  135. X    increasing indexes will reference the matrix elements left to right,
  136. X    row by row.  Thus in the following example, 'x' and 'y' are copied
  137. X    from the same matrix element:
  138. X
  139. X        mat m[1:2, 1:3];
  140. X        x = m[2,1];
  141. X        y = m[[3]];
  142. X
  143. X    There are functions which return information about a matrix.
  144. X    The 'size' functions returns the total number of elements.
  145. X    The 'matdim', 'matmin', and 'matmax' functions return the number
  146. X    of dimensions of a matrix, and the lower and upper index bounds
  147. X    for a dimension of a matrix.  For square matrices, the 'det'
  148. X    function calculates the determinant of the matrix.
  149. X
  150. X    Some functions return matrices as their results.  These    functions
  151. X    do not affect the original matrix argument, but instead return
  152. X    new matrices.  For example, the 'mattrans' function returns the
  153. X    transpose of a matrix, and 'inverse' returns the inverse of a
  154. X    matrix.  So to invert a matrix called 'x', you could use:
  155. X
  156. X        x = inverse(x);
  157. X
  158. X    The 'matfill' function fills all elements of a matrix with the
  159. X    specified value, and optionally fills the diagonal elements of a
  160. X    square matrix with a different value.  For example:
  161. X
  162. X        matfill(x,1);
  163. X
  164. X    will fill any matrix with ones, and:
  165. X
  166. X        matfill(x, 0, 1);
  167. X
  168. X    will create an identity matrix out of any square matrix.  Note that
  169. X    unlike most matrix functions, this function does not return a matrix
  170. X    value, but manipulates the matrix argument itself.
  171. X
  172. X    Matrices can be multiplied by numbers, which multiplies each element
  173. X    by the number.  Matrices can also be negated, conjugated, shifted,
  174. X    rounded, truncated, fraction'ed, and modulo'ed.  Each of these
  175. X    operations is applied to each element.
  176. X
  177. X    Matrices can be added or multiplied together if the operation is
  178. X    legal.  Note that even if the dimensions of matrices are compatible,
  179. X    operations can still fail because of mismatched lower bounds.  The
  180. X    lower bounds of two matrices must either match, or else one of them
  181. X    must have a lower bound of zero.  Thus the following code:
  182. X
  183. X        mat x[3:3];
  184. X        mat y[4:4];
  185. X        z = x + y;
  186. X
  187. X    fails because the calculator does not have a way of knowing what
  188. X    the bounds should be on the resulting matrix.  If the bounds match,
  189. X    then the resulting matrix has the same bounds.  If exactly one of
  190. X    the lower bounds is zero, then the resulting matrix will have the
  191. X    nonzero lower bounds.  Thus means that the bounds of a matrix are
  192. X    preserved when operated on by matrices with lower bounds of zero.
  193. X    For example:
  194. X
  195. X        mat x[3:7];
  196. X        mat y[5];
  197. X        z = x + y;
  198. X
  199. X    will succeed and assign the variable 'z' a matrix whose
  200. X    bounds are 3-7.
  201. X
  202. X    Vectors are matrices of only a single dimension.  The 'dp' and 'cp'
  203. X    functions calculate the dot product and cross product of a vector
  204. X    (cross product is only defined for vectors of size 3).
  205. X
  206. X    Matrices can be searched for particular values by using the 'search'
  207. X    and 'rsearch' functions.  They return the element number of the
  208. X    found value (zero based), or null if the value does not exist in the
  209. X    matrix.  Using the element number in double-bracket indexing will
  210. X    then refer to the found element.
  211. SHAR_EOF
  212. chmod 0644 calc2.9.0/help/mat || echo "restore of calc2.9.0/help/mat fails"
  213. set `wc -c calc2.9.0/help/mat`;Sum=$1
  214. if test "$Sum" != "4259"
  215. then echo original size 4259, current size $Sum;fi
  216. echo "x - extracting calc2.9.0/help/obj.file (Text)"
  217. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/obj.file &&
  218. XUsing objects
  219. X
  220. X    Objects are user-defined types which are associated with user-
  221. X    defined functions to manipulate them.  Object types are defined
  222. X    similarly to structures in C, and consist of one or more elements.
  223. X    The advantage of an object is that the user-defined routines are
  224. X    automatically called by the calculator for various operations,
  225. X    such as addition, multiplication, and printing.  Thus they can be
  226. X    manipulated by the user as if they were just another kind of number.
  227. X
  228. X    An example object type is "surd", which represents numbers of the form
  229. X
  230. X        a + b*sqrt(D),
  231. X
  232. X    where D is a fixed integer, and 'a' and 'b' are arbitrary rational
  233. X    numbers.  Addition, subtraction, multiplication, and division can be
  234. X    performed on such numbers, and the result can be put unambiguously
  235. X    into the same form.  (Complex numbers are an example of surds, where
  236. X    D is -1.)
  237. X
  238. X    The "obj" statement defines either an object type or an actual
  239. X    variable of that type.  When defining the object type, the names of
  240. X    its elements are specified inside of a pair of braces.  To define
  241. X    the surd object type, the following could be used:
  242. X
  243. X        obj surd {a, b};
  244. X
  245. X    Here a and b are the element names for the two components of the
  246. X    surd object.  An object type can be defined more than once as long
  247. X    as the number of elements and their names are the same.
  248. X
  249. X    When an object is created, the elements are all defined with zero
  250. X    values.  A user-defined routine should be provided which will place
  251. X    useful values in the elements.  For example, for an object of type
  252. X    'surd', a function called 'surd' can be defined to set the two
  253. X    components as follows:
  254. X
  255. X        define surd(a, b)
  256. X        {
  257. X            local x;
  258. X
  259. X            obj surd x;
  260. X            x.a = a;
  261. X            x.b = b;
  262. X            return x;
  263. X        }
  264. X
  265. X    When an operation is attempted for an object, user functions with
  266. X    particular names are automatically called to perform the operation.
  267. X    These names are created by concatenating the object type name and
  268. X    the operation name together with an underscore.  For example, when
  269. X    multiplying two objects of type surd, the function "surd_mul" is
  270. X    called.
  271. X
  272. X    The user function is called with the necessary arguments for that
  273. X    operation.  For example, for "surd_mul", there are two arguments,
  274. X    which are the two numbers.  The order of the arguments is always
  275. X    the order of the binary operands.  If only one of the operands to
  276. X    a binary operator is an object, then the user function for that
  277. X    object type is still called.  If the two operands are of different
  278. X    object types, then the user function that is called is the one for
  279. X    the first operand.
  280. X
  281. X    The above rules mean that for full generality, user functions
  282. X    should detect that one of their arguments is not of its own object
  283. X    type by using the 'istype' function, and then handle these cases
  284. X    specially.  In this way, users can mix normal numbers with object
  285. X    types.  (Functions which only have one operand don't have to worry
  286. X    about this.)  The following example of "surd_mul" demonstrates how
  287. X    to handle regular numbers when used together with surds:
  288. X
  289. X        define surd_mul(a, b)
  290. X        {
  291. X            local x;
  292. X
  293. X            obj surd x;
  294. X            if (!istype(a, x)) {    
  295. X                /* a not of type surd */
  296. X                x.a = b.a * a;
  297. X                x.b = b.b * a;
  298. X            } else if (!istype(b, x)) {
  299. X                /* b not of type surd */
  300. X                x.a = a.a * b;
  301. X                x.b = a.b * b;
  302. X            } else {            
  303. X                /* both are surds */
  304. X                x.a = a.a * b.a + D * a.b * b.b;
  305. X                x.b = a.a * b.b + a.b * b.a;
  306. X            }
  307. X            if (x.b == 0)
  308. X                return x.a;    /* normal number */
  309. X            return x;        /* return surd */
  310. X        }
  311. X
  312. X    In order to print the value of an object nicely, a user defined
  313. X    routine can be provided.  For small amounts of output, the print
  314. X    routine should not print a newline.  Also, it is most convenient
  315. X    if the printed object looks like the call to the creation routine.
  316. X    For output to be correctly collected within nested output calls,
  317. X    output should only go to stdout.  This means use the 'print'
  318. X    statement, the 'printf' function, or the 'fprintf' function with
  319. X    'files(1)' as the output file.  For example, for the "surd" object:
  320. X
  321. X        define surd_print(a)
  322. X        {
  323. X            print "surd(" : a.a : "," : a.b : ")" : ;
  324. X        }
  325. X
  326. X    It is not necessary to provide routines for all possible operations
  327. X    for an object, if those operations can be defaulted or do not make
  328. X    sense for the object.  The calculator will attempt meaningful
  329. X    defaults for many operations if they are not defined.  For example,
  330. X    if 'surd_square' is not defined to square a number, then 'surd_mul'
  331. X    will be called to perform the squaring.  When a default is not
  332. X    possible, then an error will be generated.
  333. X
  334. X    Please note: Arguments to object functions are always passed by
  335. X    reference (as if an '&' was specified for each variable in the call).
  336. X    Therefore, the function should not modify the parameters, but should
  337. X    copy them into local variables before modifying them.  This is done
  338. X    in order to make object calls quicker in general.
  339. X
  340. X    The double-bracket operator can be used to reference the elements
  341. X    of any object in a generic manner.  When this is done, index 0
  342. X    corresponds to the first element name, index 1 to the second name,
  343. X    and so on.  The 'size' function will return the number of elements
  344. X    in an object.
  345. X
  346. X    The following is a list of the operations possible for objects.
  347. X    The 'xx' in each function name is replaced with the actual object
  348. X    type name.  This table is displayed by the 'show objfuncs' command.
  349. X
  350. X        Name    Args    Comments
  351. X
  352. X        xx_print    1    print value, default prints elements
  353. X        xx_one      1    multiplicative identity, default is 1
  354. X        xx_test     1    logical test (false,true => 0,1), 
  355. X                    default tests elements
  356. X        xx_add      2    
  357. X        xx_sub      2    subtraction, default adds negative
  358. X        xx_neg      1    negative
  359. X        xx_mul      2    
  360. X        xx_div      2    non-integral division, default multiplies 
  361. X                    by inverse
  362. X        xx_inv      1    multiplicative inverse
  363. X        xx_abs      2    absolute value within given error
  364. X        xx_norm     1    square of absolute value
  365. X        xx_conj     1    conjugate
  366. X        xx_pow      2    integer power, default does multiply, 
  367. X                    square, inverse
  368. X        xx_sgn      1    sign of value (-1, 0, 1)
  369. X        xx_cmp      2    equality (equal,non-equal => 0,1), 
  370. X                    default tests elements
  371. X        xx_rel      2    inequality (less,equal,greater => -1,0,1)
  372. X        xx_quo      2    integer quotient
  373. X        xx_mod      2    remainder of division
  374. X        xx_int      1    integer part
  375. X        xx_frac     1    fractional part
  376. X        xx_inc      1    increment, default adds 1
  377. X        xx_dec      1    decrement, default subtracts 1
  378. X        xx_square   1    default multiplies by itself
  379. X        xx_scale    2    multiply by power of 2
  380. X        xx_shift    2    shift left by n bits (right if negative)
  381. X        xx_round    2    round to given number of decimal places
  382. X        xx_bround   2    round to given number of binary places
  383. X        xx_root     3    root of value within given error
  384. X        xx_sqrt     2    square root within given error
  385. X
  386. X
  387. X    Also see the library files:
  388. X
  389. X        dms.cal
  390. X        mod.cal
  391. X        poly.cal
  392. X        quat.cal
  393. X        surd.cal
  394. SHAR_EOF
  395. chmod 0644 calc2.9.0/help/obj.file || echo "restore of calc2.9.0/help/obj.file fails"
  396. set `wc -c calc2.9.0/help/obj.file`;Sum=$1
  397. if test "$Sum" != "6792"
  398. then echo original size 6792, current size $Sum;fi
  399. echo "x - extracting calc2.9.0/help/operator (Text)"
  400. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/operator &&
  401. XOperators
  402. X
  403. X    The operators are similar to C, but the precedence of most of
  404. X    the operators differs.  In addition, there are several additional
  405. X    operators, and some C operators are missing.  The following list
  406. X    gives the operators arranged in order of precedence, from the
  407. X    least tightly binding to the most tightly binding.
  408. X
  409. X
  410. X    ,    Comma operator.
  411. X        For situations in which a comma is used for another purpose
  412. X        (function arguments, array indexing, and the print statement),
  413. X        parenthesis must be used around the comma operator.
  414. X
  415. X    a?:b:c    Conditional value.
  416. X        The test for 'a' is identical to an if test.
  417. X
  418. X    =  +=  -=  *=  /=  %=  //=  &=  |=  <<=  >>=  ^=  **=
  419. X        Assignments.
  420. X
  421. X    ||    Conditional OR.
  422. X        Unlike C, the result is the first non-zero expression or 0,
  423. X        instead of just 0 or 1.
  424. X
  425. X    &&    Conditional AND.
  426. X        Unlike C, the result is the last expression or 0,
  427. X        instead of just 0 or 1.
  428. X
  429. X    ==  !=  <=  >=  <  >
  430. X        Relations.
  431. X
  432. X    +  -
  433. X        Binary plus and minus.
  434. X
  435. X    *  /  //  %
  436. X        Multiply, divide. and modulo.
  437. X        Please Note: The '/' operator is a fractional divide,
  438. X        whereas the '//' is an integral divide.  Thus think of '/'
  439. X        as division of real numbers, and think of '//' as division
  440. X        of integers (e.g., 8 / 3 is 8/3 whereas 8 // 3 is 2).
  441. X        The '%' is integral or fractional modulus (e.g., 11%4 is 3,
  442. X        and 10%pi() is ~.575222).
  443. X
  444. X    |    Logical OR.
  445. X        The signs of numbers do not affect the bit value.
  446. X
  447. X    &    Logical AND.
  448. X        The signs of numbers do not affect the bit value.
  449. X
  450. X    ^  **  <<  >>
  451. X        Powers and shifts.
  452. X        The '^' and '**' are both exponentiation (e.g., 2^3 is 8).
  453. X        The signs of numbers do not affect the bit values of shifts.
  454. X        These operators associate rightward (e.g., 1<<3^2 is 512).
  455. X
  456. X    +  -  !
  457. X        Unary operators.
  458. X        The '!' is the logical NOT operator.  Be careful about
  459. X        using this as the first character of a top level command,
  460. X        since it is also used for executing shell commands.
  461. X
  462. X    ++  --
  463. X        Pre or post indexing.
  464. X        These are applicable only to variables.
  465. X
  466. X    [ ]  [[ ]]  .  ( )
  467. X        Indexing, double-bracket indexing, element references,
  468. X        and function calls.  Indexing can only be applied to matrices,
  469. X        element references can only be applied to objects, but
  470. X        double-bracket indexing can be applied to matrices, objects,
  471. X        or lists.
  472. X
  473. X    variables  constants  .  ( )
  474. X        These are variable names and constants, the special '.' symbol,
  475. X        or a parenthesized expression.  Variable names begin with a
  476. X        letter, but then can contain letters, digits, or underscores.
  477. X        Constants are numbers in various formats, or strings inside
  478. X        either single or double quote marks.
  479. SHAR_EOF
  480. chmod 0644 calc2.9.0/help/operator || echo "restore of calc2.9.0/help/operator fails"
  481. set `wc -c calc2.9.0/help/operator`;Sum=$1
  482. if test "$Sum" != "2550"
  483. then echo original size 2550, current size $Sum;fi
  484. echo "x - extracting calc2.9.0/help/overview (Text)"
  485. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/overview &&
  486. X            CALC - An arbitrary precision calculator.
  487. X                by David I. Bell
  488. X
  489. X
  490. X    This is a calculator program with arbitrary precision arithmetic.
  491. X    All numbers are represented as fractions with arbitrarily large
  492. X    numerators and denominators which are always reduced to lowest terms.
  493. X    Real or exponential format numbers can be input and are converted
  494. X    to the equivalent fraction.  Hex, binary, or octal numbers can be
  495. X    input by using numbers with leading '0x', '0b' or '0' characters.
  496. X    Complex numbers can be input using a trailing 'i', as in '2+3i'.
  497. X    Strings and characters are input by using single or double quotes.
  498. X
  499. X    Commands are statements in a C-like language, where each input
  500. X    line is treated as the body of a procedure.  Thus the command
  501. X    line can contain variable declarations, expressions, labels,
  502. X    conditional tests, and loops.  Assignments to any variable name
  503. X    will automatically define that name as a global variable.  The
  504. X    other important thing to know is that all non-assignment expressions
  505. X    which are evaluated are automatically printed.  Thus, you can evaluate 
  506. X    an expression's value by simply typing it in.
  507. X
  508. X    Many useful built-in mathematical functions are available.  Use
  509. X    the 'show builtins' command to list them.  You can also define
  510. X    your own functions by using the 'define' keyword, followed by a
  511. X    function declaration very similar to C.  Functions which only
  512. X    need to return a simple expression can be defined using an
  513. X    equals sign, as in the example 'define sc(a,b) = a^3 + b^3'.
  514. X    Variables in functions can be defined as either 'global', 'local',
  515. X    or 'static'.  Global variables are common to all functions and the
  516. X    command line, whereas local variables are unique to each function
  517. X    level, and are destroyed when the function returns.  Static variables
  518. X    are scoped within single input files, or within functions, and are
  519. X    never destroyed.  Variables are not typed at definition time, but
  520. X    dynamically change as they are used.  So you must supply the correct
  521. X    type of variable to those functions and operators which only work
  522. X    for a subset of types.
  523. X
  524. X    By default, arguments to functions are passed by value (even
  525. X    matrices).  For speed, you can put an ampersand before any
  526. X    variable argument in a function call, and that variable will be
  527. X    passed by reference instead.  However, if the function changes
  528. X    its argument, the variable will change.  Arguments to built-in
  529. X    functions and object manipulation functions are always called
  530. X    by reference.  If a user-defined function takes more arguments
  531. X    than are passed, the undefined arguments have the null value.
  532. X    The 'param' function returns function arguments by argument
  533. X    number, and also returns the number of arguments passed.  Thus
  534. X    functions can be written to handle an arbitrary number of
  535. X    arguments.
  536. X
  537. X    The mat statement is used to create a matrix.  It takes a
  538. X    variable name, followed by the bounds of the matrix in square
  539. X    brackets.  The lower bounds are zero by default, but colons can
  540. X    be used to change them.  For example 'mat foo[3, 1:10]' defines
  541. X    a two dimensional matrix, with the first index ranging from 0
  542. X    to 3, and the second index ranging from 1 to 10.  The bounds of
  543. X    a matrix can be an expression calculated at runtime.
  544. X
  545. X    Lists of values are created using the 'list' function, and values can
  546. X    be inserted or removed from either the front or the end of the list.
  547. X    List elements can be indexed directly using double square brackets.
  548. X
  549. X    The obj statement is used to create an object.  Objects are
  550. X    user-defined values for which user-defined routines are
  551. X    implicitly called to perform simple actions such as add,
  552. X    multiply, compare, and print. Objects types are defined as in
  553. X    the example 'obj complex {real, imag}', where 'complex' is the
  554. X    name of the object type, and 'real' and 'imag' are element
  555. X    names used to define the value of the object (very much like
  556. X    structures).  Variables of an object type are created as in the
  557. X    example 'obj complex x,y', where 'x' and 'y' are variables.
  558. X    The elements of an object are referenced using a dot, as in the
  559. X    example 'x.real'. All user-defined routines have names composed
  560. X    of the object type and the action to perform separated by an
  561. X    underscore, as in the example 'complex_add'.  The command 'show
  562. X    objfuncs' lists all the definable routines.  Object routines
  563. X    which accept two arguments should be prepared to handle cases
  564. X    in which either one of the arguments is not of the expected
  565. X    object type.
  566. X
  567. X    These are the differences between the normal C operators and
  568. X    the ones defined by the calculator.  The '/' operator divides
  569. X    fractions, so that '7 / 2' evaluates to 7/2. The '//' operator
  570. X    is an integer divide, so that '7 // 2' evaluates to 3.  The '^'
  571. X    operator is a integral power function, so that 3^4 evaluates to
  572. X    81.  Matrices of any dimension can be treated as a zero based
  573. X    linear array using double square brackets, as in 'foo[[3]]'.
  574. X    Matrices can be indexed by using commas between the indices, as
  575. X    in foo[3,4].  Object and list elements can be referenced by
  576. X    using double square brackets.
  577. X
  578. X    The print statement is used to print values of expressions.
  579. X    Separating values by a comma puts one space between the output
  580. X    values, whereas separating values by a colon concatenates the
  581. X    output values.  A trailing colon suppresses printing of the end
  582. X    of line.  An example of printing is 'print \"The square of\",
  583. X    x, \"is\", x^2\'.
  584. X
  585. X    The 'config' function is used to modify certain parameters that
  586. X    affect calculations or the display of values.  For example, the
  587. X    output display mode can be set using 'config(\"mode\", type)',
  588. X    where 'type' is one of 'frac', 'int', 'real', 'exp', 'hex',
  589. X    'oct', or 'bin'.  The default output mode is real.  For the
  590. X    integer, real, or exponential formats, a leading '~' indicates
  591. X    that the number was truncated to the number of decimal places
  592. X    specified by the default precision.  If the '~' does not
  593. X    appear, then the displayed number is the exact value.
  594. X
  595. X    The number of decimal places printed is set by using
  596. X    'config(\"display\", n)'.  The default precision for
  597. X    real-valued functions can be set by using 'epsilon(x)', where x
  598. X    is the required precision (such as 1e-50).
  599. X
  600. X    There is a command stack feature so that you can easily
  601. X    re-execute previous commands and expressions from the terminal.
  602. X    You can also edit the current command before it is completed.
  603. X    Both of these features use emacs-like commands.
  604. X
  605. X    Files can be read in by using the 'read filename' command.
  606. X    These can contain both functions to be defined, and expressions
  607. X    to be calculated.  Global variables which are numbers can be
  608. X    saved to a file by using the 'write filename' command.
  609. SHAR_EOF
  610. chmod 0644 calc2.9.0/help/overview || echo "restore of calc2.9.0/help/overview fails"
  611. set `wc -c calc2.9.0/help/overview`;Sum=$1
  612. if test "$Sum" != "6614"
  613. then echo original size 6614, current size $Sum;fi
  614. echo "x - extracting calc2.9.0/help/statement (Text)"
  615. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/statement &&
  616. XStatements
  617. X
  618. X    Statements are very much like C statements.  Most statements act
  619. X    identically to those in C, but there are minor differences and
  620. X    some additions.  The following is a list of the statement types,
  621. X    with explanation of the non-C statements.  In this list, upper
  622. X    case words identify the keywords which are actually in lower case.
  623. X    Statements are generally terminated with semicolons, except if the
  624. X    statement is the compound one formed by matching braces.  Various
  625. X    expressions are optional and may be omitted (as in RETURN).
  626. X
  627. X
  628. X    NOTE: Calc commands are in lower case.   UPPER case is used below
  629. X          for emphasis only, and should be considered in lower case.
  630. X
  631. X
  632. X    IF (expr) statement
  633. X    IF (expr) statement ELSE statement
  634. X    FOR (optionalexpr ; optionalexpr ; optionalexpr) statement
  635. X    WHILE (expr) statement
  636. X    DO statement WHILE (expr)
  637. X    CONTINUE
  638. X    BREAK
  639. X    GOTO label
  640. X        These all work like in normal C.
  641. X
  642. X    RETURN optionalexpr
  643. X        This returns a value from a function.  Functions always
  644. X        have a return value, even if this statement is not used.
  645. X        If no return statement is executed, or if no expression
  646. X        is specified in the return statement, then the return
  647. X        value from the function is the null type.
  648. X
  649. X    SWITCH (expr) { caseclauses }
  650. X        Switch statements work similarly to C, except for the
  651. X        following.  A switch can be done on any type of value,
  652. X        and the case statements can be of any type of values.
  653. X        The case statements can also be expressions calculated
  654. X        at runtime.  The calculator compares the switch value
  655. X        with each case statement in the order specified, and
  656. X        selects the first case which matches.  The default case
  657. X        is the exception, and only matches once all other cases
  658. X        have been tested.
  659. X
  660. X    { statements }
  661. X        This is a normal list of statements, each one ended by
  662. X        a semicolon.  Unlike the C language, no declarations are
  663. X        permitted within an inner-level compound statement.
  664. X        Declarations are only permitted at the beginning of a
  665. X        function definition, or at the beginning of an expression
  666. X        sequence.
  667. X
  668. X    MAT variable [dimension] [dimension] ...
  669. X    MAT variable [dimension, dimension, ...]
  670. X    MAT variable [] = { value, ... }
  671. X        This creates a matrix variable with the specified dimensions.
  672. X        Matrices can have from 1 to 4 dimensions.  When specifying
  673. X        multiple dimensions, you can use either the standard C syntax,
  674. X        or else you can use commas for separating the dimensions.
  675. X        For example, the following two statements are equivalent,
  676. X        and so will create the same two dimensional matrix:
  677. X
  678. X            mat foo[3][6];
  679. X            mat foo[3,6];
  680. X
  681. X        By default, each dimension is indexed starting at zero,
  682. X        as in normal C, and contains the specified number of
  683. X        elements.  However, this can be changed if a colon is
  684. X        used to separate two values.  If this is done, then the
  685. X        two values become the lower and upper bounds for indexing.
  686. X        This is convenient, for example, to create matrices whose
  687. X        first row and column begin at 1.  Examples of matrix
  688. X        definitions are:
  689. X
  690. X            mat x[3]    one dimension, bounds are 0-2
  691. X            mat foo[4][5]    two dimensions, bounds are 0-3 and 0-4
  692. X            mat a[-7:7]    one dimension, bounds are (-7)-7
  693. X            mat s[1:9,1:9]    two dimensions, bounds are 1-9 and 1-9
  694. X
  695. X        Note that the MAT statement is not a declaration, but is
  696. X        executed at runtime.  Within a function, the specified
  697. X        variable must already be defined, and is just converted to
  698. X        a matrix of the specified size, and all elements are set
  699. X        to the value of zero.  For convenience, at the top level
  700. X        command level, the MAT command automatically defines a
  701. X        global variable of the specified name if necessary.
  702. X
  703. X        Since the MAT statement is executed, the bounds on the
  704. X        matrix can be full expressions, and so matrices can be
  705. X        dynamically allocated.  For example:
  706. X
  707. X            size = 20;
  708. X            mat data[size*2];
  709. X
  710. X        allocates a matrix which can be indexed from 0 to 39.
  711. X
  712. X        Initial values for the elements of a matrix can be specified
  713. X        by following the bounds information with an equals sign and
  714. X        then a list of values enclosed in a pair of braces.  Even if
  715. X        the matrix has more than one dimension, the elements must be
  716. X        specified as a linear list.  If too few values are specified,
  717. X        the remaining values are set to zero.  If too many values are
  718. X        specified, a runtime error will result.  Examples of some
  719. X        initializations are:
  720. X
  721. X            mat table1[5] = {77, 44, 22};
  722. X            mat table2[2,2] = {1, 2, 3, 4};
  723. X
  724. X        When an initialization is done, the bounds of the matrix
  725. X        can optionally be left out of the square brackets, and the
  726. X        correct bounds (zero based) will be set.  This can only be
  727. X        done for one-dimensional matrices.  An example of this is:
  728. X
  729. X            mat fred[] = {99, 98, 97};
  730. X
  731. X        The MAT statement can also be used in declarations to set
  732. X        variables as being matrices from the beginning.  For example:
  733. X
  734. X            local mat temp[5];
  735. X            static mat strtable[] = {"hi", "there", "folks");
  736. X
  737. X    OBJ type { elementnames } optionalvariables
  738. X    OBJ type variable
  739. X
  740. X        These create a new object type, or create one or more
  741. X        variables of the specified type.  For this calculator,
  742. X        an object is just a structure which is implicitly acted
  743. X        on by user defined routines.  The user defined routines
  744. X        implement common operations for the object, such as plus
  745. X        and minus, multiply and divide, comparison and printing.
  746. X        The calculator will automatically call these routines in
  747. X        order to perform many operations.
  748. X    
  749. X        To create an object type, the data elements used in
  750. X        implementing the object are specified within a pair
  751. X        of braces, separated with commas.  For example, to
  752. X        define an object will will represent points in 3-space,
  753. X        whose elements are the three coordinate values, the
  754. X        following could be used:
  755. X    
  756. X            obj point {x, y, z};
  757. X    
  758. X        This defines an object type called point, whose elements
  759. X        have the names x, y, and z.  The elements are accessed
  760. X        similarly to structure element accesses, by using a period.
  761. X        For example, given a variable 'v' which is a point object,
  762. X        the three coordinates of the point can be referenced by:
  763. X
  764. X            v.x
  765. X            v.y
  766. X            v.z
  767. X
  768. X        A particular object type can only be defined once, and
  769. X        is global throughout all functions.  However, different
  770. X        object types can be used at the same time.
  771. X
  772. X        In order to create variables of an object type, they
  773. X        can either be named after the right brace of the object
  774. X        creation statement, or else can be defined later with
  775. X        another obj statement.  To create two points using the
  776. X        second (and most common) method, the following is used:
  777. X
  778. X            obj point p1, p2;    
  779. X
  780. X        This statement is executed, and is not a declaration.
  781. X        Thus within a function, the variables p1 and p2 must have
  782. X        been previously defined, and are just changed to be the
  783. X        new object type.  For convenience, at the top level command
  784. X        level, object variables are automatically defined as being
  785. X        global when necessary.
  786. X
  787. X        Initial values for an object can be specified by following
  788. X        the variable name by an equals sign and a list of values
  789. X        enclosed in a pair of braces.  For example:
  790. X
  791. X            obj point pt = {5, 6};
  792. X
  793. X        The OBJ statement can also be used in declarations to set
  794. X        variables as being objects from the beginning.  If multiple
  795. X        variables are specified, then each one is defined as the
  796. X        specified object type.  Examples of declarations are:
  797. X
  798. X            local obj point temp1;
  799. X            static obj point temp2 = {4, 3};
  800. X            global obj point p1, p2, p3;
  801. X
  802. X    EXIT string
  803. X    QUIT string
  804. X
  805. X        This command is used in two cases.  At the top command
  806. X        line level, quit will exit from the calculator.  This
  807. X        is the normal way to leave the calculator.  In any other
  808. X        use, quit will abort the current calculation as if an
  809. X        error had occurred.  If a string is given, then the string
  810. X        is printed as the reason for quitting, otherwise a general
  811. X        quit message is printed.  The routine name and line number
  812. X        which executed the quit is also printed in either case.
  813. X
  814. X        Quit is useful when a routine detects invalid arguments,
  815. X        in order to stop a calculation cleanly.  For example,
  816. X        for a square root routine, an error can be given if the
  817. X        supplied parameter was a negative number, as in:
  818. X
  819. X            define mysqrt(n)
  820. X            {
  821. X                if (n < 0)
  822. X                    quit "Negative argument";
  823. X                ...
  824. X            }
  825. X
  826. X        Exit is an alias for quit.
  827. X
  828. X
  829. X    PRINT exprs
  830. X
  831. X        For interactive expression evaluation, the values of all
  832. X        typed-in expressions are automatically displayed to the
  833. X        user.  However, within a function or loop, the printing of
  834. X        results must be done explicitly.  This can be done using
  835. X        the 'printf' or 'fprintf' functions, as in standard C, or
  836. X        else by using the built-in 'print' statement.  The advantage
  837. X        of the print statement is that a format string is not needed.
  838. X        Instead, the given values are simply printed with zero or one
  839. X        spaces between each value.
  840. X
  841. X        Print accepts a list of expressions, separated either by
  842. X        commas or colons.  Each expression is evaluated in order
  843. X        and printed, with no other output, except for the following
  844. X        special cases.  The comma which separates expressions prints
  845. X        a single space, and a newline is printed after the last
  846. X        expression unless the statement ends with a colon.  As
  847. X        examples:
  848. X
  849. X            print 3, 4;        prints "3 4" and newline.
  850. X            print 5:;        prints "5" with no newline.
  851. X            print 'a' : 'b' , 'c';    prints "ab c" and newline.
  852. X            print;            prints a newline.
  853. X
  854. X        For numeric values, the format of the number depends on the
  855. X        current "mode" configuration parameter.  The initial mode
  856. X        is to print real numbers, but it can be changed to other
  857. X        modes such as exponential, decimal fractions, or hex.
  858. X
  859. X        If a matrix or list is printed, then the elements contained
  860. X        within the matrix or list will also be printed, up to the
  861. X        maximum number specified by the "maxprint" configuration
  862. X        parameter.  If an element is also a matrix or a list, then
  863. X        their values are not recursively printed.  Objects are printed
  864. X        using their user-defined routine.  Printing a file value
  865. X        prints the name of the file that was opened.
  866. X
  867. X
  868. X    SHOW item
  869. X
  870. X        This command displays some information.
  871. X        The following is a list of the various items:
  872. X
  873. X            builtins    built in functions
  874. X            globals        global variables
  875. X            functions    user-defined functions
  876. X            objfuncs    possible object functions
  877. X            memory        memory usage
  878. X    
  879. X
  880. X    Also see the help topic:
  881. X
  882. X        command         top level commands
  883. SHAR_EOF
  884. chmod 0644 calc2.9.0/help/statement || echo "restore of calc2.9.0/help/statement fails"
  885. set `wc -c calc2.9.0/help/statement`;Sum=$1
  886. if test "$Sum" != "10197"
  887. then echo original size 10197, current size $Sum;fi
  888. echo "x - extracting calc2.9.0/help/todo (Text)"
  889. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/todo &&
  890. XNeeded enhancements
  891. X
  892. X    Send calc comments, suggestions, bug fixes, enhancements and
  893. X    interesting calc scripts that you would like you see included in
  894. X    future distributions to:
  895. X
  896. X        dbell@canb.auug.org.au
  897. X        chongo@toad.com
  898. X
  899. X    The following items are in the calc wish list.  Programs like this
  900. X    can be extended and improved forever.
  901. X
  902. X    *  Implement an autoload feature.  Associate a calc library filename
  903. X       with a function or global variable.  On the first reference of
  904. X       such item, perform an automatic load of that file.
  905. X
  906. X    *  Use faster multiply and divide algorithms for large numbers.
  907. X
  908. X    *  Add error handling statements, so that QUITs, errors from the 
  909. X       'eval' function, division by zeroes, and so on can be caught.
  910. X       This should be done using syntax similar to:
  911. X
  912. X            ONERROR statement DO statement;
  913. X
  914. X       Something like signal isn't versatile enough.
  915. X
  916. X    *  Add a debugging capability so that functions can be single stepped,
  917. X       breakpoints inserted, variables displayed, and so on.
  918. X
  919. X    *  Figure out how to write all variables out to a file, including
  920. X       deeply nested arrays, lists, and objects.
  921. X
  922. X    *  Implement pointers.
  923. X
  924. X    *  Eliminate the need for the define keyword by doing smarter parsing.
  925. X
  926. X    *  Allow results of a command (or all commands) to be re-directed to a 
  927. X       file or piped into a command.
  928. X
  929. X    *  Add some kind of #include and #define facility.  Perhaps use
  930. X       the C pre-processor itself?
  931. X
  932. X    *  Allow one to undefine anything.  Allow one to test if anything
  933. X       is defined.
  934. X
  935. X    *  Support a more general input and output base mode other than
  936. X       just dec, hex or octal.
  937. X
  938. X    *  Allow support of POSIX bc via a translator reads bc commands, 
  939. X       converts it to calc and pipes it into calc.
  940. X
  941. X    *  Implement a form of symbolic algebra.  Work on this has already
  942. X       begun.  This will use backquotes to define expressions, and new
  943. X       functions will be able to act on expressions.  For example:
  944. X
  945. X           x = `hello * strlen(mom)`;
  946. X        x = sub(x, `hello`, `hello + 1`);
  947. X        x = sub(x, `hello`, 10, `mom`, "curds");
  948. X        eval(x);
  949. X
  950. X       prints 55.
  951. X
  952. X    *  Place the results of previous commands into a parallel history list.
  953. X       Add a binding that returns the saved result of the command so
  954. X       that one does not need to re-execute a previous command simply
  955. X       to obtain its value.
  956. X
  957. X       If you have a command that takes a very long time to execute,
  958. X       it would be nice if you could get at its result without having
  959. X       to spend the time to reexecute it.
  960. X
  961. X    *  Add a binding to delete a value from the history list.
  962. X
  963. X       One may need to remove a large value from the history list if
  964. X       it is very large.  Deleting the value would replace the history
  965. X       entry with a null value.
  966. X
  967. X    *  Add a binding to delete a command from the history list.
  968. X
  969. X       Since you can delete values, you might as well be able to
  970. X       delete commands.
  971. X
  972. X    *  All one to alter the size of the history list thru config().
  973. X
  974. X       In some cases, 256 values is too small, in others it is too large.
  975. X
  976. X    *  Add a builtin that returns a value from the history list.
  977. X       As an example:
  978. X
  979. X        histval(-10)
  980. X    
  981. X       returns the 10th value on the history value list, if such 
  982. X       a value is in the history list (null otherwise).  And:
  983. X
  984. X        histval(23)
  985. X    
  986. X       return the value of the 23rd command given to calc, if
  987. X       such a value is in the history list (null otherwise).
  988. X
  989. X       It would be very helpful to use the history values in
  990. X       subsequent equations.
  991. X
  992. X    *  Add a builtin that returns command as a string from the
  993. X       history list.  As an example:
  994. X
  995. X        history(-10)
  996. X    
  997. X       returns a string containing the 10th command on the
  998. X       history list, if a such a value is in the history list 
  999. X       (empty string otherwise).  And:
  1000. X
  1001. X        history(23)
  1002. X    
  1003. X       return the string containing the 23rd command given to calc, if
  1004. X       such a value is in the history list (empty string otherwise).
  1005. X
  1006. X       One could use the eval() function to re-evaluate the command.
  1007. X
  1008. X    *  Restore the command number to calc prompts.  When going back
  1009. X       in the history list, indicate the command number that is
  1010. X       being examined.
  1011. X
  1012. X       The command number was a useful item.  When one is scanning the
  1013. X       history list, knowing where you are is hard without it.  It can
  1014. X       get confusing when the history list wraps or when you use
  1015. X       search bindings.  Command numbers would be useful in
  1016. X       conjunction with positive args for the history() and histval()
  1017. X       functions as suggested above.
  1018. X
  1019. X    *  Add a builtin that returns the current command number.
  1020. X       For example:
  1021. X
  1022. X        cmdnum()
  1023. X
  1024. X       returns the current command number.
  1025. X
  1026. X       This would allow one to tag a value in the history list.  One
  1027. X       could save the result of cmdnum() in a variable and later use
  1028. X       it as an arg to the histval() or history() functions.
  1029. X
  1030. X    *  Add a builtin to determine if an object as been defined.
  1031. X       For example:
  1032. X
  1033. X        isobjdef("surd")
  1034. X
  1035. X       would return true if one had previously defined the
  1036. X       surd object.  I.e., if "obj surd {...};" had been
  1037. X       executed.
  1038. X
  1039. X       One cannot redefine an object.  If a script defines an object,
  1040. X       one cannot reload it without getting lots of already defined
  1041. X       errors.  If two scripts needed the same object, both could
  1042. X       define it and use isobjdef() to avoid redefinition problems.
  1043. X
  1044. X    *  Add a builtin to determine if a function as been defined.
  1045. X       For example:
  1046. X
  1047. X        isfunct("foo")
  1048. X
  1049. X       would return true if foo has been defined as a function.
  1050. X
  1051. X    *  Permit one to destroy an object.
  1052. X
  1053. X       What if one does want to redefine an object?  Consider the case
  1054. X       where one it debugging a script and wants to reload it.  If
  1055. X       that script defines an object you are doomed.  Perhaps
  1056. X       destroying a object would undefine all of its related functions
  1057. X       and values?
  1058. X
  1059. X    *  Port calc to a 64 bit machine, or a machine where long was larger
  1060. X       than an int.
  1061. X
  1062. X       There are at least two issues here.  The first is fix places
  1063. X       where calc assumes that an int and a long are the same size.
  1064. X       The second and more important would be to change calc so that
  1065. X       it could be configured to work with a base of 2^32.  (Right now
  1066. X       calc is somewhat wired to use base 2^16).
  1067. X
  1068. X       In other words first make calc 64 bit safe, then increase
  1069. X       performance on 64 bit machines by allowing one to configure
  1070. X       (via the Makefile) calc to use an larger internal base.
  1071. X    
  1072. X    *  One some machines (such as the 486), floating point can be faster 
  1073. X       than integer arithmetic.  Often such floating point would allow
  1074. X       for a larger base than 2^16, allowing calc to run even faster.
  1075. X       Allow calc to take advantage of such hardware.
  1076. X    
  1077. X    *  Add NAN's (Not A Number's) to calc.  Where is it reasonable, change 
  1078. X       calc to process these values in way similar to that of the IEEE 
  1079. X       floating point.
  1080. X    
  1081. X    *  Add a factoring builtin functions.  Provide functions that perform 
  1082. X       multiple polynomial quadratic sieves, elliptic curve, difference 
  1083. X       of two squares, N-1 factoring as so on.  Provide a easy general 
  1084. X       factoring builtin (say factor(foo)) that would attempt to apply
  1085. X       whatever process was needed based on the value.
  1086. X
  1087. X       Factoring builtins would return a matrix of factors.
  1088. X
  1089. X       It would be handy to configure, via config(), the maximum time
  1090. X       that one should try to factor a number.  By default the time
  1091. X       should be infinite.  If one set the time limit to a finite
  1092. X       value and the time limit was exceeded, the factoring builtin
  1093. X       would return whatever if had found thus far, even if no new 
  1094. X       factors had been found.
  1095. X
  1096. X       Another factoring configuration interface, via config(), that
  1097. X       is needed would be to direct the factoring builtins to return
  1098. X       as soon as a factor was found.
  1099. X
  1100. X    *  Allow one to disable, via config, the printing of the leading ~
  1101. X       on truncated numeric values.
  1102. X
  1103. X       Sometimes the leading ~'s are more annoying than helpful.
  1104. X    
  1105. X    *  Allow one to disable, via config, the printing of the leading tab 
  1106. X       when printing the value of a command that one just typed.
  1107. X
  1108. X       Most of the time, the leading tab is reasonable.  Sometimes
  1109. X       it is not.  It would be helpful if one could turn off the
  1110. X       tab in such cases.
  1111. X    
  1112. X    *  Allow one to config calc break up long output lines.
  1113. X
  1114. X       The command:  calc '2^100000'  will produce one very long
  1115. X       line.  Many times this is reasonable.  Long output lines
  1116. X       are a problem for some utilities.  It would be nice if one
  1117. X       could configure, via config(), calc to fold long lines.
  1118. X
  1119. X       By default, calc should continue to produce long lines.
  1120. X
  1121. X       One option to config should be to specify the length to
  1122. X       fold output.  Another option should be to append a trailing
  1123. X       \ on folded lines (as some symbolic packages use).
  1124. X
  1125. X    *  Add scanf() and fscanf() functions.
  1126. X
  1127. X       The scanf function should be able to handle both long lines
  1128. X       and split lines with trailing \'s.  It should also be able
  1129. X       to ignore the leading ~.
  1130. X
  1131. SHAR_EOF
  1132. chmod 0644 calc2.9.0/help/todo || echo "restore of calc2.9.0/help/todo fails"
  1133. set `wc -c calc2.9.0/help/todo`;Sum=$1
  1134. if test "$Sum" != "8781"
  1135. then echo original size 8781, current size $Sum;fi
  1136. echo "x - extracting calc2.9.0/help/types (Text)"
  1137. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/types &&
  1138. XBuiltin types
  1139. X
  1140. X    The calculator has the following built-in types.
  1141. X
  1142. X    null value
  1143. X        This is the undefined value type.  The function 'null'
  1144. X        returns this value.  Functions which do not explicitly
  1145. X        return a value return this type.  If a function is called
  1146. X        with fewer parameters than it is defined for, then the
  1147. X        missing parameters have the null type.  The null value is
  1148. X        false if used in an IF test.
  1149. X
  1150. X    rational numbers
  1151. X        This is the basic data type of the calculator.
  1152. X        These are fractions whose numerators and denominators
  1153. X        can be arbitrarily large.  The fractions are always
  1154. X        in lowest terms.  Integers have a denominator of 1.
  1155. X        The numerator of the number contains the sign, so that
  1156. X        the denominator is always positive.  When a number is
  1157. X        entered in floating point or exponential notation, it is
  1158. X        immediately converted to the appropriate fractional value.
  1159. X        Printing a value as a floating point or exponential value
  1160. X        involves a conversion from the fractional representation.
  1161. X
  1162. X        Numbers are stored in binary format, so that in general,
  1163. X        bit tests and shifts are quicker than multiplies and divides.
  1164. X        Similarly, entering or displaying of numbers in binary,
  1165. X        octal, or hex formats is quicker than in decimal.  The
  1166. X        sign of a number does not affect the bit representation
  1167. X        of a number.
  1168. X
  1169. X    complex numbers
  1170. X        Complex numbers are composed of real and imaginary parts,
  1171. X        which are both fractions as defined above.  An integer which
  1172. X        is followed by an 'i' character is a pure imaginary number.
  1173. X        Complex numbers such as "2+3i" when typed in, are processed
  1174. X        as the sum of a real and pure imaginary number, resulting
  1175. X        in the desired complex number.  Therefore, parenthesis are
  1176. X        sometimes necessary to avoid confusion, as in the two values:
  1177. X
  1178. X            1+2i ^2        (which is -3)
  1179. X            (1+2i) ^2    (which is -3+4i)
  1180. X
  1181. X        Similar care is required when entering fractional complex
  1182. X        numbers.  Note the differences below:
  1183. X
  1184. X            3/4i        (which is -(3/4)i)
  1185. X            3i/4        (which is (3/4)i)
  1186. X
  1187. X        The imaginary unit itself is input using "1i".
  1188. X
  1189. X    strings
  1190. X        Strings are a sequence of zero or more characters.
  1191. X        They are input using either of the single or double
  1192. X        quote characters.  The quote mark which starts the
  1193. X        string also ends it.  Various special characters can
  1194. X        also be inserted using back-slash.  Example strings:
  1195. X
  1196. X            "hello\n"
  1197. X            "that's all"
  1198. X            'lots of """"'
  1199. X            'a'
  1200. X            ""
  1201. X
  1202. X        There is no distinction between single character and
  1203. X        multi-character strings.  The 'str' and 'ord' functions
  1204. X        will convert between a single character string and its
  1205. X        numeric value.  The 'str' and 'eval' functions will
  1206. X        convert between longer strings and the corresponding
  1207. X        numeric value (if legal).  The 'strcat', 'strlen', and
  1208. X        'substr' functions are also useful.
  1209. X
  1210. X    matrices
  1211. X        These are one to four dimensional matrices, whose minimum
  1212. X        and maximum bounds can be specified at runtime.  Unlike C,
  1213. X        the minimum bounds of a matrix do not have to start at 0.
  1214. X        The elements of a matrix can be of any type.  There are
  1215. X        several built-in functions for matrices.  Matrices are
  1216. X        created using the 'mat' statement.
  1217. X
  1218. X    associations
  1219. X        These are one to four dimensional matrices which can be
  1220. X        indexed by arbitrary values, instead of just integers.
  1221. X        These are also known as associative arrays.  The elements of
  1222. X        an association can be of any type.  Very few operations are
  1223. X        permitted on an association except for indexing.  Associations
  1224. X        are created using the 'assoc' function.
  1225. X
  1226. X    lists
  1227. X        These are a sequence of values, which are linked together
  1228. X        so that elements can be easily be inserted or removed
  1229. X        anywhere in the list.  The values can be of any type.
  1230. X        Lists are created using the 'list' function.
  1231. X
  1232. X    files
  1233. X        These are text files opened using stdio.  Files may be opened
  1234. X        for sequential reading, writing, or appending.  Opening a
  1235. X        file using the 'fopen' function returns a value which can
  1236. X        then be used to perform I/O to that file.  File values can
  1237. X        be copied by normal assignments between variables, or by
  1238. X        using the result of the 'files' function.  Such copies are
  1239. X        indistinguishable from each other.
  1240. SHAR_EOF
  1241. chmod 0644 calc2.9.0/help/types || echo "restore of calc2.9.0/help/types fails"
  1242. set `wc -c calc2.9.0/help/types`;Sum=$1
  1243. if test "$Sum" != "4070"
  1244. then echo original size 4070, current size $Sum;fi
  1245. echo "x - extracting calc2.9.0/help/usage (Text)"
  1246. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/usage &&
  1247. XCalc command line
  1248. X
  1249. X    Calc has the following command line:
  1250. X
  1251. X        calc [-h] [-q] [calc_command ...]
  1252. X
  1253. X        -h    print a help message  (equivalent to the
  1254. X            help command)
  1255. X
  1256. X        -q    By default, calc executes each file specified
  1257. X            in the :-separated list found in the environment
  1258. X            variable $CALCRC.  If $CALCRC does not exist,
  1259. X            an internal default is used.
  1260. X
  1261. X    If some calc_commands arguments are given on the command line,
  1262. X    calc executes these commands and then exists.  If no command
  1263. X    line arguments are given, calc prompts and reads commands
  1264. X    from standard input.
  1265. SHAR_EOF
  1266. chmod 0644 calc2.9.0/help/usage || echo "restore of calc2.9.0/help/usage fails"
  1267. set `wc -c calc2.9.0/help/usage`;Sum=$1
  1268. if test "$Sum" != "551"
  1269. then echo original size 551, current size $Sum;fi
  1270. echo "x - extracting calc2.9.0/help/variable (Text)"
  1271. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/variable &&
  1272. XVariable declarations
  1273. X
  1274. X    Variables can be declared as either being global, local, or static.
  1275. X    Global variables are visible to all functions and on the command
  1276. X    line, and are permanent.  Local variables are visible only within
  1277. X    a single function or command sequence.  When the function or command
  1278. X    sequence returns, the local variables are deleted.  Static variables
  1279. X    are permanent like global variables, but are only visible within the
  1280. X    same input file or function where they are defined.
  1281. X
  1282. X    To declare one or more variables, the 'local', 'global', or 'static'
  1283. X    keywords are used, followed by the desired list of variable names,
  1284. X    separated by commas.  The definition is terminated with a semicolon.
  1285. X    Examples of declarations are:
  1286. X
  1287. X        local    x, y, z;
  1288. X        global    fred;
  1289. X        local    foo, bar;
  1290. X        static    var1, var2, var3;
  1291. X
  1292. X    Variables may have initializations applied to them.  This is done
  1293. X    by following the variable name by an equals sign and an expression.
  1294. X    Global and local variables are initialized each time that control
  1295. X    reaches them (e.g., at the entry to a function which contains them).
  1296. X    Static variables are initialized once only, at the time that control
  1297. X    first reaches them (but in future releases the time of initialization
  1298. X    may change).  Unlike in C, expressions for static variables may
  1299. X    contain function calls and refer to variables.  Examples of such
  1300. X    initializations are:
  1301. X
  1302. X        local    a1 = 7, a2 = 3;
  1303. X        static    b = a1 + sin(a2);
  1304. X
  1305. X    Within function declarations, all variables must be defined.
  1306. X    But on the top level command line, assignments automatically define
  1307. X    global variables as needed.  For example, on the top level command
  1308. X    line, the following defines the global variable x if it had not
  1309. X    already been defined:
  1310. X
  1311. X        x = 7
  1312. X
  1313. X    The static keyword may be used at the top level command level to
  1314. X    define a variable which is only accessible interactively, or within
  1315. X    functions defined interactively.
  1316. X
  1317. X    Variables have no fixed type, thus there is no need or way to
  1318. X    specify the types of variables as they are defined.  Instead, the
  1319. X    types of variables change as they are assigned to or are specified
  1320. X    in special statements such as 'mat' and 'obj'.  When a variable is
  1321. X    first defined using 'local', 'global', or 'static', it has the
  1322. X    value of zero.
  1323. X
  1324. X    If a procedure defines a local or static variable name which matches
  1325. X    a global variable name, or has a parameter name which matches a
  1326. X    global variable name, then the local variable or parameter takes
  1327. X    precedence within that procedure, and the global variable is not
  1328. X    directly accessible.
  1329. X
  1330. X    The MAT and OBJ keywords may be used within a declaration statement
  1331. X    in order to initially define variables as that type.  Initialization
  1332. X    of these variables are also allowed.  Examples of such declarations
  1333. X    are:
  1334. X
  1335. X        static mat table[3] = {5, 6, 7};
  1336. X        local obj point p1, p2;
  1337. X
  1338. X    There are no pointers in the calculator language, thus all
  1339. X    arguments to user-defined functions are normally passed by value.
  1340. X    This is true even for matrices, strings, and lists.  In order
  1341. X    to circumvent this, the '&' operator is allowed before a variable
  1342. X    when it is an argument to a function.  When this is done, the
  1343. X    address of the variable is passed to the function instead of its
  1344. X    value.  This is true no matter what the type of the variable is.
  1345. X    This allows for fast calls of functions when the passed variable
  1346. X    is huge (such as a large array).  However, the passed variable can
  1347. X    then be changed by the function if the parameter is assigned into.
  1348. X    The function being called does not need to know if the variable
  1349. X    is being passed by value or by address.
  1350. X
  1351. X    Built-in functions and object functions always accept their
  1352. X    arguments as addresses, thus there is no need to use '&' when
  1353. X    calling built-in functions.
  1354. SHAR_EOF
  1355. chmod 0644 calc2.9.0/help/variable || echo "restore of calc2.9.0/help/variable fails"
  1356. set `wc -c calc2.9.0/help/variable`;Sum=$1
  1357. if test "$Sum" != "3722"
  1358. then echo original size 3722, current size $Sum;fi
  1359. echo "x - extracting calc2.9.0/lib/Makefile (Text)"
  1360. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/lib/Makefile &&
  1361. X#
  1362. X# lib - makefile for calc library scripts
  1363. X#
  1364. X# Copyright (c) 1993 David I. Bell and Landon Curt Noll
  1365. X# Permission is granted to use, distribute, or modify this source,
  1366. X# provided that this copyright notice remains intact.
  1367. X#
  1368. X# Arbitrary precision calculator.
  1369. X#
  1370. X# calculator by David I. Bell
  1371. X# makefile by Landon Curt Noll
  1372. X
  1373. X# Normally, the upper level makefile will set these values.  We provide
  1374. X# a default here just in case you want to build from this directory.
  1375. X#
  1376. X# where to install things
  1377. XLIBDIR= /usr/local/lib/calc
  1378. X# how to build a directory
  1379. XMKDIR=mkdir -p
  1380. X#MKDIR=mkdir
  1381. X
  1382. X# The calc files to install
  1383. X#
  1384. XCALC_FILES= README bigprime.cal deg.cal ellip.cal lucas.cal lucas_chk.cal \
  1385. X    lucas_tbl.cal mersenne.cal mod.cal nextprim.cal pell.cal pi.cal \
  1386. X    pollard.cal poly.cal psqrt.cal quat.cal regress.cal solve.cal \
  1387. X    sumsq.cal surd.cal unitfrac.cal varargs.cal chrem.cal cryrand.cal \
  1388. X    bindings
  1389. X
  1390. XSHELL= /bin/sh
  1391. X
  1392. Xall: ${CALC_FILES}
  1393. X
  1394. Xclean:
  1395. X
  1396. Xclobber:
  1397. X
  1398. Xinstall: all
  1399. X    -@if [ ! -d ${LIBDIR} ]; then \
  1400. X        echo ${MKDIR} ${LIBDIR}; \
  1401. X        ${MKDIR} ${LIBDIR}; \
  1402. X    fi
  1403. X    @for i in ${CALC_FILES}; do \
  1404. X        echo rm -f ${LIBDIR}/$$i; \
  1405. X        rm -f ${LIBDIR}/$$i; \
  1406. X        echo cp $$i ${LIBDIR}; \
  1407. X        cp $$i ${LIBDIR}; \
  1408. X        echo chmod 0444 ${LIBDIR}/$$i; \
  1409. X        chmod 0444 ${LIBDIR}/$$i; \
  1410. X    done
  1411. SHAR_EOF
  1412. chmod 0644 calc2.9.0/lib/Makefile || echo "restore of calc2.9.0/lib/Makefile fails"
  1413. set `wc -c calc2.9.0/lib/Makefile`;Sum=$1
  1414. if test "$Sum" != "1257"
  1415. then echo original size 1257, current size $Sum;fi
  1416. echo "x - extracting calc2.9.0/lib/README (Text)"
  1417. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/lib/README &&
  1418. X
  1419. X# Copyright (c) 1993 David I. Bell and Landon Curt Noll
  1420. X# Permission is granted to use, distribute, or modify this source,
  1421. X# provided that this copyright notice remains intact.
  1422. X
  1423. XThe following calc library files are provided because they serve as 
  1424. Xexamples of how use the calc language, and because the authors thought 
  1425. Xthem to be useful!
  1426. X
  1427. XIf you write something that you think is useful, please send it to:
  1428. X
  1429. X    dbell@canb.auug.org.au
  1430. X    chongo@toad.com                 {uunet,pyramid,sun}!hoptoad!chongo
  1431. X
  1432. XBy convention, a lib file only defines and/or initializes functions,
  1433. Xobjects and variables.  (The regression test is an exception.)  Also by
  1434. Xconvention, the a usage message regarding each important object and
  1435. Xfunction is printed at the time of the read.
  1436. X
  1437. XBy convention, the global variable  lib_debug  is used to control
  1438. Xthe verbosity of debug information printed by lib files.  By default,
  1439. Xthe lib_debug has a value of 0.  If lib_debug < 0, then no debug
  1440. Xmessages are printed.  If lib_debug >= 0, then only usage message 
  1441. Xregarding each important object are printed at the time of the read.
  1442. XIf lib_debug == 0, then only such usage messages are printed; no
  1443. Xother debug information is printed.
  1444. X
  1445. XTo conform to the above convention, your lib files should end with
  1446. Xlines of the form:
  1447. X
  1448. X    global lib_debug;
  1449. X    if (lib_debug >= 0) {
  1450. X        print "funcA(side_a, side_b, side_c) defined";
  1451. X        print "funcB(size, mass) defined";
  1452. X    }
  1453. X
  1454. X
  1455. X=-=
  1456. X
  1457. X
  1458. Xbernoulli.cal
  1459. X
  1460. X    B(n)
  1461. X
  1462. X    Calculate the nth Bernoulli number.
  1463. X
  1464. X
  1465. Xbigprime.cal
  1466. X
  1467. X    bigprime(a, m, p) 
  1468. X
  1469. X    A prime test, base a, on p*2^x+1 for even x>m.
  1470. X
  1471. X
  1472. Xchrem.cal
  1473. X
  1474. X    chrem(r1,m1 [,r2,m2, ...])
  1475. X    chrem(rlist, mlist)
  1476. X
  1477. X    Chinese remainder theorem/problem solver.
  1478. X
  1479. X
  1480. Xcryrand.cal
  1481. X
  1482. X    shufrand()
  1483. X    sshufrand(seed)
  1484. X    rand([a, [b]])
  1485. X    srand(seed)
  1486. X    cryrand([a, [b]])
  1487. X    scryrand([seed, [len1, len2]])
  1488. X    random([a, [b]])
  1489. X    srandom(seed)
  1490. X    obj cryobj
  1491. X    randstate([cryobj | 0])
  1492. X    nxtprime(n, [val, modulus])
  1493. X
  1494. X    Cryptographically strong pseudo-random number generator library.
  1495. X    
  1496. X
  1497. Xdeg.cal        
  1498. X
  1499. X    dms(deg, min, sec)
  1500. X    dms_add(a, b)
  1501. X    dms_neg(a)
  1502. X    dms_sub(a, b)
  1503. X    dms_mul(a, b)
  1504. X    dms_print(a)
  1505. X
  1506. X    Calculate in degrees, minutes, and seconds.
  1507. X
  1508. X
  1509. Xellip.cal    
  1510. X
  1511. X    factor(iN, ia, B, force)
  1512. X
  1513. X    Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
  1514. X
  1515. X
  1516. Xlucas.cal
  1517. X
  1518. X    lucas(h, n)
  1519. X
  1520. X    Perform a primality test of h*2^n-1, with 1<=h<2*n.
  1521. X
  1522. X
  1523. Xlucas_chk.cal
  1524. X
  1525. X    lucas_chk(high_n)
  1526. X
  1527. X    Test all primes of the form h*2^n-1, with 1<=h<200 and n <= high_n.
  1528. X    Requires lucas.cal to be loaded.  The highest useful high_n is 1000.
  1529. X
  1530. X
  1531. Xlucas_tbl.cal
  1532. X
  1533. X    Lucasian criteria for primality tables.
  1534. X
  1535. X
  1536. Xmersenne.cal
  1537. X
  1538. X    mersenne(p)
  1539. X
  1540. X    Perform a primality test of 2^p-1, for prime p>1.
  1541. X
  1542. X
  1543. Xmod.cal    
  1544. X
  1545. X    mod(a)
  1546. X    mod_print(a)
  1547. X    mod_one()
  1548. X    mod_cmp(a, b)
  1549. X    mod_rel(a, b)
  1550. X    mod_add(a, b)
  1551. X    mod_sub(a, b)
  1552. X    mod_neg(a)
  1553. X    mod_mul(a, b)
  1554. X    mod_square(a)
  1555. X    mod_inc(a)
  1556. X    mod_dec(a)
  1557. X    mod_inv(a)
  1558. X    mod_div(a, b)
  1559. X    mod_pow(a, b)
  1560. X
  1561. X    Routines to handle numbers modulo a specified number.
  1562. X
  1563. X
  1564. Xnextprim.cal
  1565. X
  1566. X    nextprime(n, tries)
  1567. X
  1568. X    Function to find the next prime (probably).
  1569. X
  1570. X
  1571. Xpell.cal
  1572. X
  1573. X    pellx(D)
  1574. X    pell(D)
  1575. X
  1576. X    Solve Pell's equation; Returns the solution X to: X^2 - D * Y^2 = 1.
  1577. X    Type the solution to pells equation for a particular D.
  1578. X
  1579. X
  1580. Xpi.cal
  1581. SHAR_EOF
  1582. echo "End of part 15"
  1583. echo "File calc2.9.0/lib/README is continued in part 16"
  1584. echo "16" > s2_seq_.tmp
  1585. exit 0
  1586.