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