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