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