home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / libgpp.i03 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  49KB  |  1,014 lines

  1. This is Info file libgpp, produced by Makeinfo-1.47 from the input file
  2. libgpp.tex.
  3. START-INFO-DIR-ENTRY
  4. * Libg++: (libg++).        The g++ library.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the features and implementation of The GNU C++
  7. library
  8.    Copyright (C) 1988, 1991, 1992 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the section entitled "GNU Library General Public License" is
  15. included exactly as in the original, and provided that the entire
  16. resulting derived work is distributed under the terms of a permission
  17. notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that the section entitled "GNU Library General Public
  21. License" and this permission notice may be included in translations
  22. approved by the Free Software Foundation instead of in the original
  23. English.
  24. File: libgpp,  Node: Obstack,  Next: AllocRing,  Prev: Stream,  Up: Top
  25. The Obstack class
  26. *****************
  27.    The `Obstack' class is a simple rewrite of the C obstack macros and
  28. functions provided in the GNU CC compiler source distribution.
  29.    Obstacks provide a simple method of creating and maintaining a string
  30. table, optimized for the very frequent task of building strings
  31. character-by-character, and sometimes keeping them, and sometimes not.
  32. They seem especially useful in any parsing application. One of the test
  33. files demonstrates usage.
  34.    A brief summary:
  35. `grow'
  36.      places something on the obstack without committing to wrap it up
  37.      as a single entity yet.
  38. `finish'
  39.      wraps up a constructed object as a single entity, and returns the
  40.      pointer to its start address.
  41. `copy'
  42.      places things on the obstack, and *does* wrap them up. `copy' is
  43.      always equivalent to first grow, then finish.
  44. `free'
  45.      deletes something, and anything else put on the obstack since its
  46.      creation.
  47.    The other functions are less commonly needed:
  48. `blank'
  49.      is like grow, except it just grows the space by size units without
  50.      placing anything into this space
  51. `alloc'
  52.      is like `blank', but it wraps up the object and returns its
  53.      starting address.
  54. `chunk_size, base, next_free, alignment_mask, size, room'
  55.      returns the appropriate class variables.
  56. `grow_fast'
  57.      places a character on the obstack without checking if there is
  58.      enough room.
  59. `blank_fast'
  60.      like `blank', but without checking if there is enough room.
  61. `shrink(int n)'
  62.      shrink the current chunk by n bytes.
  63. `contains(void* addr)'
  64.      returns true if the Obstack holds the address addr.
  65.    Here is a lightly edited version of the original C documentation:
  66.    These functions operate a stack of objects.  Each object starts life
  67. small, and may grow to maturity.  (Consider building a word syllable by
  68. syllable.)  An object can move while it is growing.  Once it has been
  69. "finished" it never changes address again.  So the "top of the stack"
  70. is typically an immature growing object, while the rest of the stack is
  71. of mature, fixed size and fixed address objects.
  72.    These routines grab large chunks of memory, using the GNU C++ `new'
  73. operator.  On occasion, they free chunks, via `delete'.
  74.    Each independent stack is represented by a Obstack.
  75.    One motivation for this package is the problem of growing char
  76. strings in symbol tables.  Unless you are a "fascist pig with a
  77. read-only mind" [Gosper's immortal quote from HAKMEM item 154, out of
  78. context] you would not like to put any arbitrary upper limit on the
  79. length of your symbols.
  80.    In practice this often means you will build many short symbols and a
  81. few long symbols.  At the time you are reading a symbol you don't know
  82. how long it is.  One traditional method is to read a symbol into a
  83. buffer, `realloc()'ating the buffer every time you try to read a symbol
  84. that is longer than the buffer.  This is beaut, but you still will want
  85. to copy the symbol from the buffer to a more permanent symbol-table
  86. entry say about half the time.
  87.    With obstacks, you can work differently.  Use one obstack for all
  88. symbol names.  As you read a symbol, grow the name in the obstack
  89. gradually. When the name is complete, finalize it.  Then, if the symbol
  90. exists already, free the newly read name.
  91.    The way we do this is to take a large chunk, allocating memory from
  92. low addresses.  When you want to build a symbol in the chunk you just
  93. add chars above the current "high water mark" in the chunk.  When you
  94. have finished adding chars, because you got to the end of the symbol,
  95. you know how long the chars are, and you can create a new object.
  96. Mostly the chars will not burst over the highest address of the chunk,
  97. because you would typically expect a chunk to be (say) 100 times as
  98. long as an average object.
  99.    In case that isn't clear, when we have enough chars to make up the
  100. object, *they are already contiguous in the chunk* (guaranteed) so we
  101. just point to it where it lies.  No moving of chars is needed and this
  102. is the second win: potentially long strings need never be explicitly
  103. shuffled. Once an object is formed, it does not change its address
  104. during its lifetime.
  105.    When the chars burst over a chunk boundary, we allocate a larger
  106. chunk, and then copy the partly formed object from the end of the old
  107. chunk to the beginning of the new larger chunk.  We then carry on
  108. accreting characters to the end of the object as we normally would.
  109.    A special version of grow is provided to add a single char at a time
  110. to a growing object.
  111.    Summary:
  112.    * We allocate large chunks.
  113.    * We carve out one object at a time from the current chunk.
  114.    * Once carved, an object never moves.
  115.    * We are free to append data of any size to the currently growing
  116.      object.
  117.    * Exactly one object is growing in an obstack at any one time.
  118.    * You can run one obstack per control block.
  119.    * You may have as many control blocks as you dare.
  120.    * Because of the way we do it, you can `unwind' a obstack back to a
  121.      previous state. (You may remove objects much as you would with a
  122.      stack.)
  123.    The obstack data structure is used in many places in the GNU C++
  124. compiler.
  125.    Differences from the the GNU C version
  126.   1. The obvious differences stemming from the use of classes and
  127.      inline functions instead of structs and macros. The C `init' and
  128.      `begin' macros are replaced by constructors.
  129.   2. Overloaded function names are used for grow (and others), rather
  130.      than the C `grow', `grow0', etc.
  131.   3. All dynamic allocation uses the the built-in `new' operator. This
  132.      restricts flexibility by a little, but maintains compatibility
  133.      with usual C++ conventions.
  134.   4. There are now two versions of finish:
  135.        1. finish() behaves like the C version.
  136.        2. finish(char terminator) adds `terminator', and then calls
  137.           `finish()'.  This enables the normal invocation of
  138.           `finish(0)' to wrap up a string being grown
  139.           character-by-character.
  140.   5. There are special versions of grow(const char* s) and copy(const
  141.      char* s) that add the null-terminated string `s' after computing
  142.      its length.
  143.   6. The shrink and contains functions are provided.
  144. File: libgpp,  Node: AllocRing,  Next: String,  Prev: Obstack,  Up: Top
  145. The AllocRing class
  146. *******************
  147.    An AllocRing is a bounded ring (circular list), each of whose
  148. elements contains a pointer to some space allocated via `new
  149. char[some_size]'. The entries are used cyclicly.  The size, n, of the
  150. ring is fixed at construction. After that, every nth use of the ring
  151. will reuse (or reallocate) the same space. AllocRings are needed in
  152. order to temporarily hold chunks of space that are needed transiently,
  153. but across constructor-destructor scopes. They mainly useful for storing
  154. strings containing formatted characters to print acrosss various
  155. functions and coercions. These strings are needed across routines, so
  156. may not be deleted in any one of them, but should be recovered at some
  157. point. In other words, an AllocRing is an extremely simple minded
  158. garbage collection mechanism. The GNU C++ library used to use one
  159. AllocRing for such formatting purposes, but it is being phased out, and
  160. is now only used by obsolete functions. These days, AllocRings are
  161. probably not very useful.
  162.    Support includes:
  163. `AllocRing a(int n)'
  164.      constructs an Alloc ring with n entries, all null.
  165. `void* mem = a.alloc(sz)'
  166.      moves the ring pointer to the next entry, and reuses the space if
  167.      their is enough, also allocates space via new char[sz].
  168. `int present = a.contains(void* ptr)'
  169.      returns true if ptr is held in one of the ring entries.
  170. `a.clear()'
  171.      deletes all space pointed to in any entry. This is called
  172.      automatically upon destruction.
  173. `a.free(void* ptr)'
  174.      If ptr is one of the entries, calls delete of the pointer, and
  175.      resets to entry pointer to null.
  176. File: libgpp,  Node: String,  Next: Integer,  Prev: AllocRing,  Up: Top
  177. The String class
  178. ****************
  179.    The `String' class is designed to extend GNU C++ to support string
  180. processing capabilities similar to those in languages like Awk.  The
  181. class provides facilities that ought to be convenient and efficient
  182. enough to be useful replacements for `char*' based processing via the C
  183. string library (i.e., `strcpy, strcmp,' etc.) in many applications.
  184. Many details about String representations are described in the
  185. Representation section.
  186.    A separate `SubString' class supports substring extraction and
  187. modification operations. This is implemented in a way that user
  188. programs never directly construct or represent substrings, which are
  189. only used indirectly via String operations.
  190.    Another separate class, `Regex' is also used indirectly via String
  191. operations in support of regular expression searching, matching, and the
  192. like.  The Regex class is based entirely on the GNU Emacs regex
  193. functions.  *Note Syntax of Regular Expressions: (emacs.info)Regexps,
  194. for a full explanation of regular expression syntax.  (For
  195. implementation details, see the internal documentation in files
  196. `regex.h' and `regex.c'.)
  197. Constructors
  198. ============
  199.    Strings are initialized and assigned as in the following examples:
  200. `String x;  String y = 0; String z = "";'
  201.      Set x, y, and z to the nil string. Note that either 0 or "" may
  202.      always be used to refer to the nil string.
  203. `String x = "Hello"; String y("Hello");'
  204.      Set x and y to a copy of the string "Hello".
  205. `String x = 'A'; String y('A');'
  206.      Set x and y to the string value "A"
  207. `String u = x; String v(x);'
  208.      Set u and v to the same string as String x
  209. `String u = x.at(1,4); String v(x.at(1,4));'
  210.      Set u and v to the length 4 substring of x starting at position 1
  211.      (counting indexes from 0).
  212. `String x("abc", 2);'
  213.      Sets x to "ab", i.e., the first 2 characters of "abc".
  214. `String x = dec(20);'
  215.      Sets x to "20". As here, Strings may be initialized or assigned
  216.      the results of any `char*' function.
  217.    There are no directly accessible forms for declaring SubString
  218. variables.
  219.    The declaration `Regex r("[a-zA-Z_][a-zA-Z0-9_]*");' creates a
  220. compiled regular expression suitable for use in String operations
  221. described below. (In this case, one that matches any C++ identifier).
  222. The first argument may also be a String. Be careful in distinguishing
  223. the role of backslashes in quoted GNU C++ char* constants versus those
  224. in Regexes. For example, a Regex that matches either one or more tabs
  225. or all strings beginning with "ba" and ending with any number of
  226. occurrences of "na" could be declared as `Regex r =
  227. "\\(\t+\\)\\|\\(ba\\(na\\)*\\)"' Note that only one backslash is needed
  228. to signify the tab, but two are needed for the parenthesization and
  229. virgule, since the GNU C++ lexical analyzer decodes and strips
  230. backslashes before they are seen by Regex.
  231.    There are three additional optional arguments to the Regex
  232. constructor that are less commonly useful:
  233. `fast (default 0)'
  234.      `fast' may be set to true (1) if the Regex should be
  235.      "fast-compiled". This causes an additional compilation step that
  236.      is generally worthwhile if the Regex will be used many times.
  237. `bufsize (default max(40, length of the string))'
  238.      This is an estimate of the size of the internal compiled
  239.      expression. Set it to a larger value if you know that the
  240.      expression will require a lot of space. If you do not know, do not
  241.      worry: realloc is used if necessary.
  242. `transtable (default none == 0)'
  243.      The address of a byte translation table (a char[256]) that
  244.      translates each character before matching.
  245.    As a convenience, several Regexes are predefined and usable in any
  246. program. Here are their declarations from `String.h'.
  247.      extern Regex RXwhite;      // = "[ \n\t]+"
  248.      extern Regex RXint;        // = "-?[0-9]+"
  249.      extern Regex RXdouble;     // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
  250.                                 //    \\([0-9]+\\)\\|
  251.                                 //    \\(\\.[0-9]+\\)\\)
  252.                                 //    \\([eE][---+]?[0-9]+\\)?"
  253.      extern Regex RXalpha;      // = "[A-Za-z]+"
  254.      extern Regex RXlowercase;  // = "[a-z]+"
  255.      extern Regex RXuppercase;  // = "[A-Z]+"
  256.      extern Regex RXalphanum;   // = "[0-9A-Za-z]+"
  257.      extern Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
  258. Examples
  259. ========
  260.    Most `String' class capabilities are best shown via example. The
  261. examples below use the following declarations.
  262.          String x = "Hello";
  263.          String y = "world";
  264.          String n = "123";
  265.          String z;
  266.          char*  s = ",";
  267.          String lft, mid, rgt;
  268.          Regex  r = "e[a-z]*o";
  269.          Regex  r2("/[a-z]*/");
  270.          char   c;
  271.          int    i, pos, len;
  272.          double f;
  273.          String words[10];
  274.          words[0] = "a";
  275.          words[1] = "b";
  276.          words[2] = "c";
  277. Comparing, Searching and Matching
  278. =================================
  279.    The usual lexicographic relational operators (`==, !=, <, <=, >, >=')
  280. are defined. A functional form `compare(String, String)' is also
  281. provided, as is `fcompare(String, String)', which compares Strings
  282. without regard for upper vs. lower case.
  283.    All other matching and searching operations are based on some form
  284. of the (non-public) `match' and `search' functions.  `match' and
  285. `search' differ in that `match' attempts to match only at the given
  286. starting position, while `search' starts at the position, and then
  287. proceeds left or right looking for a match.  As seen in the following
  288. examples, the second optional `startpos' argument to functions using
  289. `match' and `search' specifies the starting position of the search: If
  290. non-negative, it results in a left-to-right search starting at position
  291. `startpos', and if negative, a right-to-left search starting at
  292. position `x.length() + startpos'. In all cases, the index returned is
  293. that of the beginning of the match, or -1 if there is no match.
  294.    Three String functions serve as front ends to `search' and `match'.
  295. `index' performs a search, returning the index, `matches' performs a
  296. match, returning nonzero (actually, the length of the match) on success,
  297. and `contains' is a boolean function performing either a search or
  298. match, depending on whether an index argument is provided:
  299. `x.index("lo")'
  300.      returns the zero-based index of the leftmost occurrence of
  301.      substring "lo" (3, in this case).  The argument may be a String,
  302.      SubString, char, char*, or Regex.
  303. `x.index("l", 2)'
  304.      returns the index of the first of the leftmost occurrence of "l"
  305.      found starting the search at position x[2], or 2 in this case.
  306. `x.index("l", -1)'
  307.      returns the index of the rightmost occurrence of "l", or 3 here.
  308. `x.index("l", -3)'
  309.      returns the index of the rightmost occurrence of "l" found by
  310.      starting the search at the 3rd to the last position of x,
  311.      returning 2 in this case.
  312. `pos = r.search("leo", 3, len, 0)'
  313.      returns the index of r in the `char*' string of length 3, starting
  314.      at position 0, also placing the  length of the match in reference
  315.      parameter len.
  316. `x.contains("He")'
  317.      returns nonzero if the String x contains the substring "He". The
  318.      argument may be a String, SubString, char, char*, or Regex.
  319. `x.contains("el", 1)'
  320.      returns nonzero if x contains the substring "el" at position 1. As
  321.      in this example, the second argument to `contains', if present,
  322.      means to match the substring only at that position, and not to
  323.      search elsewhere in the string.
  324. `x.contains(RXwhite);'
  325.      returns nonzero if x contains any whitespace (space, tab, or
  326.      newline). Recall that `RXwhite' is a global whitespace Regex.
  327. `x.matches("lo", 3)'
  328.      returns nonzero if x starting at position 3 exactly matches "lo",
  329.      with no trailing characters (as it does in this example).
  330. `x.matches(r)'
  331.      returns nonzero if String x as a whole matches Regex r.
  332. `int f = x.freq("l")'
  333.      returns the number of distinct, nonoverlapping matches to the
  334.      argument (2 in this case).
  335. Substring extraction
  336. ====================
  337.    Substrings may be extracted via the `at', `before', `through',
  338. `from', and `after' functions. These behave as either lvalues or
  339. rvalues.
  340. `z = x.at(2, 3)'
  341.      sets String z to be equal to the length 3 substring of String x
  342.      starting at zero-based position 2, setting z to "llo" in this
  343.      case. A nil String is returned if the arguments don't make sense.
  344. `x.at(2, 2) = "r"'
  345.      Sets what was in positions 2 to 3 of x to "r", setting x to "Hero"
  346.      in this case. As indicated here, SubString assignments may be of
  347.      different lengths.
  348. `x.at("He") = "je";'
  349.      x("He") is the substring of x that matches the first occurrence of
  350.      it's argument. The substitution sets x to "jello". If "He" did not
  351.      occur, the substring would be nil, and the assignment would have
  352.      no effect.
  353. `x.at("l", -1) = "i";'
  354.      replaces the rightmost occurrence of "l" with "i", setting x to
  355.      "Helio".
  356. `z = x.at(r)'
  357.      sets String z to the first match in x of Regex r, or "ello" in this
  358.      case. A nil String is returned if there is no match.
  359. `z = x.before("o")'
  360.      sets z to the part of x to the left of the first occurrence of
  361.      "o", or "Hell" in this case. The argument may also be a String,
  362.      SubString, or Regex.  (If there is no match, z is set to "".)
  363. `x.before("ll") = "Bri";'
  364.      sets the part of x to the left of "ll" to "Bri", setting x to
  365.      "Brillo".
  366. `z = x.before(2)'
  367.      sets z to the part of x to the left of x[2], or "He" in this case.
  368. `z = x.after("Hel")'
  369.      sets z to the part of x to the right of "Hel", or "lo" in this
  370.      case.
  371. `z = x.through("el")'
  372.      sets z to the part of x up and including "el", or "Hel" in this
  373.      case.
  374. `z = x.from("el")'
  375.      sets z to the part of x from "el" to the end, or "ello" in this
  376.      case.
  377. `x.after("Hel") = "p";'
  378.      sets x to "Help";
  379. `z = x.after(3)'
  380.      sets z to the part of x to the right of x[3] or "o" in this case.
  381. `z = "  ab c"; z = z.after(RXwhite)'
  382.      sets z to the part of its old string to the right of the first
  383.      group of whitespace, setting z to "ab c"; Use gsub(below) to strip
  384.      out multiple occurrences of whitespace or any pattern.
  385. `x[0] = 'J';'
  386.      sets the first element of x to 'J'. x[i] returns a reference to
  387.      the ith element of x, or triggers an error if i is out of range.
  388. `common_prefix(x, "Help")'
  389.      returns the String containing the common prefix of the two Strings
  390.      or "Hel" in this case.
  391. `common_suffix(x, "to")'
  392.      returns the String containing the common suffix of the two Strings
  393.      or "o" in this case.
  394. Concatenation
  395. =============
  396. `z = x + s + ' ' + y.at("w") + y.after("w") + ".";'
  397.      sets z to "Hello, world."
  398. `x += y;'
  399.      sets x to "Helloworld"
  400. `cat(x, y, z)'
  401.      A faster way to say z = x + y.
  402. `cat(z, y, x, x)'
  403.      Double concatenation; A faster way to say x = z + y + x.
  404. `y.prepend(x);'
  405.      A faster way to say y = x + y.
  406. `z = replicate(x, 3);'
  407.      sets z to "HelloHelloHello".
  408. `z = join(words, 3, "/")'
  409.      sets z to the concatenation of the first 3 Strings in String array
  410.      words, each separated by "/", setting z to "a/b/c" in this case. 
  411.      The last argument may be "" or 0, indicating no separation.
  412. Other manipulations
  413. ===================
  414. `z = "this string has five words"; i = split(z, words, 10, RXwhite);'
  415.      sets up to 10 elements of String array words to the parts of z
  416.      separated by whitespace, and returns the number of parts actually
  417.      encountered (5 in this case). Here, words[0] = "this", words[1] =
  418.      "string", etc.  The last argument may be any of the usual. If
  419.      there is no match, all of z ends up in words[0]. The words array
  420.      is *not* dynamically created by split.
  421. `int nmatches x.gsub("l","ll")'
  422.      substitutes all original occurrences of "l" with "ll", setting x
  423.      to "Hellllo". The first argument may be any of the usual,
  424.      including Regex.  If the second argument is "" or 0, all
  425.      occurrences are deleted. gsub returns the number of matches that
  426.      were replaced.
  427. `z = x + y;  z.del("loworl");'
  428.      deletes the leftmost occurrence of "loworl" in z, setting z to
  429.      "Held".
  430. `z = reverse(x)'
  431.      sets z to the reverse of x, or "olleH".
  432. `z = upcase(x)'
  433.      sets z to x, with all letters set to uppercase, setting z to
  434.      "HELLO"
  435. `z = downcase(x)'
  436.      sets z to x, with all letters set to lowercase, setting z to
  437.      "hello"
  438. `z = capitalize(x)'
  439.      sets z to x, with the first letter of each word set to uppercase,
  440.      and all others to lowercase, setting z to "Hello"
  441. `x.reverse(), x.upcase(), x.downcase(), x.capitalize()'
  442.      in-place, self-modifying versions of the above.
  443. Reading, Writing and Conversion
  444. ===============================
  445. `cout << x'
  446.      writes out x.
  447. `cout << x.at(2, 3)'
  448.      writes out the substring "llo".
  449. `cin >> x'
  450.      reads a whitespace-bounded string into x.
  451. `x.length()'
  452.      returns the length of String x (5, in this case).
  453. `s = (const char*)x'
  454.      can be used to extract the `char*' char array. This coercion is
  455.      useful for sending a String as an argument to any function
  456.      expecting a `const char*' argument (like `atoi', and
  457.      `File::open'). This operator must be used with care, since the
  458.      conversion returns a pointer to `String' internals without copying
  459.      the characters: The resulting `(char*)' is only valid until the
  460.      next String operation,  and you must not modify it. (The
  461.      conversion is defined to return a const value so that GNU C++ will
  462.      produce warning and/or error messages if changes are attempted.)
  463. File: libgpp,  Node: Integer,  Next: Rational,  Prev: String,  Up: Top
  464. The Integer class.
  465. ******************
  466.    The `Integer' class provides multiple precision integer arithmetic
  467. facilities. Some representation details are discussed in the
  468. Representation section.
  469.    `Integers' may be up to `b * ((1 << b) - 1)' bits long, where `b' is
  470. the number of bits per short (typically 1048560 bits when `b = 16'). 
  471. The implementation assumes that a `long' is at least twice as long as a
  472. `short'. This assumption hides beneath almost all primitive operations,
  473. and would be very difficult to change. It also relies on correct
  474. behavior of *unsigned* arithmetic operations.
  475.    Some of the arithmetic algorithms are very loosely based on those
  476. provided in the MIT Scheme `bignum.c' release, which is Copyright (c)
  477. 1987 Massachusetts Institute of Technology. Their use here falls within
  478. the provisions described in the Scheme release.
  479.    Integers may be constructed in the following ways:
  480. `Integer x;'
  481.      Declares an uninitialized Integer.
  482. `Integer x = 2; Integer y(2);'
  483.      Set x and y to the Integer value 2;
  484. `Integer u(x); Integer v = x;'
  485.      Set u and v to the same value as x.
  486.    `Integers' may be coerced back into longs via the `long' coercion
  487. operator. If the Integer cannot fit into a long, this returns MINLONG
  488. or MAXLONG (depending on the sign) where MINLONG is the most negative,
  489. and MAXLONG is the most positive representable long.  The member
  490. function `fits_in_long()' may be used to test this. `Integers' may also
  491. be coerced into `doubles', with potential loss of precision. `+/-HUGE'
  492. is returned if the Integer cannot fit into a double. `fits_in_double()'
  493. may be used to test this.
  494.    All of the usual arithmetic operators are provided (`+, -, *, /, %,
  495. +=, ++, -=, --, *=, /=, %=, ==, !=, <, <=, >, >=').  All operators
  496. support special versions for mixed arguments of Integers and regular
  497. C++ longs in order to avoid useless coercions, as well as to allow
  498. automatic promotion of shorts and ints to longs, so that they may be
  499. applied without additional Integer coercion operators.  The only
  500. operators that behave differently than the corresponding int or long
  501. operators are `++' and `--'.  Because C++ does not distinguish prefix
  502. from postfix application, these are declared as `void' operators, so
  503. that no confusion can result from applying them as postfix.  Thus, for
  504. Integers x and y, ` ++x; y = x; ' is correct, but ` y = ++x; ' and ` y
  505. = x++; ' are not.
  506.    Bitwise operators (`~', `&', `|', `^', `<<', `>>', `&=', `|=', `^=',
  507. `<<=', `>>=') are also provided.  However, these operate on
  508. sign-magnitude, rather than two's complement representations. The sign
  509. of the result is arbitrarily taken as the sign of the first argument.
  510. For example, `Integer(-3) & Integer(5)' returns `Integer(-1)', not -3,
  511. as it would using two's complement. Also, `~', the complement operator,
  512. complements only those bits needed for the representation.  Bit
  513. operators are also provided in the BitSet and BitString classes. One of
  514. these classes should be used instead of Integers when the results of
  515. bit manipulations are not interpreted numerically.
  516.    The following utility functions are also provided. (All arguments
  517. are Integers unless otherwise noted).
  518. `void divide(x, y, q, r);'
  519.      Sets q to the quotient and r to the remainder of x and y. (q and r
  520.      are returned by reference).
  521. `Integer pow(Integer x, Integer p)'
  522.      returns x raised to the power p.
  523. `Integer Ipow(long x, long p)'
  524.      returns x raised to the power p.
  525. `Integer gcd(x, y)'
  526.      returns the greatest common divisor of x and y.
  527. `Integer lcm(x, y)'
  528.      returns the least common multiple of x and y.
  529. `Integer abs(x);'
  530.      returns the absolute value of x.
  531. `void x.negate();'
  532.      negates x.
  533. `Integer sqr(x)'
  534.      returns x * x;
  535. `Integer sqrt(x)'
  536.      returns the floor of the  square root of x.
  537. `long lg(x);'
  538.      returns the floor of the base 2 logarithm of abs(x)
  539. `int sign(x)'
  540.      returns -1 if x is negative, 0 if zero, else +1. Using `if
  541.      (sign(x) == 0)' is a generally faster method of testing for zero
  542.      than using relational operators.
  543. `int even(x)'
  544.      returns true if x is an even number
  545. `int odd(x)'
  546.      returns true if x is an odd number.
  547. `void setbit(Integer& x, long b)'
  548.      sets the b'th bit (counting right-to-left from zero) of x to 1.
  549. `void clearbit(Integer& x, long b)'
  550.      sets the b'th bit of x to 0.
  551. `int testbit(Integer x, long b)'
  552.      returns true if the b'th bit of x is 1.
  553. `Integer atoI(char* asciinumber, int base = 10);'
  554.      converts the base base char* string into its Integer form.
  555. `void Integer::printon(ostream& s, int base = 10, int width = 0);'
  556.      prints the ascii string value of `(*this)' as a base `base'
  557.      number, in field width at least `width'.
  558. `ostream << x;'
  559.      prints x in base ten format.
  560. `istream >> x;'
  561.      reads x as a base ten number.
  562. `int compare(Integer x, Integer y)'
  563.      returns a negative number if x<y, zero if x==y, or positive if x>y.
  564. `int ucompare(Integer x, Integer y)'
  565.      like compare, but performs unsigned comparison.
  566. `add(x, y, z)'
  567.      A faster way to say z = x + y.
  568. `sub(x, y, z)'
  569.      A faster way to say z = x - y.
  570. `mul(x, y, z)'
  571.      A faster way to say z = x * y.
  572. `div(x, y, z)'
  573.      A faster way to say z = x / y.
  574. `mod(x, y, z)'
  575.      A faster way to say z = x % y.
  576. `and(x, y, z)'
  577.      A faster way to say z = x & y.
  578. `or(x, y, z)'
  579.      A faster way to say z = x | y.
  580. `xor(x, y, z)'
  581.      A faster way to say z = x ^ y.
  582. `lshift(x, y, z)'
  583.      A faster way to say z = x << y.
  584. `rshift(x, y, z)'
  585.      A faster way to say z = x >> y.
  586. `pow(x, y, z)'
  587.      A faster way to say z = pow(x, y).
  588. `complement(x, z)'
  589.      A faster way to say z = ~x.
  590. `negate(x, z)'
  591.      A faster way to say z = -x.
  592. File: libgpp,  Node: Rational,  Next: Complex,  Prev: Integer,  Up: Top
  593. The Rational Class
  594. ******************
  595.    Class `Rational' provides multiple precision rational number
  596. arithmetic. All rationals are maintained in simplest form (i.e., with
  597. the numerator and denominator relatively prime, and with the
  598. denominator strictly positive). Rational arithmetic and relational
  599. operators are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=, <, <=, >,
  600. >='). Operations resulting in a rational number with zero denominator
  601. trigger an exception.
  602.    Rationals may be constructed and used in the following ways:
  603. `Rational x;'
  604.      Declares an uninitialized Rational.
  605. `Rational x = 2; Rational y(2);'
  606.      Set x and y to the Rational value 2/1;
  607. `Rational x(2, 3);'
  608.      Sets x to the Rational value 2/3;
  609. `Rational x = 1.2;'
  610.      Sets x to a Rational value close to 1.2. Any double precision value
  611.      may be used to construct a Rational. The Rational will possess
  612.      exactly as much precision as the double. Double values that do not
  613.      have precise floating point equivalents (like 1.2) produce
  614.      similarly imprecise rational values.
  615. `Rational x(Integer(123), Integer(4567));'
  616.      Sets x to the Rational value 123/4567.
  617. `Rational u(x); Rational v = x;'
  618.      Set u and v to the same value as x.
  619. `double(Rational x)'
  620.      A Rational may be coerced to a double with potential loss of
  621.      precision. +/-HUGE is returned if it will not fit.
  622. `Rational abs(x)'
  623.      returns the absolute value of x.
  624. `void x.negate()'
  625.      negates x.
  626. `void x.invert()'
  627.      sets x to 1/x.
  628. `int sign(x)'
  629.      returns 0 if x is zero, 1 if positive, and -1 if negative.
  630. `Rational sqr(x)'
  631.      returns x * x.
  632. `Rational pow(x, Integer y)'
  633.      returns x to the y power.
  634. `Integer x.numerator()'
  635.      returns the numerator.
  636. `Integer x.denominator()'
  637.      returns the denominator.
  638. `Integer floor(x)'
  639.      returns the greatest Integer less than x.
  640. `Integer ceil(x)'
  641.      returns the least Integer greater than x.
  642. `Integer trunc(x)'
  643.      returns the Integer part of x.
  644. `Integer round(x)'
  645.      returns the nearest Integer to x.
  646. `int compare(x, y)'
  647.      returns a negative, zero, or positive number signifying whether x
  648.      is less than, equal to, or greater than y.
  649. `ostream << x;'
  650.      prints x in the form num/den, or just num if the denominator is
  651.      one.
  652. `istream >> x;'
  653.      reads x in the form num/den, or just num in which case the
  654.      denominator is set to one.
  655. `add(x, y, z)'
  656.      A faster way to say z = x + y.
  657. `sub(x, y, z)'
  658.      A faster way to say z = x - y.
  659. `mul(x, y, z)'
  660.      A faster way to say z = x * y.
  661. `div(x, y, z)'
  662.      A faster way to say z = x / y.
  663. `pow(x, y, z)'
  664.      A faster way to say z = pow(x, y).
  665. `negate(x, z)'
  666.      A faster way to say z = -x.
  667. File: libgpp,  Node: Complex,  Next: Fix,  Prev: Rational,  Up: Top
  668. The Complex class.
  669. ******************
  670.    Class `Complex' is implemented in a way similar to that described by
  671. Stroustrup. In keeping with libg++ conventions, the class is named
  672. `Complex', not `complex'. Complex arithmetic and relational operators
  673. are provided (`+, -, *, /, +=, -=, *=, /=, ==, !='). Attempted division
  674. by (0, 0) triggers an exception.
  675.    Complex numbers may be constructed and used in the following ways:
  676. `Complex x;'
  677.      Declares an uninitialized Complex.
  678. `Complex x = 2; Complex y(2.0);'
  679.      Set x and y to the Complex value (2.0, 0.0);
  680. `Complex x(2, 3);'
  681.      Sets x to the Complex value (2, 3);
  682. `Complex u(x); Complex v = x;'
  683.      Set u and v to the same value as x.
  684. `double real(Complex& x);'
  685.      returns the real part of x.
  686. `double imag(Complex& x);'
  687.      returns the imaginary part of x.
  688. `double abs(Complex& x);'
  689.      returns the magnitude of x.
  690. `double norm(Complex& x);'
  691.      returns the square of the magnitude of x.
  692. `double arg(Complex& x);'
  693.      returns the argument (amplitude) of x.
  694. `Complex polar(double r, double t = 0.0);'
  695.      returns a Complex with abs of r and arg of t.
  696. `Complex conj(Complex& x);'
  697.      returns the complex conjugate of x.
  698. `Complex cos(Complex& x);'
  699.      returns the complex cosine of x.
  700. `Complex sin(Complex& x);'
  701.      returns the complex sine of x.
  702. `Complex cosh(Complex& x);'
  703.      returns the complex hyperbolic cosine of x.
  704. `Complex sinh(Complex& x);'
  705.      returns the complex hyperbolic sine of x.
  706. `Complex exp(Complex& x);'
  707.      returns the exponential of x.
  708. `Complex log(Complex& x);'
  709.      returns the natural log of x.
  710. `Complex pow(Complex& x, long p);'
  711.      returns x raised to the p power.
  712. `Complex pow(Complex& x, Complex& p);'
  713.      returns x raised to the p power.
  714. `Complex sqrt(Complex& x);'
  715.      returns the square root of x.
  716. `ostream << x;'
  717.      prints x in the form (re, im).
  718. `istream >> x;'
  719.      reads x in the form (re, im), or just (re) or re in which case the
  720.      imaginary part is set to zero.
  721. File: libgpp,  Node: Fix,  Next: Bit,  Prev: Complex,  Up: Top
  722. Fixed precision numbers
  723. ***********************
  724.    Classes `Fix16', `Fix24', `Fix32', and `Fix48' support operations on
  725. 16, 24, 32, or 48 bit quantities that are considered as real numbers in
  726. the range [-1, +1).  Such numbers are often encountered in digital
  727. signal processing applications. The classes may be be used in isolation
  728. or together.  Class `Fix32' operations are entirely self-contained. 
  729. Class `Fix16' operations are self-contained except that the
  730. multiplication operation `Fix16 * Fix16' returns a `Fix32'. `Fix24' and
  731. `Fix48' are similarly related.
  732.    The standard arithmetic and relational operations are supported
  733. (`=', `+', `-', `*', `/', `<<', `>>', `+=', `-=', `*=', `/=', `<<=',
  734. `>>=', `==', `!=', `<', `<=', `>', `>='). All operations include
  735. provisions for special handling in cases where the result exceeds +/-
  736. 1.0. There are two cases that may be handled separately: "overflow"
  737. where the results of addition and subtraction operations go out of
  738. range, and all other "range errors" in which resulting values go
  739. off-scale (as with division operations, and assignment or
  740. initialization with off-scale values). In signal processing
  741. applications, it is often useful to handle these two cases differently.
  742. Handlers take one argument, a reference to the integer mantissa of the
  743. offending value, which may then be manipulated.  In cases of overflow,
  744. this value is the result of the (integer) arithmetic computation on the
  745. mantissa; in others it is a fully saturated (i.e., most positive or
  746. most negative) value. Handling may be reset to any of several provided
  747. functions or any other user-defined function via `set_overflow_handler'
  748. and `set_range_error_handler'. The provided functions for `Fix16' are
  749. as follows (corresponding functions are also supported for the others).
  750. `Fix16_overflow_saturate'
  751.      The default overflow handler. Results are "saturated": positive
  752.      results are set to the largest representable value (binary
  753.      0.111111...), and negative values to -1.0.
  754. `Fix16_ignore'
  755.      Performs no action. For overflow, this will allow addition and
  756.      subtraction operations to "wrap around" in the same manner as
  757.      integer arithmetic, and for saturation, will leave values
  758.      saturated.
  759. `Fix16_overflow_warning_saturate'
  760.      Prints a warning message on standard error, then saturates the
  761.      results.
  762. `Fix16_warning'
  763.      The default range_error handler. Prints a warning message on
  764.      standard error; otherwise leaving the argument unmodified.
  765. `Fix16_abort'
  766.      prints an error message on standard error, then aborts execution.
  767.    In addition to arithmetic operations, the following are provided:
  768. `Fix16 a = 0.5;'
  769.      Constructs fixed precision objects from double precision values.
  770.      Attempting to initialize to a value outside the range invokes the
  771.      range_error handler, except, as a convenience, initialization to
  772.      1.0 sets the variable to the most positive representable value
  773.      (binary 0.1111111...) without invoking the handler.
  774. `short& mantissa(a); long& mantissa(b);'
  775.      return a * pow(2, 15) or b * pow(2, 31) as an integer. These are
  776.      returned by reference, to enable "manual" data manipulation.
  777. `double value(a); double value(b);'
  778.      return a or b as floating point numbers.
  779. File: libgpp,  Node: Bit,  Next: Random,  Prev: Fix,  Up: Top
  780. Classes for Bit manipulation
  781. ****************************
  782.    libg++ provides several different classes supporting the use and
  783. manipulation of collections of bits in different ways.
  784.    * Class `Integer' provides "integer" semantics. It supports
  785.      manipulation of bits in ways that are often useful when treating
  786.      bit arrays as numerical (integer) quantities.  This class is
  787.      described elsewhere.
  788.    * Class `BitSet' provides "set" semantics. It supports operations
  789.      useful when treating collections of bits as representing
  790.      potentially infinite sets of integers.
  791.    * Class `BitSet32' supports fixed-length BitSets holding exactly 32
  792.      bits.
  793.    * Class `Bitset256'supports fixed-length BitSets holding exactly 256
  794.      bits.
  795.    * Class `BitString' provides "string" (or "vector") semantics. It
  796.      supports operations useful when treating collections of bits as
  797.      strings of zeros and ones.
  798.    These classes also differ in the following ways:
  799.    * BitSets are logically infinite. Their space is dynamically altered
  800.      to adjust to the smallest number of consecutive bits actually
  801.      required to represent the sets. Integers also have this property.
  802.      BitStrings are logically finite, but their sizes are internally
  803.      dynamically managed to maintain proper length. This means that,
  804.      for example, BitStrings are concatenatable while BitSets and
  805.      Integers are not.
  806.    * BitSet32 and BitSet256 have precisely the same properties as
  807.      BitSets, except that they use constant fixed length bit vectors.
  808.    * While all classes support basic unary and binary operations `~, &,
  809.      |, ^, -', the semantics differ. BitSets perform bit operations that
  810.      precisely mirror those for infinite sets. For example,
  811.      complementing an empty BitSet returns one representing an infinite
  812.      number of set bits. Operations on BitStrings and Integers operate
  813.      only on those bits actually present in the representation.  For
  814.      BitStrings and Integers, the the `&' operation returns a BitString
  815.      with a length equal to the minimum length of the operands, and `|,
  816.      ^' return one with length of the maximum.
  817.    * Only BitStrings support substring extraction and bit pattern
  818.      matching.
  819. BitSet
  820. ======
  821.    Bitsets are objects that contain logically infinite sets of
  822. nonnegative integers.  Representational details are discussed in the
  823. Representation chapter. Because they are logically infinite, all
  824. BitSets possess a trailing, infinitely replicated 0 or 1 bit, called
  825. the "virtual bit", and indicated via 0* or 1*.
  826.    BitSet32 and BitSet256 have they same properties, except they are of
  827. fixed length, and thus have no virtual bit.
  828.    BitSets may be constructed as follows:
  829. `BitSet a;'
  830.      declares an empty BitSet.
  831. `BitSet a = atoBitSet("001000");'
  832.      sets a to the BitSet 0010*, reading left-to-right. The "0*"
  833.      indicates that the set ends with an infinite number of zero
  834.      (clear) bits.
  835. `BitSet a = atoBitSet("00101*");'
  836.      sets a to the BitSet 00101*, where "1*" means that the set ends
  837.      with an infinite number of one (set) bits.
  838. `BitSet a = longtoBitSet((long)23);'
  839.      sets a to the BitSet 111010*, the binary representation of decimal
  840.      23.
  841. `BitSet a = utoBitSet((unsigned)23);'
  842.      sets a to the BitSet 111010*, the binary representation of decimal
  843.      23.
  844.    The following functions and operators are provided (Assume the
  845. declaration of BitSets a = 0011010*, b = 101101*, throughout, as
  846. examples).
  847.      returns the complement of a, or 1100101* in this case.
  848. `a.complement()'
  849.      sets a to ~a.
  850. `a & b; a &= b;'
  851.      returns a intersected with b, or 0011010*.
  852. `a | b; a |= b;'
  853.      returns a unioned with b, or 1011111*.
  854. `a - b; a -= b;'
  855.      returns the set difference of a and b, or 000010*.
  856. `a ^ b; a ^= b;'
  857.      returns the symmetric difference of a and b, or 1000101*.
  858. `a.empty()'
  859.      returns true if a is an empty set.
  860. `a == b;'
  861.      returns true if a and b contain the same set.
  862. `a <= b;'
  863.      returns true if a is a subset of b.
  864. `a < b;'
  865.      returns true if a is a proper subset of b;
  866. `a != b; a >= b; a > b;'
  867.      are the converses of the above.
  868. `a.set(7)'
  869.      sets the 7th (counting from 0) bit of a, setting a to 001111010*
  870. `a.clear(2)'
  871.      clears the 2nd bit bit of a, setting a to 00011110*
  872. `a.clear()'
  873.      clears all bits of a;
  874. `a.set()'
  875.      sets all bits of a;
  876. `a.invert(0)'
  877.      complements the 0th bit of a, setting a to 10011110*
  878. `a.set(0,1)'
  879.      sets the 0th through 1st bits of a, setting a to 110111110* The
  880.      two-argument versions of clear and invert are similar.
  881. `a.test(3)'
  882.      returns true if the 3rd bit of a is set.
  883. `a.test(3, 5)'
  884.      returns true if any of bits 3 through 5 are set.
  885. `int i = a[3]; a[3] = 0;'
  886.      The subscript operator allows bits to be inspected and changed via
  887.      standard subscript semantics, using a friend class BitSetBit. The
  888.      use of the subscript operator a[i] rather than a.test(i) requires
  889.      somewhat greater overhead.
  890. `a.first(1) or a.first()'
  891.      returns the index of the first set bit of a (2 in this case), or
  892.      -1 if no bits are set.
  893. `a.first(0)'
  894.      returns the index of the first clear bit of a (0 in this case), or
  895.      -1 if no bits are clear.
  896. `a.next(2, 1) or a.next(2)'
  897.      returns the index of the next bit after position 2 that is set (3
  898.      in this case) or -1. `first' and `next' may be used as iterators,
  899.      as in `for (int i = a.first(); i >= 0; i = a.next(i))...'.
  900. `a.last(1)'
  901.      returns the index of the rightmost set bit, or -1 if there or no
  902.      set bits or all set bits.
  903. `a.previous(3, 0)'
  904.      returns the index of the previous clear bit before position 3.
  905. `a.count(1)'
  906.      returns the number of set bits in a, or -1 if there are an
  907.      infinite number.
  908. `a.virtual_bit()'
  909.      returns the trailing (infinitely replicated) bit of a.
  910. `a = atoBitSet("ababX", 'a', 'b', 'X');'
  911.      converts the char* string into a bitset, with 'a' denoting false,
  912.      'b' denoting true, and 'X' denoting infinite replication.
  913. `a.printon(cout, '-', '.', 0)'
  914.      prints `a' to `cout' represented with `'-'' for falses, `'.'' for
  915.      trues, and no replication marker.
  916. `cout << a'
  917.      prints `a' to `cout' (representing lases by `'f'', trues by `'t'',
  918.      and using `'*'' as the replication marker).
  919. `diff(x, y, z)'
  920.      A faster way to say z = x - y.
  921. `and(x, y, z)'
  922.      A faster way to say z = x & y.
  923. `or(x, y, z)'
  924.      A faster way to say z = x | y.
  925. `xor(x, y, z)'
  926.      A faster way to say z = x ^ y.
  927. `complement(x, z)'
  928.      A faster way to say z = ~x.
  929. BitString
  930. =========
  931.    BitStrings are objects that contain arbitrary-length strings of
  932. zeroes and ones. BitStrings possess some features that make them behave
  933. like sets, and others that behave as strings. They are useful in
  934. applications (such as signature-based algorithms) where both
  935. capabilities are needed.  Representational details are discussed in the
  936. Representation chapter.  Most capabilities are exact analogs of those
  937. supported in the BitSet and String classes.  A BitSubString is used
  938. with substring operations along the same lines as the String SubString
  939. class.  A BitPattern class is used for masked bit pattern searching.
  940.    Only a default constructor is supported.  The declaration `BitString
  941. a;' initializes a to be an empty BitString. BitStrings may often be
  942. initialized via `atoBitString' and `longtoBitString'.
  943.    Set operations (` ~, complement, &, &=, |, |=, -, ^, ^=') behave
  944. just as the BitSet versions, except that there is no "virtual bit":
  945. complementing complements only those bits in the BitString, and all
  946. binary operations across unequal length BitStrings assume a virtual bit
  947. of zero. The `&' operation returns a BitString with a length equal to
  948. the minimum length of the operands, and `|, ^' return one with length
  949. of the maximum.
  950.    Set-based relational operations (`==, !=, <=, <, >=, >') follow the
  951. same rules. A string-like lexicographic comparison function,
  952. `lcompare', tests the lexicographic relation between two BitStrings.
  953. For example, lcompare(1100, 0101) returns 1, since the first BitString
  954. starts with 1 and the second with 0.
  955.    Individual bit setting, testing, and iterator operations (`set,
  956. clear, invert, test, first, next, last, previous') are also like those
  957. for BitSets. BitStrings are automatically expanded when setting bits at
  958. positions greater than their current length.
  959.    The string-based capabilities are just as those for class String.
  960. BitStrings may be concatenated (`+, +='), searched (`index, contains,
  961. matches'), and extracted into BitSubStrings (`before, at, after') which
  962. may be assigned and otherwise manipulated. Other string-based utility
  963. functions (`reverse, common_prefix, common_suffix') are also provided.
  964. These have the same capabilities and descriptions as those for Strings.
  965.    String-oriented operations can also be performed with a mask via
  966. class BitPattern. BitPatterns consist of two BitStrings, a pattern and
  967. a mask. On searching and matching, bits in the pattern that correspond
  968. to 0 bits in the mask are ignored. (The mask may be shorter than the
  969. pattern, in which case trailing mask bits are assumed to be 0). The
  970. pattern and mask are both public variables, and may be individually
  971. subjected to other bit operations.
  972.    Converting to char* and printing (`(atoBitString, atoBitPattern,
  973. printon, ostream <<)') are also as in BitSets, except that no virtual
  974. bit is used, and an 'X' in a BitPattern means that the pattern bit is
  975. masked out.
  976.    The following features are unique to BitStrings.
  977.    Assume declarations of BitString a = atoBitString("01010110") and b =
  978. atoBitSTring("1101").
  979. `a = b + c;'
  980.      Sets a to the concatenation of b and c;
  981. `a = b + 0; a = b + 1;'
  982.      sets a to b, appended with a zero (one).
  983. `a += b;'
  984.      appends b to a;
  985. `a += 0; a += 1;'
  986.      appends a zero (one) to a.
  987. `a << 2; a <<= 2'
  988.      return a with 2 zeros prepended, setting a to 0001010110. (Note
  989.      the necessary confusion of << and >> operators. For consistency
  990.      with the integer versions, << shifts low bits to high, even though
  991.      they are printed low bits first.)
  992. `a >> 3; a >>= 3'
  993.      return a with the first 3 bits deleted, setting a to 10110.
  994. `a.left_trim(0)'
  995.      deletes all 0 bits on the left of a, setting a to 1010110.
  996. `a.right_trim(0)'
  997.      deletes all trailing 0 bits of a, setting a to 0101011.
  998. `cat(x, y, z)'
  999.      A faster way to say z = x + y.
  1000. `diff(x, y, z)'
  1001.      A faster way to say z = x - y.
  1002. `and(x, y, z)'
  1003.      A faster way to say z = x & y.
  1004. `or(x, y, z)'
  1005.      A faster way to say z = x | y.
  1006. `xor(x, y, z)'
  1007.      A faster way to say z = x ^ y.
  1008. `lshift(x, y, z)'
  1009.      A faster way to say z = x << y.
  1010. `rshift(x, y, z)'
  1011.      A faster way to say z = x >> y.
  1012. `complement(x, z)'
  1013.      A faster way to say z = ~x.
  1014.