|
|
1.1 ! root 1: ! 2: ! 3: bc Command bc ! 4: ! 5: ! 6: ! 7: ! 8: Interactive calculator with arbitrary precision ! 9: ! 10: bbcc [ -ll ] [ _f_i_l_e ... ] ! 11: ! 12: bc is a language that performs calculations on numbers with an ! 13: arbitrary number of digits. bc is most commonly used as an in- ! 14: teractive calculator, where the user types arithmetic expressions ! 15: in a syntax reminiscent of C. If bc is invoked with no file ar- ! 16: guments on its command line, it reads the standard input. For ! 17: example: ! 18: ! 19: ! 20: _I_n_p_u_t _O_u_t_p_u_t ! 21: bc ! 22: (1000+23)*42 42966 ! 23: k = 2^10 ! 24: 16 * k 16384 ! 25: 2 ^ 100 1267650600228229401496703205376 ! 26: ! 27: ! 28: bc may also be invoked with one or more file arguments. After bc ! 29: reads each file, it reads the standard input. This provides a ! 30: convenient way to access programs in files. A library of mathe- ! 31: matical functions is available, obtained by using the -l option. ! 32: ! 33: The following summarizes briefly the facilities provided by bc. ! 34: More information is available in the tutorial to bbcc that is in- ! 35: cluded with this manual. ! 36: ! 37: Comments are enclosed between the delimiters `/*' and `*/'. ! 38: Names of variables or functions must begin with a lower-case let- ! 39: ter, and may have any number of subsequent letters or digits. ! 40: Names may not begin with an upper-case letter because numbers ! 41: with a base greater than ten may need need upper-case letters for ! 42: their notation. The three built-in variables obase, ibase, and ! 43: scale represent the number base for printing numbers (default, ! 44: ten), the number base for reading numbers (default, ten), and the ! 45: number of digits after the decimal (radix) point (default, zero), ! 46: respectively. Variables may be simple variables or arrays, and ! 47: need not be pre-declared, with the exception of variables inter- ! 48: nal to functions. Some examples of variables and array elements ! 49: are x25, array[10], and number. ! 50: ! 51: Numbers are any string of digits, and may have one decimal point. ! 52: Digits are taken from the ordinary digits (0-9) and then the up- ! 53: per-case letters (A-F), in that order. ! 54: ! 55: Certain names are reserved for use as key words. The key words ! 56: recognized by bc include the following: ! 57: ! 58: iiff, ffoorr, ddoo, wwhhiillee ! 59: Test conditions and define loops, with syntax identical to C ! 60: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66: ! 67: ! 68: ! 69: bc Command bc ! 70: ! 71: ! 72: ! 73: bbrreeaakk, ccoonnttiinnuuee ! 74: Alter control flow within for and while loops. ! 75: ! 76: qquuiitt Tell bc to exit immediately ! 77: ! 78: ddeeffiinnee _f_u_n_c_t_i_o_n (_a_r_g, ..., _a_r_g) ! 79: Define a bc function by a compound statement, as in C. ! 80: ! 81: aauuttoo _v_a_r, ..., _v_a_r ! 82: Define variables that are local to a function, rather than ! 83: having global scope. ! 84: ! 85: rreettuurrnn (_v_a_l_u_e) ! 86: Return a value from a function. ! 87: ! 88: ssccaallee (_v_a_l_u_e) ! 89: Return the number of digits to the right of the decimal ! 90: point in value. ! 91: ! 92: ssqqrrtt (_v_a_l_u_e) ! 93: Return the square root of value ! 94: ! 95: lleennggtthh (_v_a_l_u_e) ! 96: Return the number of decimal digits in value. ! 97: ! 98: The following operators are recognized: ! 99: ! 100: ! 101: + -* / % ^ ++ ! 102: -- =+= -= *= /= %= ! 103: ^= ==!= < <= > >= ! 104: ! 105: ! 106: These operators are similar to those in C, with the exception of ! 107: ^ and ^=, which are exponentiation operators. Expressions can be ! 108: grouped with parentheses. Statements are separated with semi- ! 109: colons or newlines, and may be made into compound statements with ! 110: braces. bc prints the value of any statement that is an expres- ! 111: sion but is not an assignment. ! 112: ! 113: As in the editor ed, an `!' at the beginning of a line causes ! 114: that line to be sent as a command to the COHERENT shell sh. ! 115: ! 116: The built-in mathematics library contains the following functions ! 117: and variables: ! 118: ! 119: ! 120: aattaann(_z) Arctangent of _z ! 121: ccooss(_z) Cosine of _z ! 122: eexxpp(_z) Exponential function of _z ! 123: jj(_n,_z) _nth order Bessel function of _z ! 124: llnn(_z) Natural logarithm of _z ! 125: ppii Value of pi to 100 digits ! 126: ssiinn(_z) Sine of _z ! 127: ! 128: ! 129: ! 130: COHERENT Lexicon Page 2 ! 131: ! 132: ! 133: ! 134: ! 135: bc Command bc ! 136: ! 137: ! 138: ! 139: ! 140: ***** Examples ***** ! 141: ! 142: The first example calculates the factorial of its positive in- ! 143: teger argument by recursion. ! 144: ! 145: ! 146: /* ! 147: * Factorial function implemented by recursion. ! 148: */ ! 149: define fact(n) { ! 150: if (n <= 1) return (n); ! 151: return (n * fact(n-1)); ! 152: } ! 153: ! 154: ! 155: The second example also calculates the factorial of its positive ! 156: integer argument, this time by iteration. ! 157: ! 158: ! 159: /* ! 160: * Factorial function implemented by iteration. ! 161: */ ! 162: define fact(n) { ! 163: auto result; ! 164: ! 165: result = 1; ! 166: for (i=1; i<=n; i++) result *= i; ! 167: return (result); ! 168: } ! 169: ! 170: ! 171: ***** Files ***** ! 172: ! 173: /uussrr/lliibb/lliibb.bb -- Source code for the library ! 174: ! 175: ***** See Also ***** ! 176: ! 177: commands, conv, dc, multi-precision arithmetic ! 178: _b_c _D_e_s_k _C_a_l_c_u_l_a_t_o_r _L_a_n_g_u_a_g_e, tutorial ! 179: ! 180: ***** Notes ***** ! 181: ! 182: Line numbers do not accompany error messages in source files. ! 183: ! 184: ! 185: ! 186: ! 187: ! 188: ! 189: ! 190: ! 191: ! 192: ! 193: ! 194: ! 195: ! 196: COHERENT Lexicon Page 3 ! 197: ! 198:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.