| 1 | .TH BC 1 |
| 2 | .SH NAME |
| 3 | bc \- arbitrary-precision arithmetic language |
| 4 | .SH SYNOPSIS |
| 5 | .B bc |
| 6 | [ |
| 7 | .B \-c |
| 8 | ] [ |
| 9 | .B \-l |
| 10 | ] [ file ... ] |
| 11 | .SH DESCRIPTION |
| 12 | .I Bc |
| 13 | is an interactive processor for a language which resembles |
| 14 | C but provides unlimited precision arithmetic. |
| 15 | It takes input from any files given, then reads |
| 16 | the standard input. |
| 17 | The |
| 18 | .B \-l |
| 19 | argument stands for the name |
| 20 | of an arbitrary precision math library. |
| 21 | The syntax for |
| 22 | .I bc |
| 23 | programs is as follows; |
| 24 | L means letter a-z, |
| 25 | E means expression, S means statement. |
| 26 | .HP 6 |
| 27 | Comments |
| 28 | .br |
| 29 | are enclosed in /* and */. |
| 30 | .HP 6 |
| 31 | Names |
| 32 | .br |
| 33 | simple variables: L |
| 34 | .br |
| 35 | array elements: L [ E ] |
| 36 | .br |
| 37 | The words `ibase', `obase', and `scale' |
| 38 | .HP 6 |
| 39 | Other operands |
| 40 | .br |
| 41 | arbitrarily long numbers with optional sign and decimal point. |
| 42 | .br |
| 43 | ( E ) |
| 44 | .br |
| 45 | sqrt ( E ) |
| 46 | .br |
| 47 | length ( E ) number of significant decimal digits |
| 48 | .br |
| 49 | scale ( E ) number of digits right of decimal point |
| 50 | .br |
| 51 | L ( E , ... , E ) |
| 52 | .HP 6 |
| 53 | Operators |
| 54 | .br |
| 55 | + \- * / % ^ |
| 56 | (% is remainder; ^ is power) |
| 57 | .br |
| 58 | ++ \-\- (prefix and postfix; apply to names) |
| 59 | .br |
| 60 | == <= >= != < > |
| 61 | .br |
| 62 | = =+ =\- =* =/ =% =^ |
| 63 | .br |
| 64 | .HP 6 |
| 65 | Statements |
| 66 | .br |
| 67 | E |
| 68 | .br |
| 69 | { S ; ... ; S } |
| 70 | .br |
| 71 | if ( E ) S |
| 72 | .br |
| 73 | while ( E ) S |
| 74 | .br |
| 75 | for ( E ; E ; E ) S |
| 76 | .br |
| 77 | null statement |
| 78 | .br |
| 79 | break |
| 80 | .br |
| 81 | quit |
| 82 | .HP 6 |
| 83 | Function definitions |
| 84 | .br |
| 85 | define L ( L ,..., L ) { |
| 86 | .br |
| 87 | auto L, ... , L |
| 88 | .br |
| 89 | S; ... S |
| 90 | .br |
| 91 | return ( E ) |
| 92 | .br |
| 93 | } |
| 94 | .HP 6 |
| 95 | Functions in |
| 96 | .B \-l |
| 97 | math library |
| 98 | .br |
| 99 | s(x) sine |
| 100 | .br |
| 101 | c(x) cosine |
| 102 | .br |
| 103 | e(x) exponential |
| 104 | .br |
| 105 | l(x) log |
| 106 | .br |
| 107 | a(x) arctangent |
| 108 | .br |
| 109 | j(n,x) Bessel function |
| 110 | .PP |
| 111 | .DT |
| 112 | All function arguments are passed by value. |
| 113 | .PP |
| 114 | The value of a statement that is an expression is printed |
| 115 | unless the main operator is an assignment. |
| 116 | Either semicolons or newlines may separate statements. |
| 117 | Assignment to |
| 118 | .I scale |
| 119 | influences the number of digits to be retained on arithmetic |
| 120 | operations in the manner of |
| 121 | .IR dc (1). |
| 122 | Assignments to |
| 123 | .I ibase |
| 124 | or |
| 125 | .I obase |
| 126 | set the input and output number radix respectively. |
| 127 | .PP |
| 128 | The same letter may be used as an array, a function, |
| 129 | and a simple variable simultaneously. |
| 130 | All variables are global to the program. |
| 131 | `Auto' variables are pushed down during function calls. |
| 132 | When using arrays as function arguments |
| 133 | or defining them as automatic variables |
| 134 | empty square brackets must follow the array name. |
| 135 | .PP |
| 136 | For example |
| 137 | .PP |
| 138 | .nf |
| 139 | scale = 20 |
| 140 | define e(x){ |
| 141 | auto a, b, c, i, s |
| 142 | a = 1 |
| 143 | b = 1 |
| 144 | s = 1 |
| 145 | for(i=1; 1==1; i++){ |
| 146 | a = a*x |
| 147 | b = b*i |
| 148 | c = a/b |
| 149 | if(c == 0) return(s) |
| 150 | s = s+c |
| 151 | } |
| 152 | } |
| 153 | .PP |
| 154 | .fi |
| 155 | defines a function to compute an approximate value of |
| 156 | the exponential function and |
| 157 | .PP |
| 158 | .nf |
| 159 | for(i=1; i<=10; i++) e(i) |
| 160 | .fi |
| 161 | .PP |
| 162 | prints approximate values of the exponential function of |
| 163 | the first ten integers. |
| 164 | .PP |
| 165 | .I Bc |
| 166 | is actually a preprocessor for |
| 167 | .IR dc (1), |
| 168 | which it invokes automatically, unless the |
| 169 | .B \-c |
| 170 | (compile only) |
| 171 | option is present. |
| 172 | In this case the |
| 173 | .I dc |
| 174 | input is sent to the standard output instead. |
| 175 | .SH FILES |
| 176 | .ta \w'/usr/lib/lib.b 'u |
| 177 | /usr/lib/lib.b mathematical library |
| 178 | .br |
| 179 | dc(1) desk calculator proper |
| 180 | .SH "SEE ALSO" |
| 181 | dc(1) |
| 182 | .br |
| 183 | L. L. Cherry and R. Morris, |
| 184 | .I |
| 185 | BC \- An arbitrary precision desk-calculator language |
| 186 | .SH BUGS |
| 187 | No &&, \(or\|\(or, or ! operators. |
| 188 | .br |
| 189 | .I For |
| 190 | statement must have all three E's. |
| 191 | .br |
| 192 | .I \11\11Quit |
| 193 | is interpreted when read, not when executed. |