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

  1. Newsgroups: comp.sources.unix
  2. From: dbell@canb.auug.org.au (David I. Bell)
  3. Subject: v27i141: calc-2.9.0 - arbitrary precision C-like programmable calculator, Part14/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 141
  10. Archive-Name: calc-2.9.0/part14
  11.  
  12. #!/bin/sh
  13. # this is part 14 of a multipart archive
  14. # do not concatenate these parts, unpack them in order with /bin/sh
  15. # file calc2.9.0/zmul.c continued
  16. #
  17. CurArch=14
  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/zmul.c"
  28. sed 's/^X//' << 'SHAR_EOF' >> calc2.9.0/zmul.c
  29. X     */
  30. X    hd = &vp[size - 1];
  31. X    while ((*hd == 0) && (size > 1)) {
  32. X        size--;
  33. X        hd--;
  34. X    }
  35. X    sizetotal = size + size;
  36. X
  37. X    /*
  38. X     * If the number has only a small number of digits, then use the
  39. X     * (almost) normal multiplication method.  Multiply each halfword
  40. X     * only by those halfwards further on in the number.  Missed terms
  41. X     * will then be the same pairs of products repeated, and the squares
  42. X     * of each halfword.  The first case is handled by doubling the
  43. X     * result.  The second case is handled explicitly.  The number of
  44. X     * digits where the algorithm changes is settable from 2 to maxint.
  45. X     */
  46. X    if (size < _sq2_) {
  47. X        hd = ans;
  48. X        len = sizetotal;
  49. X        while (len--)
  50. X            *hd++ = 0;
  51. X
  52. X        h2 = vp;
  53. X        hd = ans + 1;
  54. X        for (len = size; len--; hd += 2) {
  55. X            digit = (FULL) *h2++;
  56. X            if (digit == 0)
  57. X                continue;
  58. X            h3 = h2;
  59. X            h1 = hd;
  60. X            carry = 0;
  61. X            len1 = len;
  62. X            while (len1 >= 4) {    /* expand the loop some */
  63. X                len1 -= 4;
  64. X                sival.ivalue = (digit * ((FULL) *h3++))
  65. X                    + ((FULL) *h1) + carry;
  66. X                *h1++ = sival.silow;
  67. X                sival.ivalue = (digit * ((FULL) *h3++))
  68. X                    + ((FULL) *h1) + ((FULL) sival.sihigh);
  69. X                *h1++ = sival.silow;
  70. X                sival.ivalue = (digit * ((FULL) *h3++))
  71. X                    + ((FULL) *h1) + ((FULL) sival.sihigh);
  72. X                *h1++ = sival.silow;
  73. X                sival.ivalue = (digit * ((FULL) *h3++))
  74. X                    + ((FULL) *h1) + ((FULL) sival.sihigh);
  75. X                *h1++ = sival.silow;
  76. X                carry = sival.sihigh;
  77. X            }
  78. X            while (len1--) {
  79. X                sival.ivalue = (digit * ((FULL) *h3++))
  80. X                    + ((FULL) *h1) + carry;
  81. X                *h1++ = sival.silow;
  82. X                carry = sival.sihigh;
  83. X            }
  84. X            while (carry) {
  85. X                sival.ivalue = ((FULL) *h1) + carry;
  86. X                *h1++ = sival.silow;
  87. X                carry = sival.sihigh;
  88. X            }
  89. X        }
  90. X
  91. X        /*
  92. X         * Now double the result.
  93. X         * There is no final carry to worry about because we
  94. X         * handle all digits of the result which must fit.
  95. X         */
  96. X        carry = 0;
  97. X        hd = ans;
  98. X        len = sizetotal;
  99. X        while (len--) {
  100. X            digit = ((FULL) *hd);
  101. X            sival.ivalue = digit + digit + carry;
  102. X            *hd++ = sival.silow;
  103. X            carry = sival.sihigh;
  104. X        }
  105. X
  106. X        /*
  107. X         * Now add in the squares of each halfword.
  108. X         */
  109. X        carry = 0;
  110. X        hd = ans;
  111. X        h3 = vp;
  112. X        len = size;
  113. X        while (len--) {
  114. X            digit = ((FULL) *h3++);
  115. X            sival.ivalue = digit * digit + ((FULL) *hd) + carry;
  116. X            *hd++ = sival.silow;
  117. X            carry = sival.sihigh;
  118. X            sival.ivalue = ((FULL) *hd) + carry;
  119. X            *hd++ = sival.silow;
  120. X            carry = sival.sihigh;
  121. X        }
  122. X        while (carry) {
  123. X            sival.ivalue = ((FULL) *hd) + carry;
  124. X            *hd++ = sival.silow;
  125. X            carry = sival.sihigh;
  126. X        }
  127. X
  128. X        /*
  129. X         * Finally return the size of the result.
  130. X         */
  131. X        len = sizetotal;
  132. X        hd = &ans[len - 1];
  133. X        while ((*hd == 0) && (len > 1)) {
  134. X            len--;
  135. X            hd--;
  136. X        }
  137. X        return len;
  138. X    }
  139. X
  140. X    /*
  141. X     * The number to be squared is large.
  142. X     * Allocate temporary space and determine the sizes and
  143. X     * positions of the values to be calculated.
  144. X     */
  145. X    temp = tempbuf;
  146. X    tempbuf += (3 * (size + 1) / 2);
  147. X
  148. X    sizeA = size / 2;
  149. X    sizeB = size - sizeA;
  150. X    shift = sizeB;
  151. X    baseA = vp + sizeB;
  152. X    baseB = vp;
  153. X    baseAA = &ans[shift * 2];
  154. X    baseBB = ans;
  155. X    baseAABB = temp;
  156. X    baseAB = temp;
  157. X    baseABAB = &temp[shift];
  158. X
  159. X    /*
  160. X     * Trim the second number of leading zeroes.
  161. X     */
  162. X    hd = &baseB[sizeB - 1];
  163. X    while ((*hd == 0) && (sizeB > 1)) {
  164. X        sizeB--;
  165. X        hd--;
  166. X    }
  167. X
  168. X    /*
  169. X     * Now to proceed to calculate the result using the formula.
  170. X     *    (A*S+B)^2 = (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2.
  171. X     * The steps are done in the following order:
  172. X     *    S^2*A^2 + B^2
  173. X     *    A^2 + B^2
  174. X     *    (S^2+S)*A^2 + (S+1)*B^2
  175. X     *    (A-B)^2
  176. X     *    (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2.
  177. X     *
  178. X     * Begin by forming the squares of two the halfs concatenated
  179. X     * together in the final result location.  Make sure that the
  180. X     * highest words of the results are zero.
  181. X     */
  182. X    sizeBB = dosquare(baseB, sizeB, baseBB);
  183. X    hd = &baseBB[sizeBB];
  184. X    len = shift * 2 - sizeBB;
  185. X    while (len--)
  186. X        *hd++ = 0;
  187. X
  188. X    sizeAA = dosquare(baseA, sizeA, baseAA);
  189. X    hd = &baseAA[sizeAA];
  190. X    len = sizetotal - shift * 2 - sizeAA;
  191. X    while (len--)
  192. X        *hd++ = 0;
  193. X
  194. X    /*
  195. X     * Sum the two squares into a temporary location.
  196. X     */
  197. X    if (sizeAA >= sizeBB) {
  198. X        h1 = baseAA;
  199. X        h2 = baseBB;
  200. X        sizeAABB = sizeAA;
  201. X        sumsize = sizeBB;
  202. X    } else {
  203. X        h1 = baseBB;
  204. X        h2 = baseAA;
  205. X        sizeAABB = sizeBB;
  206. X        sumsize = sizeAA;
  207. X    }
  208. X    copysize = sizeAABB - sumsize;
  209. X
  210. X    hd = baseAABB;
  211. X    carry = 0;
  212. X    while (sumsize--) {
  213. X        sival.ivalue = ((FULL) *h1++) + ((FULL) *h2++) + carry;
  214. X        *hd++ = sival.silow;
  215. X        carry = sival.sihigh;
  216. X    }
  217. X    while (copysize--) {
  218. X        sival.ivalue = ((FULL) *h1++) + carry;
  219. X        *hd++ = sival.silow;
  220. X        carry = sival.sihigh;
  221. X    }
  222. X    if (carry) {
  223. X        *hd = (HALF)carry;
  224. X        sizeAABB++;
  225. X    }
  226. X
  227. X    /*
  228. X     * Add the sum back into the previously calculated squares
  229. X     * shifted over to the proper location.
  230. X     */
  231. X    h1 = baseAABB;
  232. X    hd = ans + shift;
  233. X    carry = 0;
  234. X    len = sizeAABB;
  235. X    while (len--) {
  236. X        sival.ivalue = ((FULL) *hd) + ((FULL) *h1++) + carry;
  237. X        *hd++ = sival.silow;
  238. X        carry = sival.sihigh;
  239. X    }
  240. X    while (carry) {
  241. X        sival.ivalue = ((FULL) *hd) + carry;
  242. X        *hd++ = sival.silow;
  243. X        carry = sival.sihigh;
  244. X    }
  245. X
  246. X    /*
  247. X     * Calculate the absolute value of the difference of the two halfs
  248. X     * into a temporary location.
  249. X     */
  250. X    if (sizeA == sizeB) {
  251. X        len = sizeA;
  252. X        h1 = &baseA[len - 1];
  253. X        h2 = &baseB[len - 1];
  254. X        while ((len > 1) && (*h1 == *h2)) {
  255. X            len--;
  256. X            h1--;
  257. X            h2--;
  258. X        }
  259. X    }
  260. X    if ((sizeA > sizeB) || ((sizeA == sizeB) && (*h1 > *h2)))
  261. X    {
  262. X        h1 = baseA;
  263. X        h2 = baseB;
  264. X        sizeAB = sizeA;
  265. X        subsize = sizeB;
  266. X    } else {
  267. X        h1 = baseB;
  268. X        h2 = baseA;
  269. X        sizeAB = sizeB;
  270. X        subsize = sizeA;
  271. X    }
  272. X    copysize = sizeAB - subsize;
  273. X
  274. X    hd = baseAB;
  275. X    carry = 0;
  276. X    while (subsize--) {
  277. X        sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry;
  278. X        *hd++ = BASE1 - sival.silow;
  279. X        carry = sival.sihigh;
  280. X    }
  281. X    while (copysize--) {
  282. X        sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry;
  283. X        *hd++ = BASE1 - sival.silow;
  284. X        carry = sival.sihigh;
  285. X    }
  286. X
  287. X    hd = &baseAB[sizeAB - 1];
  288. X    while ((*hd == 0) && (sizeAB > 1)) {
  289. X        sizeAB--;
  290. X        hd--;
  291. X    }
  292. X
  293. X    /*
  294. X     * Now square the number into another temporary location,
  295. X     * and subtract that from the final result.
  296. X     */
  297. X    sizeABAB = dosquare(baseAB, sizeAB, baseABAB);
  298. X
  299. X    h1 = baseABAB;
  300. X    hd = ans + shift;
  301. X    carry = 0;
  302. X    while (sizeABAB--) {
  303. X        sival.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) + carry;
  304. X        *hd++ = BASE1 - sival.silow;
  305. X        carry = sival.sihigh;
  306. X    }
  307. X    while (carry) {
  308. X        sival.ivalue = BASE1 - ((FULL) *hd) + carry;
  309. X        *hd++ = BASE1 - sival.silow;
  310. X        carry = sival.sihigh;
  311. X    }
  312. X
  313. X    /*
  314. X     * Return the size of the result.
  315. X     */
  316. X    len = sizetotal;
  317. X    hd = &ans[len - 1];
  318. X    while ((*hd == 0) && (len > 1)) {
  319. X        len--;
  320. X        hd--;
  321. X    }
  322. X    tempbuf = temp;
  323. X    return len;
  324. X}
  325. X
  326. X
  327. X/*
  328. X * Return a pointer to a buffer to be used for holding a temporary number.
  329. X * The buffer will be at least as large as the specified number of HALFs,
  330. X * and remains valid until the next call to this routine.  The buffer cannot
  331. X * be freed by the caller.  There is only one temporary buffer, and so as to
  332. X * avoid possible conflicts this is only used by the lowest level routines
  333. X * such as divide, multiply, and square.
  334. X */
  335. XHALF *
  336. Xzalloctemp(len)
  337. X    LEN len;        /* required number of HALFs in buffer */
  338. X{
  339. X    HALF *hp;
  340. X    static LEN buflen;    /* current length of temp buffer */
  341. X    static HALF *bufptr;    /* pointer to current temp buffer */
  342. X
  343. X    if (len <= buflen)
  344. X        return bufptr;
  345. X
  346. X    /*
  347. X     * We need to grow the temporary buffer.
  348. X     * First free any existing buffer, and then allocate the new one.
  349. X     * While we are at it, make the new buffer bigger than necessary
  350. X     * in order to reduce the number of reallocations.
  351. X     */
  352. X    len += 100;
  353. X    if (buflen) {
  354. X        buflen = 0;
  355. X        free(bufptr);
  356. X    }
  357. X    hp = (HALF *) malloc(len * sizeof(HALF));
  358. X    if (hp == NULL)
  359. X        math_error("No memory for temp buffer");
  360. X    bufptr = hp;
  361. X    buflen = len;
  362. X    return hp;
  363. X}
  364. X
  365. X/* END CODE */
  366. SHAR_EOF
  367. echo "File calc2.9.0/zmul.c is complete"
  368. chmod 0644 calc2.9.0/zmul.c || echo "restore of calc2.9.0/zmul.c fails"
  369. set `wc -c calc2.9.0/zmul.c`;Sum=$1
  370. if test "$Sum" != "27288"
  371. then echo original size 27288, current size $Sum;fi
  372. echo "x - extracting calc2.9.0/help/Makefile (Text)"
  373. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/Makefile &&
  374. X#
  375. X# help - makefile for calc help files
  376. X#
  377. X# Copyright (c) 1993 David I. Bell and Landon Curt Noll
  378. X# Permission is granted to use, distribute, or modify this source,
  379. X# provided that this copyright notice remains intact.
  380. X#
  381. X# Arbitrary precision calculator.
  382. X#
  383. X# calculator by David I. Bell
  384. X# makefile by Landon Curt Noll
  385. X
  386. XSHELL= /bin/sh
  387. X
  388. X# Normally, the upper level makefile will set these values.  We provide
  389. X# a default here just in case you want to build from this directory.
  390. X#
  391. X# where to install things
  392. XHELPDIR= /usr/local/lib/calc/help
  393. X# the usually LIBDIR value from the upper level Makefile
  394. XLIBDIR= /usr/local/lib/calc
  395. X
  396. X# how to build a directory
  397. XMKDIR=mkdir -p
  398. X#MKDIR=mkdir
  399. X
  400. X# standard tools
  401. XSED= sed
  402. X
  403. X# Standard help files
  404. X#
  405. XSTD_HELP_FILES=intro command expression define variable statement \
  406. X    operator types mat list file builtin config interrupt \
  407. X    history usage credit bindings assoc \
  408. X    overview stdlib environment todo credit help
  409. X
  410. X# Help files that are constructed from other sources
  411. X#
  412. XBUILT_HELP_FILES=bindings stdlib changes libcalc
  413. X
  414. Xall: ${STD_HELP_FILES} obj.file ${BUILT_HELP_FILES}
  415. X
  416. Xbindings: ../lib/bindings
  417. X    rm -f bindings
  418. X    cp ../lib/bindings bindings
  419. X    chmod 0444 bindings
  420. X
  421. Xstdlib: ../lib/README
  422. X    rm -f stdlib
  423. X    cp ../lib/README stdlib
  424. X    chmod 0444 stdlib
  425. X
  426. Xchanges: ../CHANGES
  427. X    rm -f changes
  428. X    cp ../CHANGES changes
  429. X    chmod 0444 changes
  430. X
  431. Xlibcalc: ../LIBRARY
  432. X    rm -f libcalc
  433. X    ${SED} -e 's:$${LIBDIR}:${LIBDIR}:g' < ../LIBRARY > libcalc
  434. X    chmod 0444 libcalc
  435. X
  436. Xclean:
  437. X
  438. Xclobber:
  439. X    rm -f ${BUILT_HELP_FILES}
  440. X
  441. Xinstall: all
  442. X    -@if [ ! -d ${HELPDIR} ]; then \
  443. X        echo ${MKDIR} ${HELPDIR}; \
  444. X        ${MKDIR} ${HELPDIR}; \
  445. X    fi
  446. X    @for i in ${STD_HELP_FILES} ${BUILT_HELP_FILES}; do \
  447. X        echo rm -f ${HELPDIR}/$$i; \
  448. X        rm -f ${HELPDIR}/$$i; \
  449. X        echo cp $$i ${HELPDIR}; \
  450. X        cp $$i ${HELPDIR}; \
  451. X        echo chmod 0444 ${HELPDIR}/$$i; \
  452. X        chmod 0444 ${HELPDIR}/$$i; \
  453. X    done
  454. X    rm -f ${HELPDIR}/obj
  455. X    cp obj.file ${HELPDIR}/obj
  456. X    chmod 0444 ${HELPDIR}/obj
  457. SHAR_EOF
  458. chmod 0444 calc2.9.0/help/Makefile || echo "restore of calc2.9.0/help/Makefile fails"
  459. set `wc -c calc2.9.0/help/Makefile`;Sum=$1
  460. if test "$Sum" != "1934"
  461. then echo original size 1934, current size $Sum;fi
  462. echo "x - extracting calc2.9.0/help/assoc (Text)"
  463. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/assoc &&
  464. XUsing associations
  465. X
  466. X    Associations are special values that act like matrices, except
  467. X    that they are more general (and slower) than normal matrices.
  468. X    Unlike matrices, associations can be indexed by arbitrary values.
  469. X    For example, if 'val' was an association, you could do the following:
  470. X
  471. X        val['hello'] = 11;
  472. X        val[4.5] = val['hello'];
  473. X        print val[9/2];
  474. X
  475. X    and 11 would be printed.
  476. X
  477. X    Associations are created by the 'assoc' function.  It takes no
  478. X    arguments, and simply returns an empty association.  You can then
  479. X    insert elements into the association by indexing the returned value
  480. X    as shown above.
  481. X
  482. X    Associations are multi-dimensional.  You can index them using one to
  483. X    four dimensions as desired, and the elements with different numbers
  484. X    of dimensions will remain separated.  For example, 'val[3]' and
  485. X    'val[3,0]' can both be used in the same association and will be
  486. X    distinct elements.
  487. X
  488. X    When references are made to undefined elements of an association,
  489. X    a null value is simply returned.  Therefore no bounds errors can
  490. X    occur when indexing an association.  Assignments of a null value
  491. X    to an element of an association does not delete the element, but
  492. X    a later reference to that element will return the null value as if
  493. X    the element was undefined.  Elements with null values are implicitly
  494. X    created on certain other operations which require an address to be
  495. X    taken, such as the += operator and using & in a function call.
  496. X
  497. X    The elements of an association are stored in a hash table for
  498. X    quick access.  The index values are hashed to select the correct
  499. X    hash chain for a small sequential search for the element.  The hash
  500. X    table will be resized as necessary as the number of entries in
  501. X    the association becomes larger.
  502. X
  503. X    The size function returns the number of elements in an association.
  504. X    This size will include elements with null values.
  505. X
  506. X    Double bracket indexing can be used for associations to walk through
  507. X    the elements of the association.  The order that the elements are
  508. X    returned in as the index increases is essentially random.  Any
  509. X    change made to the association can reorder the elements, this making
  510. X    a sequential scan through the elements difficult.
  511. X
  512. X    The search and rsearch functions can search for an element in an
  513. X    association which has the specified value.  They return the index
  514. X    of the found element, or a NULL value if the value was not found.
  515. X
  516. X    Associations can be copied by an assignment, and can be compared
  517. X    for equality.  But no other operations on associations have meaning,
  518. X    and are illegal.
  519. SHAR_EOF
  520. chmod 0644 calc2.9.0/help/assoc || echo "restore of calc2.9.0/help/assoc fails"
  521. set `wc -c calc2.9.0/help/assoc`;Sum=$1
  522. if test "$Sum" != "2519"
  523. then echo original size 2519, current size $Sum;fi
  524. echo "x - extracting calc2.9.0/help/builtin (Text)"
  525. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/builtin &&
  526. XBuiltin functions
  527. X
  528. X    There is a large number of built-in functions.  Many of the
  529. X    functions work on several types of arguments, whereas some only
  530. X    work for the correct types (e.g., numbers or strings).  In the
  531. X    following description, this is indicated by whether or not the
  532. X    description refers to values or numbers.  This display is generated
  533. X    by the 'show builtins' command.
  534. X
  535. X        Name      Args   Description
  536. X
  537. X        abs       1-2    absolute value within accuracy b
  538. X        acos      1-2    arccosine of a within accuracy b
  539. X        acosh     1-2    hyperbolic arccosine of a within accuracy b
  540. X        append    2      append value to end of list
  541. X        appr      1-2    approximate a with simpler fraction to within b
  542. X        arg       1-2    argument (the angle) of complex number
  543. X        asin      1-2    arcsine of a within accuracy b
  544. X        asinh     1-2    hyperbolic arcsine of a within accuracy b
  545. X        atan      1-2    arctangent of a within accuracy b
  546. X        atan2     2-3    angle to point (b,a) within accuracy c
  547. X        atanh     1-2    hyperbolic arctangent of a within accuracy b
  548. X        avg       1+     arithmetic mean of values
  549. X        bround    1-2    round value a to b number of binary places
  550. X        btrunc    1-2    truncate a to b number of binary places
  551. X        ceil      1      smallest integer greater than or equal to number
  552. X        cfappr    1-2    approximate a within accuracy b using 
  553. X                continued fractions
  554. X        cfsim     1      simplify number using continued fractions
  555. X        char      1      character corresponding to integer value
  556. X        cmp       2      compare values returning -1, 0, or 1
  557. X        comb      2      combinatorial number a!/b!(a-b)!
  558. X        config    1-2    set or read configuration value
  559. X        conj      1      complex conjugate of value
  560. X        cos       1-2    cosine of value a within accuracy b
  561. X        cosh      1-2    hyperbolic cosine of a within accuracy b
  562. X        cp        2      Cross product of two vectors
  563. X        delete    2      delete element from list a at position b
  564. X        den       1      denominator of fraction
  565. X        det       1      determinant of matrix
  566. X        digit     2      digit at specified decimal place of number
  567. X        digits    1      number of digits in number
  568. X        dp        2      Dot product of two vectors
  569. X        epsilon   0-1    set or read allowed error for real calculations
  570. X        eval      1      Evaluate expression from string to value
  571. X        exp       1-2    exponential of value a within accuracy b
  572. X        fcnt      2      count of times one number divides another
  573. X        fib       1      Fibonacci number F(n)
  574. X        frem      2      number with all occurrences of factor removed
  575. X        fact      1      factorial
  576. X        fclose    1      close file
  577. X        feof      1      whether EOF reached for file
  578. X        ferror    1      whether error occurred for file
  579. X        fflush    1      flush output to file
  580. X        fgetc     1      read next char from file
  581. X        fgetline  1      read next line from file
  582. X        files     0-1    return opened file or max number of opened files
  583. X        floor     1      greatest integer less than or equal to number
  584. X        fopen     2      open file name a in mode b
  585. X        fprintf   2+     print formatted output to opened file
  586. X        frac      1      fractional part of value
  587. X        gcd       1+     greatest common divisor
  588. X        gcdrem    2      a divided repeatedly by gcd with b
  589. X        hash      1+     return non-negative hash value for one or
  590. X                         more values
  591. X        highbit   1      high bit number in base 2 representation
  592. X        hmean     1+     harmonic mean of values
  593. X        hypot     2-3    hypotenuse of right triangle within accuracy c
  594. X        ilog      2      integral log of one number with another
  595. X        ilog10    1      integral log of a number base 10
  596. X        ilog2     1      integral log of a number base 2
  597. X        im        1      imaginary part of complex number
  598. X        insert    3      insert value c into list a at position b
  599. X        int       1      integer part of value
  600. X        inverse   1      multiplicative inverse of value
  601. X        iroot     2      integer b'th root of a
  602. X        iseven    1      whether a value is an even integer
  603. X        isfile    1      whether a value is a file
  604. X        isint     1      whether a value is an integer
  605. X        islist    1      whether a value is a list
  606. X        ismat     1      whether a value is a matrix
  607. X        ismult    2      whether a is a multiple of b
  608. X        isnull    1      whether a value is the null value
  609. X        isnum     1      whether a value is a number
  610. X        isobj     1      whether a value is an object
  611. X        isodd     1      whether a value is an odd integer
  612. X        isqrt     1      integer part of square root
  613. X        isreal    1      whether a value is a real number
  614. X        isset     2      whether bit b of abs(a) (in base 2) is set
  615. X        isstr     1      whether a value is a string
  616. X        isrel     2      whether two numbers are relatively prime
  617. X        issimple  1      whether value is a simple type
  618. X        issq      1      whether or not number is a square
  619. X        istype    2      whether the type of a is same as the type of b
  620. X        jacobi    2      -1 => a is not quadratic residue mod b
  621. X                 1 => b is composite, or a is quad residue of b
  622. X        lcm       1+     least common multiple
  623. X        lcmfact   1      lcm of all integers up till number
  624. X        lfactor   2      lowest prime factor of a in first b primes
  625. X        list      0+     create list of specified values
  626. X        ln        1-2    natural logarithm of value a within accuracy b
  627. X        lowbit    1      low bit number in base 2 representation
  628. X        ltol      1-2    leg-to-leg of unit right triangle (sqrt(1 - a^2))
  629. X        matdim    1      number of dimensions of matrix
  630. X        matfill   2-3    fill matrix with value b (value c on diagonal)
  631. X        matmax    2      maximum index of matrix a dim b
  632. X        matmin    2      minimum index of matrix a dim b
  633. X        mattrans  1      transpose of matrix
  634. X        max       1+     maximum value
  635. X        meq       3      whether a and b are equal modulo c
  636. X        min       1+     minimum value
  637. X        minv      2      inverse of a modulo b
  638. X        mmin      2      a mod b value with smallest abs value
  639. X        mne       3      whether a and b are not equal modulo c
  640. X        near      2-3    sign of (abs(a-b) - c)
  641. X        norm      1      norm of a value (square of absolute value)
  642. X        null      0      null value
  643. X        num       1      numerator of fraction
  644. X        ord       1      integer corresponding to character value
  645. X        param     1      value of parameter n (or parameter count if n 
  646. X                is zero)
  647. X        perm      2      permutation number a!/(a-b)!
  648. X        pfact     1      product of primes up till number
  649. X        pi        0-1    value of pi accurate to within epsilon
  650. X        places    1      places after decimal point (-1 if infinite)
  651. X        pmod      3      mod of a power (a ^ b (mod c))
  652. X        polar     2-3    complex value of polar coordinate (a * exp(b*1i))
  653. X        poly      2+     (a1,a2,...,an,x) = a1*x^n+a2*x^(n-1)+...+an
  654. X        pop       1      pop value from front of list
  655. X        power     2-3    value a raised to the power b within accuracy c
  656. X        ptest     2      probabilistic primality test
  657. X        printf    1+     print formatted output to stdout
  658. X        prompt    1      prompt for input line using value a
  659. X        push      2      push value onto front of list
  660. X        quomod    4      set c and d to quotient and remainder of a 
  661. X                divided by b
  662. X        rcin      2      convert normal number a to REDC number mod b
  663. X        rcmul     3      multiply REDC numbers a and b mod c
  664. X        rcout     2      convert REDC number a mod b to normal number
  665. X        rcpow     3      raise REDC number a to power b mod c
  666. X        rcsq      2      square REDC number a mod b
  667. X        re        1      real part of complex number
  668. X        remove    1      remove value from end of list
  669. X        root      2-3    value a taken to the b'th root within accuracy c
  670. X        round     1-2    round value a to b number of decimal places
  671. X        rsearch   2-3    reverse search matrix or list for value b 
  672. X                starting at index c
  673. X        runtime   0      user mode cpu time in seconds
  674. X        scale     2      scale value up or down by a power of two
  675. X        search    2-3    search matrix or list for value b starting 
  676. X                at index c
  677. X        sgn       1      sign of value (-1, 0, 1)
  678. X        sin       1-2    sine of value a within accuracy b
  679. X        sinh      1-2    hyperbolic sine of a within accuracy b
  680. X        size      1      total number of elements in value
  681. X        sqrt      1-2    square root of value a within accuracy b
  682. X        ssq       1+     sum of squares of values
  683. X        str       1      simple value converted to string
  684. X        strcat    1+     concatenate strings together
  685. X        strlen    1      length of string
  686. X        strprintf 1+     return formatted output as a string
  687. X        substr    3      substring of a from position b for c chars
  688. X        swap      2      swap values of variables a and b (can be dangerous)
  689. X        tan       1-2    tangent of a within accuracy b
  690. X        tanh      1-2    hyperbolic tangent of a within accuracy b
  691. X        trunc     1-2    truncate a to b number of decimal places
  692. X        xor       1+     logical xor
  693. X
  694. X    The config function sets or reads the value of a configuration
  695. X    parameter.  The first argument is a string which names the parameter
  696. X    to be set or read.  If only one argument is given, then the current
  697. X    value of the named parameter is returned.  If two arguments are given,
  698. X    then the named parameter is set to the value of the second argument,
  699. X    and the old value of the parameter is returned.  Therefore you can
  700. X    change a parameter and restore its old value later.  The possible
  701. X    parameters are explained in the next section.
  702. X
  703. X    The scale function multiplies or divides a number by a power of 2.
  704. X    This is used for fractional calculations, unlike the << and >>
  705. X    operators, which are only defined for integers.  For example,
  706. X    scale(6, -3) is 3/4.
  707. X
  708. X    The quomod function is used to obtain both the quotient and remainder
  709. X    of a division in one operation.  The first two arguments a and b are
  710. X    the numbers to be divided.  The last two arguments c and d are two
  711. X    variables which will be assigned the quotient and remainder.  For
  712. X    nonnegative arguments, the results are equivalent to computing a//b
  713. X    and a%b.  If a is negative and the remainder is nonzero, then the
  714. X    quotient will be one less than a//b.  This makes the following three
  715. X    properties always hold:  The quotient c is always an integer.  The
  716. X    remainder d is always 0 <= d < b.  The equation a = b * c + d always
  717. X    holds.  This function returns 0 if there is no remainder, and 1 if
  718. X    there is a remainder.  For examples, quomod(10, 3, x, y) sets x to 3,
  719. X    y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x
  720. X    to -2, y to 2.28318, and returns the value 1.
  721. X
  722. X    The eval function accepts a string argument and evaluates the
  723. X    expression represented by the string and returns its value.
  724. X    The expression can include function calls and variable references.
  725. X    For example, eval("fact(3) + 7") returns 13.  When combined with
  726. X    the prompt function, this allows the calculator to read values from
  727. X    the user.  For example, x=eval(prompt("Number: ")) sets x to the
  728. X    value input by the user.
  729. X
  730. X    The digit and isset functions return individual digits of a number,
  731. X    either in base 10 or in base 2, where the lowest digit of a number
  732. X    is at digit position 0.  For example, digit(5678, 3) is 5, and
  733. X    isset(0b1000100, 2) is 1.  Negative digit positions indicate places
  734. X    to the right of the decimal or binary point, so that for example,
  735. X    digit(3.456, -1) is 4.
  736. X
  737. X    The ptest function is a primality testing function.  The first
  738. X    argument is the suspected prime to be tested.  The second argument
  739. X    is an iteration count.  The function returns 0 if the number is
  740. X    definitely not prime, and 1 is the number is probably prime.  The
  741. X    chance of a number which is probably prime being actually composite
  742. X    is less than 1/4 raised to the power of the iteration count.  For
  743. X    example, for a random number p, ptest(p, 10) incorrectly returns 1
  744. X    less than once in every million numbers, and you will probably never
  745. X    find a number where ptest(p, 20) gives the wrong answer.
  746. X
  747. X    The functions rcin, rcmul, rcout, rcpow, and rcsq are used to
  748. X    perform modular arithmetic calculations for large odd numbers
  749. X    faster than the usual methods.  To do this, you first use the
  750. X    rcin function to convert all input values into numbers which are
  751. X    in a format called REDC format.  Then you use rcmul, rcsq, and
  752. X    rcpow to multiply such numbers together to produce results also
  753. X    in REDC format.  Finally, you use rcout to convert a number in
  754. X    REDC format back to a normal number.  The addition, subtraction,
  755. X    negation, and equality comparison between REDC numbers are done
  756. X    using the normal modular methods.  For example, to calculate the
  757. X    value 13 * 17 + 1 (mod 11), you could use:
  758. X
  759. X        p = 11;
  760. X        t1 = rcin(13, p);
  761. X        t2 = rcin(17, p);
  762. X        t3 = rcin(1, p);
  763. X        t4 = rcmul(t1, t2, p);
  764. X        t5 = (t4 + t3) % p;
  765. X        answer = rcout(t5, p);
  766. X
  767. X    The swap function exchanges the values of two variables without
  768. X    performing copies.  For example, after:
  769. X
  770. X        x = 17;
  771. X        y = 19;
  772. X        swap(x, y);
  773. X
  774. X    then x is 19 and y is 17.  This function should not be used to
  775. X    swap a value which is contained within another one.  If this is
  776. X    done, then some memory will be lost.  For example, the following
  777. X    should not be done:
  778. X
  779. X        mat x[5];
  780. X        swap(x, x[0]);
  781. X
  782. X    The hash function returns a relatively small non-negative integer
  783. X    for one or more input values.  The hash values should not be used
  784. X    across runs of the calculator, since the algorithms used to generate
  785. X    the hash value may change with different versions of the calculator.
  786. SHAR_EOF
  787. chmod 0644 calc2.9.0/help/builtin || echo "restore of calc2.9.0/help/builtin fails"
  788. set `wc -c calc2.9.0/help/builtin`;Sum=$1
  789. if test "$Sum" != "13487"
  790. then echo original size 13487, current size $Sum;fi
  791. echo "x - extracting calc2.9.0/help/command (Text)"
  792. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/command &&
  793. XCommand sequence
  794. X
  795. X    This is a sequence of any the following command formats, where
  796. X    each command is terminated by a semicolon or newline.  Long command
  797. X    lines can be extended by using a back-slash followed by a newline
  798. X    character.  When this is done, the prompt shows a double angle
  799. X    bracket to indicate that the line is still in progress.  Certain
  800. X    cases will automatically prompt for more input in a similar manner,
  801. X    even without the back-slash.  The most common case for this is when
  802. X    a function is being defined, but is not yet completed.
  803. X
  804. X    Each command sequence terminates only on an end of file.  In
  805. X    addition, commands can consist of expression sequences, which are
  806. X    described in the next section.
  807. X
  808. X
  809. X    NOTE: Calc commands are in lower case.   UPPER case is used below
  810. X          for emphasis only, and should be considered in lower case.
  811. X
  812. X
  813. X    DEFINE function(params) { body }
  814. X    DEFINE function(params) = expression
  815. X        This first form defines a full function which can consist
  816. X        of declarations followed by many statements which implement
  817. X        the function.
  818. X
  819. X        The second form defines a simple function which calculates
  820. X        the specified expression value from the specified parameters.
  821. X        The expression cannot be a statement.  However, the comma
  822. X        and question mark operators can be useful.  Examples of
  823. X        simple functions are:
  824. X
  825. X            define sumcubes(a, b) = a^3 + b^3;
  826. X            define pimod(a) = a % pi();
  827. X
  828. X    HELP
  829. X        This displays a general help message.
  830. X
  831. X    READ filename
  832. X        This reads definitions from the specified filename.
  833. X        The name can be quoted if desired.  The calculator
  834. X        uses the CALCPATH environment variable to search
  835. X        through the specified directories for the filename,
  836. X        similarly to the use of the PATH environment variable.
  837. X        If CALCPATH is not defined, then a default path of
  838. X        ":/usr/lib/calc" is used (that is, the current directory
  839. X        followed by a general calc library directory).  The
  840. X        ".cal" extension is defaulted for input files, so that
  841. X        if "filename" is not found, then "filename.cal" is then
  842. X        searched for.  The contents of the filename are command
  843. X        sequences which can consist of expressions to evaluate
  844. X        or functions to define, just like at the top level
  845. X        command level.
  846. X
  847. X    WRITE filename
  848. X        This writes the values of all global variables to the
  849. X        specified filename, in such a way that the file can be
  850. X        later read in order to recreate the variable values.
  851. X        For speed reasons, values are written as hex fractions.
  852. X        This command currently only saves simple types, so that
  853. X        matrices, lists, and objects are not saved.  Function
  854. X        definitions are also not saved.
  855. X
  856. X    QUIT
  857. X        This leaves the calculator, when given as a top-level
  858. X        command.
  859. X    
  860. X
  861. X    Also see the help topic:
  862. X
  863. X        statement       flow control and declaration statements
  864. SHAR_EOF
  865. chmod 0644 calc2.9.0/help/command || echo "restore of calc2.9.0/help/command fails"
  866. set `wc -c calc2.9.0/help/command`;Sum=$1
  867. if test "$Sum" != "2740"
  868. then echo original size 2740, current size $Sum;fi
  869. echo "x - extracting calc2.9.0/help/config (Text)"
  870. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/config &&
  871. XConfiguration parameters
  872. X
  873. X    Configuration parameters affect how the calculator performs certain
  874. X    operations, and affects all future calculations.  These parameters
  875. X    affect the accuracy of calculations, the displayed format of results,
  876. X    and which algorithms are used for calculations.  The parameters are
  877. X    read or set using the "config" built-in function.  The following
  878. X    parameters can be specified:
  879. X
  880. X        "trace"        turns tracing on or off (for debugging).
  881. X        "display"    sets number of digits in prints.
  882. X        "epsilon"    sets error value for transcendentals.
  883. X        "maxprint"    sets maximum number of elements printed.
  884. X        "mode"        sets printout mode.
  885. X        "mul2"        sets size for alternative multiply.
  886. X        "sq2"        sets size for alternative squaring.
  887. X        "pow2"        sets size for alternate powering.
  888. X        "redc2"        sets size for alternate REDC.
  889. X
  890. X    The use of the trace flag is for debugging, and its meaning may
  891. X    change in the future.  A value of 1 causes the calculator to print
  892. X    its internal opcodes as it executes functions.  A value of zero
  893. X    disables tracing again.
  894. X
  895. X    Display specifies how many digits after the decimal point should
  896. X    be printed when printing real or exponential numbers.  The initial
  897. X    display value is 20.  This parameter does not affect the accuracy
  898. X    of a calculation, since it only has meaning when printing results.
  899. X
  900. X    Epsilon specifies the required precision of calculations by
  901. X    setting the maximum allowed error for transcendental functions.
  902. X    The error is an absolute error value for many functions, but
  903. X    for some functions it is a relative error.  The initial value
  904. X    is 1e-20.  Functions which require an epsilon value accept an
  905. X    optional argument which overrides this default epsilon value for
  906. X    that single call.  The built-in function "epsilon" also can be
  907. X    used to read or set this value, and is provided for ease of use.
  908. X
  909. X    Mode specifies how numbers should be printed.  Mode is a string
  910. X    value indicating the printout method.  The initial mode is "real".
  911. X    Possible modes are:
  912. X
  913. X        "frac"        decimal fractions
  914. X        "int"        decimal integer
  915. X        "real"        decimal floating point
  916. X        "exp"        decimal exponential
  917. X        "hex"        hex fractions
  918. X        "oct"        octal fractions
  919. X        "bin"        binary fractions
  920. X
  921. X    Maxprint specifies the maximum number of elements to be displayed
  922. X    when a matrix or list is printed.  The initial value is 16 elements.
  923. X
  924. X    Mul2 and sq2 specify the sizes of numbers at which calc switches
  925. X    from its first to its second algorithm for multiplying and squaring.
  926. X    The first algorithm is the usual method of cross multiplying, which
  927. X    runs in a time of O(N^2).  The second method is a recursive and
  928. X    complicated method which runs in a time of O(N^1.585).  The argument
  929. X    for these parameters is the number of binary words at which the
  930. X    second algorithm begins to be used.  The minimum value is 2, and
  931. X    the maximum value is very large.  If 2 is used, then the recursive
  932. X    algorithm is used all the way down to single digits, which becomes
  933. X    slow since the recursion overhead is high.  If a number such as
  934. X    1000000 is used, then the recursive algorithm is never used, causing
  935. X    calculations for large numbers to slow down.  For a typical example
  936. X    on a 386, the two algorithms are about equal in speed for a value
  937. X    of 20, which is about 100 decimal digits.  A value of zero resets
  938. X    the parameter back to its default value.  Usually there is no need
  939. X    to change these parameters.
  940. X
  941. X    Pow2 specifies the sizes of numbers at which calc switches from
  942. X    its first to its second algorithm for calculating powers modulo
  943. X    another number.  The first algorithm for calculating modular powers
  944. X    is by repeated squaring and multiplying and dividing by the modulus.
  945. X    The second method uses the REDC algorithm given by Peter Montgomery
  946. X    which avoids divisions.  The argument for pow2 is the size of the
  947. X    modulus at which the second algorithm begins to be used.
  948. X
  949. X    Redc2 specifies the sizes of numbers at which calc switches from
  950. X    its first to its second algorithm when using the REDC algorithm.
  951. X    The first algorithm performs a multiply and a modular reduction
  952. X    together in one loop which runs in O(N^2).  The second algorithm
  953. X    does the REDC calculation using three multiplies, and runs in
  954. X    O(N^1.585).  The argument for redc2 is the size of the modulus at
  955. X    which the second algorithm begins to be used.
  956. X
  957. X    Examples of setting some parameters are:
  958. X
  959. X        config("mode", "exp");        exponential output
  960. X        config("display", 50);        50 digits of output
  961. X        epsilon(epsilon() / 8);        3 bits more accuracy
  962. SHAR_EOF
  963. chmod 0644 calc2.9.0/help/config || echo "restore of calc2.9.0/help/config fails"
  964. set `wc -c calc2.9.0/help/config`;Sum=$1
  965. if test "$Sum" != "4426"
  966. then echo original size 4426, current size $Sum;fi
  967. echo "x - extracting calc2.9.0/help/credit (Text)"
  968. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/credit &&
  969. XCredits
  970. X
  971. X    Written by David I. Bell.
  972. X
  973. X    Thanks for suggestions and encouragement from Peter Miller,
  974. X    Neil Justusson, and Landon Noll.
  975. X
  976. X    Thanks to Stephen Rothwell for writing the original version of
  977. X    hist.c which is used to do the command line editing.
  978. X
  979. X    Thanks to Ernest W. Bowen for supplying some improvements in
  980. X    accuracy and generality for some numeric functions.  Much of
  981. X    this was in terms of actual code which I gratefully accepted.
  982. X
  983. X    Portions of this program are derived from an earlier set of
  984. X    public domain arbitrarily precision routines which was posted
  985. X    to the net around 1984.  By now, there is almost no recognizable 
  986. X    code left from that original source.
  987. X
  988. X    Most of this source and binary is:
  989. X
  990. X        Copyright (c) 1993 David I. Bell
  991. X
  992. X    A few files are a joint copyright between David I. Bell and Landon Noll.
  993. X
  994. X    Permission is granted to use, distribute, or modify this source,
  995. X    provided that this copyright notice remains intact.
  996. X
  997. X    Send calc comments, suggestions, bug fixes, enhancements and
  998. X    interesting calc scripts that you would like you see included in
  999. X    future distributions to:
  1000. X
  1001. X        dbell@canb.auug.org.au
  1002. X        chongo@toad.com
  1003. X
  1004. X    Enjoy!
  1005. SHAR_EOF
  1006. chmod 0644 calc2.9.0/help/credit || echo "restore of calc2.9.0/help/credit fails"
  1007. set `wc -c calc2.9.0/help/credit`;Sum=$1
  1008. if test "$Sum" != "1145"
  1009. then echo original size 1145, current size $Sum;fi
  1010. echo "x - extracting calc2.9.0/help/define (Text)"
  1011. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/define &&
  1012. XFunction definitions
  1013. X
  1014. X    Function definitions are introduced by the 'define' keyword.
  1015. X    Other than this, the basic structure of a function is like in C.
  1016. X    That is, parameters are specified for the function within parenthesis,
  1017. X    the function body is introduced by a left brace, variables are
  1018. X    declared for the function, statements implementing the function
  1019. X    follow, and the function is ended with a right brace.
  1020. X
  1021. X    There are some subtle differences, however.  The types of parameters
  1022. X    and variables are not defined at compile time, but instead are typed
  1023. X    at runtime.  Thus there is no definitions needed to distinguish
  1024. X    between integers, fractions, complex numbers, matrices, and so on.
  1025. X    Thus when declaring parameters for a function, only the name of
  1026. X    the parameter is needed.  Thus there are never any declarations
  1027. X    between the function parameter list and the body of the function.
  1028. X
  1029. X    For example, the following function computes a factorial:
  1030. X
  1031. X        define factorial(n)
  1032. X        {
  1033. X            local    ans;
  1034. X
  1035. X            ans = 1;
  1036. X            while (n > 1)
  1037. X                ans *= n--;
  1038. X            return ans;
  1039. X        }
  1040. X
  1041. X    If a function is very simple and just returns a value, then the
  1042. X    function can be defined in shortened manner by using an equals sign
  1043. X    in place of the left brace.  In this case, the function declaration
  1044. X    is terminated by a newline character, and its value is the specified
  1045. X    expression.  Statements such as 'if' are not allowed.  An optional
  1046. X    semicolon ending the expression is allowed.  As an example, the
  1047. X    average of two numbers could be defined as:
  1048. X
  1049. X        define average(a, b) = (a + b) / 2;
  1050. X
  1051. X    Functions can be defined which can be very complex.  These can be
  1052. X    defined on the command line if desired, but editing of partial
  1053. X    functions is not possible past a single line.  If an error is made
  1054. X    on a previous line, then the function must be finished (with probable
  1055. X    errors) and reentered from the beginning.  Thus for complicated
  1056. X    functions, it is best to use an editor to create the function in a
  1057. X    file, and then enter the calculator and read in the file containing
  1058. X    the definition.
  1059. X
  1060. X    The parameters of a function can be referenced by name, as in
  1061. X    normal C usage, or by using the 'param' function.  This function
  1062. X    returns the specified parameter of the function it is in, where
  1063. X    the parameters are numbered starting from 1.  The total number
  1064. X    of parameters to the function is returned by using 'param(0)'.
  1065. X    Using this function allows you to implement varargs-like routines
  1066. X    which can handle any number of calling parameters.  For example:
  1067. X
  1068. X        define sc()
  1069. X        {
  1070. X            local s, i;
  1071. X
  1072. X            s = 0;
  1073. X            for (i = 1; i <= param(0); i++)
  1074. X                s += param(i)^3;
  1075. X            return s;
  1076. X        }
  1077. X
  1078. X    defines a function which returns the sum of the cubes of all it's
  1079. X    parameters.
  1080. SHAR_EOF
  1081. chmod 0644 calc2.9.0/help/define || echo "restore of calc2.9.0/help/define fails"
  1082. set `wc -c calc2.9.0/help/define`;Sum=$1
  1083. if test "$Sum" != "2679"
  1084. then echo original size 2679, current size $Sum;fi
  1085. echo "x - extracting calc2.9.0/help/environment (Text)"
  1086. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/environment &&
  1087. XEnvironment variables
  1088. X
  1089. X    CALCPATH
  1090. X
  1091. X        A :-separated list of directories used to search for
  1092. X        scripts filenames that do not begin with /, ./ or ~.
  1093. X
  1094. X        If this variable does not exist, a compiled value
  1095. X        is used.  Typically compiled in value is:
  1096. X
  1097. X            .:./lib:~/lib:${LIBDIR}/calc
  1098. X    
  1099. X        where ${LIBDIR} is usually:
  1100. X
  1101. X            /usr/lib/calc
  1102. X
  1103. X        This value is used by the READ command.  It is an error
  1104. X        if no such readable file is found.
  1105. X    
  1106. X    
  1107. X    CALCRC
  1108. X
  1109. X        On startup (unless -h or -q was given on the command
  1110. X        line), calc searches for files along the :-separated
  1111. X        $CALCRC environment variable.
  1112. X
  1113. X        If this variable does not exist, a compiled value
  1114. X        is used.  Typically compiled in value is:
  1115. X
  1116. X            ${LIBDIR}/startup:~/.calcrc
  1117. X    
  1118. X        where ${LIBDIR} is usually:
  1119. X
  1120. X            /usr/lib/calc
  1121. X
  1122. X        Missing files along the $CALCRC path are silently ignored.
  1123. X    
  1124. X    CALCBINDINGS
  1125. X
  1126. X        On startup (unless -h or -q was given on the command
  1127. X        line), calc reads key bindings from the filename specified
  1128. X        in the $CALCRC environment variable.  These key bindings
  1129. X        are used for command line editing and the command history.
  1130. X
  1131. X        If this variable does not exist, a compiled value is used.
  1132. X        Typically compiled in value is:
  1133. X
  1134. X            ${LIBDIR}/bindings
  1135. X    
  1136. X        where ${LIBDIR} is usually:
  1137. X
  1138. X            /usr/lib/calc
  1139. X
  1140. X        If the file could not be opened, or if standard input is not
  1141. X        a terminal, then calc will still run, but fancy command line
  1142. X        editing is disabled.
  1143. X
  1144. X    HOME
  1145. X
  1146. X        This value is taken to be the home directory of the
  1147. X        current user.  It is used when files begin with '~/'.
  1148. X
  1149. X        If this variable does not exist, the home directory password 
  1150. X        entry of the current user is used.  If that information
  1151. X        is not available, '.' is used.
  1152. X    
  1153. X    PAGER
  1154. X
  1155. X        When invoking help, this environment variable is used
  1156. X        to display a help file.
  1157. X
  1158. X        If this variable does not exist, a compiled value
  1159. X        is used.  Typically compiled in value is something
  1160. X        such as 'more', 'less', 'pg' or 'cat'.
  1161. X    
  1162. X    SHELL
  1163. X
  1164. X        When a !-command is used, the program indicated by
  1165. X        this environment variable is used.
  1166. X
  1167. X        If this variable does not exist, a compiled value
  1168. X        is used.  Typically compiled in value is something
  1169. X        such as 'sh' is used.
  1170. SHAR_EOF
  1171. chmod 0644 calc2.9.0/help/environment || echo "restore of calc2.9.0/help/environment fails"
  1172. set `wc -c calc2.9.0/help/environment`;Sum=$1
  1173. if test "$Sum" != "2248"
  1174. then echo original size 2248, current size $Sum;fi
  1175. echo "x - extracting calc2.9.0/help/expression (Text)"
  1176. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/expression &&
  1177. XExpression sequences
  1178. X
  1179. X    This is a sequence of statements, of which expression statements
  1180. X    are the commonest case.  Statements are separated with semicolons,
  1181. X    and the newline character generally ends the sequence.  If any
  1182. X    statement is an expression by itself, or is associated with an
  1183. X    'if' statement which is true, then two special things can happen.
  1184. X    If the sequence is executed at the top level of the calculator,
  1185. X    then the value of '.' is set to the value of the last expression.
  1186. X    Also, if an expression is a non-assignment, then the value of the
  1187. X    expression is automatically printed if its value is not NULL.
  1188. X    Some operations such as    pre-increment and plus-equals are also
  1189. X    treated as assignments.
  1190. X
  1191. X    Examples of this are the following:
  1192. X
  1193. X    expression        sets '.' to        prints
  1194. X    ----------        -----------        ------
  1195. X    3+4            7            7
  1196. X    2*4; 8+1; fact(3)    6            8, 9, and 6
  1197. X    x=3^2            9            -
  1198. X    if (3 < 2) 5; else 6    6            6
  1199. X    x++            old x            -
  1200. X    print fact(4)        -            24
  1201. X    null()            null()            -
  1202. X
  1203. X    Variables can be defined at the beginning of an expression sequence.
  1204. X    This is most useful for local variables, as in the following example,
  1205. X    which sums the square roots of the first few numbers:
  1206. X
  1207. X    local s, i; s = 0; for (i = 0; i < 10; i++) s += sqrt(i); s
  1208. X
  1209. X    If a return statement is executed in an expression sequence, then
  1210. X    the result of the expression sequence is the returned value.  In
  1211. X    this case, '.' is set to the value, but nothing is printed.
  1212. SHAR_EOF
  1213. chmod 0644 calc2.9.0/help/expression || echo "restore of calc2.9.0/help/expression fails"
  1214. set `wc -c calc2.9.0/help/expression`;Sum=$1
  1215. if test "$Sum" != "1413"
  1216. then echo original size 1413, current size $Sum;fi
  1217. echo "x - extracting calc2.9.0/help/file (Text)"
  1218. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/file &&
  1219. XUsing files
  1220. X
  1221. X    The calculator provides some functions which allow the program to
  1222. X    read or write text files.  These functions use stdio internally,
  1223. X    and the functions appear similar to some of the stdio functions.
  1224. X    Some differences do occur, as will be explained here.
  1225. X
  1226. X    Names of files are subject to ~ expansion just like the C or
  1227. X    Korn shell.  For example, the file name:
  1228. X
  1229. X        ~/.rc.cal
  1230. X    
  1231. X    refers to the file '.rc.cal' under your home directory.  The
  1232. X    file name:
  1233. X
  1234. X        ~chongo/.rc.cal
  1235. X
  1236. X    refers to the a file 'rc.cal' under the home directory of 'chongo'.
  1237. X
  1238. X    A file can be opened for either reading, writing, or appending.
  1239. X    To do this, the 'fopen' function is used, which accepts a filename
  1240. X    and an open mode, both as strings.  You use 'r' for reading, 'w'
  1241. X    for writing, and 'a' for appending.  For example, to open the file
  1242. X    'foo' for reading, the following could be used:
  1243. X
  1244. X        fd = fopen('foo', 'r');
  1245. X
  1246. X    If the open is unsuccessful, the numeric value of errno is returned.
  1247. X    If the open is successful, a value of type 'file' will be returned.
  1248. X    You can use the 'isfile' function to test the return value to see
  1249. X    if the open succeeded.  You should assign the return value of fopen
  1250. X    to a variable for later use.  File values can be copied to more than
  1251. X    one variable, and using any of the variables with the same file value
  1252. X    will produce the same results.
  1253. X
  1254. X    If you overwrite a variable containing a file value or don't save the
  1255. X    result of an 'fopen', the opened file still remains open.  Such 'lost'
  1256. X    files can be recovered by using the 'files' function.  This function
  1257. X    either takes no arguments or else takes one integer argument.  If no
  1258. X    arguments are given, then 'files' returns the maximum number of opened
  1259. X    files.  If an argument is given, then the 'files' function uses it as
  1260. X    an index into an internal table of open files, and returns a value
  1261. X    referring to one the open files.  If that entry in the table is not
  1262. X    in use, then the null value is returned instead.  Index 0 always
  1263. X    refers to standard input, index 1 always refers to standard output,
  1264. X    and index 2 always refers to standard error.  These three files are
  1265. X    already open by the calculator and cannot be closed.  As an example
  1266. X    of using 'files', if you wanted to assign a file value which is
  1267. X    equivalent to stdout, you could use:
  1268. X
  1269. X        stdout = files(1);
  1270. X
  1271. X    The 'fclose' function is used to close a file which had been opened.
  1272. X    When this is done, the file value associated with the file remains
  1273. X    a file value, but appears 'closed', and cannot be used in further
  1274. X    file-related calls (except fclose) without causing errors.  This same
  1275. X    action occurs to all copies of the file value.  You do not need to
  1276. X    explicitly close all the copies of a file value.  The 'fclose'
  1277. X    function returns the numeric value of errno if there had been an
  1278. X    error using the file, or the null value if there was no error.
  1279. X
  1280. X    File values can be printed.  When this is done, the filename of the
  1281. X    opened file is printed inside of quote marks.  If the file value had
  1282. X    been closed, then the null string is printed.  If a file value is the
  1283. X    result of a top-level expression, then in addition to the filename,
  1284. X    the open mode, file position, and possible EOF, error, and closed
  1285. X    status is also displayed.
  1286. X
  1287. X    File values can be used inside of 'if' tests.  When this is done,
  1288. X    an opened file is TRUE, and a closed file is FALSE.  As an example
  1289. X    of this, the following loop will print the names of all the currently
  1290. X    opened non-standard files with their indexes, and then close them:
  1291. X
  1292. X        for (i = 3; i < files(); i++) {
  1293. X            if (files(i)) {
  1294. X                print i, files(i);
  1295. X                fclose(files(i));
  1296. X            }
  1297. X        }
  1298. X
  1299. X    The functions to read from files are 'fgetline' and 'fgetc'.
  1300. X    The 'fgetline' function accepts a file value, and returns the next
  1301. X    input line from a file.  The line is returned as a string value, and
  1302. X    does not contain the end of line character.  Empty lines return the
  1303. X    null string.  When the end of file is reached, fgetline returns the
  1304. X    null value.  (Note the distinction between a null string and a null
  1305. X    value.)  If the line contained a numeric value, then the 'eval'
  1306. X    function can then be used to convert the string to a numeric value.
  1307. X    Care should be used when doing this, however, since eval will
  1308. X    generate an error if the string doesn't represent a valid expression.
  1309. X    The 'fgetc' function returns the next character from a file as a
  1310. X    single character string.  It returns the null value when end of file
  1311. X    is reached.
  1312. X
  1313. X    The 'printf' and 'fprintf' functions are used to print results to a
  1314. X    file (which could be stdout or stderr).  The 'fprintf' function
  1315. X    accepts a file variable, whereas the 'printf' function assumes the
  1316. X    use of 'files(1)' (stdout).  They both require a format string, which
  1317. X    is used in almost the same way as in normal C.  The differences come
  1318. X    in the interpretation of values to be printed for various formats.
  1319. X    Unlike in C, where an unmatched format type and value will cause
  1320. X    problems, in the calculator nothing bad will happen.  This is because
  1321. X    the calculator knows the types of all values, and will handle them
  1322. X    all reasonably.  What this means is that you can (for example), always
  1323. X    use %s or %d in your format strings, even if you are printing a non-
  1324. X    string or non-numeric value.  For example, the following is valid:
  1325. X
  1326. X        printf("Two values are %d and %s\n", "fred", 4567);
  1327. X
  1328. X    and will print "Two values are fred and 4567".
  1329. X
  1330. X    Using particular format characters, however, is still useful if
  1331. X    you wish to use width or precision arguments in the format, or if
  1332. X    you wish to print numbers in a particular format.  The following
  1333. X    is a list of the possible numeric formats:
  1334. X
  1335. X        %d        print in currently defined numeric format
  1336. X        %f        print as floating point
  1337. X        %e        print as exponential
  1338. X        %r        print as decimal fractions
  1339. X        %x        print as hex fractions
  1340. X        %o        print as octal fractions
  1341. X        %b        print as binary fractions
  1342. X
  1343. X    Note then, that using %d in the format makes the output configurable
  1344. X    by using the 'config' function to change the output mode, whereas
  1345. X    the other formats override the mode and force the output to be in
  1346. X    the specified format.
  1347. X
  1348. X    Using the precision argument will override the 'config' function
  1349. X    to set the number of decimal places printed.  For example:
  1350. X
  1351. X        printf("The number is %.100f\n", 1/3);
  1352. X
  1353. X    will print 100 decimal places no matter what the display configuration
  1354. X    value is set to.
  1355. X
  1356. X    The %s and %c formats are identical, and will print out the string
  1357. X    representation of the value.  In these cases, the precision argument
  1358. X    will truncate the output the same way as in standard C.
  1359. X
  1360. X    If a matrix or list is printed, then the output mode and precision
  1361. X    affects the printing of each individual element.  However, field
  1362. X    widths are ignored since these values print using multiple lines.
  1363. X    Field widths are also ignored if an object value prints on multiple
  1364. X    lines.
  1365. X
  1366. X    The final file-related functions are 'fflush', 'ferror', and 'feof'.
  1367. X    The 'fflush' function forces buffered output to a file.  The 'ferror'
  1368. X    function returns nonzero if an error had occurred to a file.  The
  1369. X    'feof' function returns nonzero if end of file has been reached
  1370. X    while reading a file.
  1371. X
  1372. X    The 'strprintf' function formats output similarly to 'printf',
  1373. X    but the output is returned as a string value instead of being
  1374. X    printed.
  1375. SHAR_EOF
  1376. chmod 0644 calc2.9.0/help/file || echo "restore of calc2.9.0/help/file fails"
  1377. set `wc -c calc2.9.0/help/file`;Sum=$1
  1378. if test "$Sum" != "7229"
  1379. then echo original size 7229, current size $Sum;fi
  1380. echo "x - extracting calc2.9.0/help/help (Text)"
  1381. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/help &&
  1382. XFor more information while running calc, type  help  followed by one of the
  1383. Xfollowing topics:
  1384. X
  1385. X    topic        description
  1386. X    -----        -----------
  1387. X    intro        introduction to calc
  1388. X    overview    overview of calc
  1389. X
  1390. X    assoc        using associations
  1391. X    bindings    input & history character bindings
  1392. X    builtin        builtin functions
  1393. X    command        top level commands
  1394. X    config        configuration parameters
  1395. X    define        how to define functions
  1396. X    environment    how environment variables effect calc
  1397. X    expression    expression sequences
  1398. X    file        using files
  1399. X    history        command history
  1400. X    interrupt    how interrupts are handled
  1401. X    list        using lists
  1402. X    mat        using matrices
  1403. X    obj        user defined data types
  1404. X    operator    math, relational, logic and variable access operators
  1405. X    statement    flow control and declaration statements
  1406. X    stdlib        description of some lib files shipped with calc
  1407. X    types        builtin data types
  1408. X    usage        how to invoke the calc command
  1409. X    variable    variables and variable declarations
  1410. X
  1411. X    changes        recent changes to calc
  1412. X    credit        who wrote calc, and who helped, copyright
  1413. X    help        this file
  1414. X    libcalc        using the arbitrary precision routines in a C program
  1415. X    todo        needed enhancements and wish list
  1416. X
  1417. XFor example:
  1418. X
  1419. X    help usage
  1420. X
  1421. Xwill print the calc command usage information.  One can obtain calc help
  1422. Xwithout invoking any startup code by running calc as follows:
  1423. X
  1424. X    calc -q help topic
  1425. X
  1426. Xwhere 'topic' is one of the topics listed above.
  1427. SHAR_EOF
  1428. chmod 0644 calc2.9.0/help/help || echo "restore of calc2.9.0/help/help fails"
  1429. set `wc -c calc2.9.0/help/help`;Sum=$1
  1430. if test "$Sum" != "1350"
  1431. then echo original size 1350, current size $Sum;fi
  1432. echo "x - extracting calc2.9.0/help/history (Text)"
  1433. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/history &&
  1434. XCommand history
  1435. X
  1436. X    There is a command line editor and history mechanism built
  1437. X    into calc, which is active when stdin is a terminal.  When
  1438. X    stdin is not a terminal, then the command line editor is
  1439. X    disabled.
  1440. X
  1441. X    Lines of input to calc are always terminated by the return
  1442. X    (or enter) key.  When the return key is typed, then the current
  1443. X    line is executed and is also saved into a command history list
  1444. X    for future recall.
  1445. X
  1446. X    Before the return key is typed, the current line can be edited
  1447. X    using emacs-like editing commands.  As examples, ^A moves to
  1448. X    the beginning of the line, ^F moves forwards through the line,
  1449. X    backspace removes characters from the line, and ^K kills the
  1450. X    rest of the line.
  1451. X
  1452. X    Previously entered commands can be recalled by using the history
  1453. X    list.  The history list functions in a LRU manner, with no
  1454. X    duplicated lines.  This means that the most recently entered
  1455. X    lines are always at the end of the history list where they are
  1456. X    easiest to recall.
  1457. X
  1458. X    Typing <esc>h lists all of the commands in the command history
  1459. X    and numbers the lines.  The most recently executed line is always
  1460. X    number 1, the next most recent number 2, and so on.  The numbering
  1461. X    for a particular command therefore changes as lines are entered.
  1462. X
  1463. X    Typing a number at the beginning of a line followed by <esc>g
  1464. X    will recall that numbered line.  So that for example, 2<esc>g
  1465. X    will recall the second most recent line that was entered.
  1466. X
  1467. X    The ^P and ^N keys move up and down the lines in the history list.
  1468. X    If they attempt to go off the top or bottom of the list, then a
  1469. X    blank line is shown to indicate this, and then they wrap around
  1470. X    to the other end of the list.
  1471. X
  1472. X    Typing a string followed by a ^R will search backwards through
  1473. X    the history and recall the most recent command which begins
  1474. X    with that string.
  1475. X
  1476. X    Typing ^O inserts the current line at the end of the history list
  1477. X    without executing it, and starts a new line.  This is useful to
  1478. X    rearrange old history lines to become recent, or to save a partially
  1479. X    completed command so that another command can be typed ahead of it.
  1480. X
  1481. X    If your terminal has arrow keys which generate escape sequences
  1482. X    of a particular kind (<esc>[A and so on), then you can use
  1483. X    those arrow keys in place of the ^B, ^F, ^P, and ^N keys.
  1484. X
  1485. X    The actual keys used for editing are defined in a bindings file,
  1486. X    called /usr/lib/calc/bindings.  Changing the entries in this file
  1487. X    will change the key bindings used for editing.  If the file
  1488. X    is not readable, then a message will be output and command
  1489. X    line editing is disabled.  In this case you can only edit each
  1490. X    line as provided by the terminal driver in the operating system.
  1491. X
  1492. X    A shell command can be executed by typing '!cmd', where cmd
  1493. X    is the command to execute.  If cmd is not given, then a shell
  1494. X    command level is started.
  1495. SHAR_EOF
  1496. chmod 0644 calc2.9.0/help/history || echo "restore of calc2.9.0/help/history fails"
  1497. set `wc -c calc2.9.0/help/history`;Sum=$1
  1498. if test "$Sum" != "2782"
  1499. then echo original size 2782, current size $Sum;fi
  1500. echo "x - extracting calc2.9.0/help/interrupt (Text)"
  1501. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/interrupt &&
  1502. XInterrupts
  1503. X
  1504. X    While a calculation is in progress, you can generate the SIGINT
  1505. X    signal, and the calculator will catch it.  At appropriate points
  1506. X    within a calculation, the calculator will check that the signal
  1507. X    has been given, and will abort the calculation cleanly.  If the
  1508. X    calculator is in the middle of a large calculation, it might be
  1509. X    a while before the interrupt has an effect.
  1510. X
  1511. X    You can generate the SIGINT signal multiple times if necessary,
  1512. X    and each time the calculator will abort the calculation at a more
  1513. X    risky place within the calculation.  Each new interrupt prints a
  1514. X    message of the form:
  1515. X
  1516. X        [Abort level n]
  1517. X
  1518. X    where n ranges from 1 to 3.  For n equal to 1, the calculator will
  1519. X    abort calculations at the next statement boundary.  For n equal to 2,
  1520. X    the calculator will abort calculations at the next opcode boundary.
  1521. X    For n equal to 3, the calculator will abort calculations at the next
  1522. X    lowest level arithmetic operation boundary.
  1523. X
  1524. X    If a final interrupt is given when n is 3, the calculator will
  1525. X    immediately abort the current calculation and longjmp back to the
  1526. X    top level command level.  Doing this may result in corrupted data
  1527. X    structures and unpredictable future behavior, and so should only
  1528. X    be done as a last resort.  You are advised to quit the calculator
  1529. X    after this has been done.
  1530. SHAR_EOF
  1531. chmod 0644 calc2.9.0/help/interrupt || echo "restore of calc2.9.0/help/interrupt fails"
  1532. set `wc -c calc2.9.0/help/interrupt`;Sum=$1
  1533. if test "$Sum" != "1306"
  1534. then echo original size 1306, current size $Sum;fi
  1535. echo "x - extracting calc2.9.0/help/intro (Text)"
  1536. sed 's/^X//' << 'SHAR_EOF' > calc2.9.0/help/intro &&
  1537. XQuick introduction
  1538. X
  1539. X    This is an interactive calculator which provides for easy large
  1540. X    numeric calculations, but which also can be easily programmed
  1541. X    for difficult or long calculations.  It can accept a command line
  1542. X    argument, in which case it executes that single command and exits.
  1543. X    Otherwise, it enters interactive mode.  In this mode, it accepts
  1544. X    commands one at a time, processes them, and displays the answers.
  1545. X    In the simplest case, commands are simply expressions which are
  1546. X    evaluated.  For example, the following line can be input:
  1547. X
  1548. X        3 * (4 + 1)
  1549. X
  1550. X    and the calculator will print 15.
  1551. X
  1552. X    The special '.' symbol (called dot), represents the result of the
  1553. X    last command expression, if any.  This is of great use when a series
  1554. X    of partial results are calculated, or when the output mode is changed
  1555. X    and the last result needs to be redisplayed.  For example, the above
  1556. X    result can be doubled by typing:
  1557. X
  1558. X        . * 2
  1559. X
  1560. X    and the calculator will print 30.
  1561. X
  1562. X    For more complex calculations, variables can be used to save the
  1563. X    intermediate results.  For example, the result of adding 7 to the
  1564. X    previous result can be saved by typing:
  1565. X
  1566. X        old = . + 7
  1567. X
  1568. X    Functions can be used in expressions.  There are a great number of
  1569. X    pre-defined functions.  For example, the following will calculate
  1570. X    the factorial of the value of 'old':
  1571. SHAR_EOF
  1572. echo "End of part 14"
  1573. echo "File calc2.9.0/help/intro is continued in part 15"
  1574. echo "15" > s2_seq_.tmp
  1575. exit 0
  1576.