trivial pathname changes
[unix-history] / usr / src / usr.bin / bc / bc.1
CommitLineData
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
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.
25The
b5dc1377 26.Tp Fl l
67aa4194
KM
27argument stands for the name
28of an arbitrary precision math library.
b5dc1377
CL
29.Tp Fl c
30.Nm Bc
31is actually a preprocessor for
32.Ar dc 1 ,
33which it invokes automatically, unless the
34.Fl c
35compile only.
36option is present.
37In this case the
38.Ar dc
39input is sent to the standard output instead.
40.Tp
41.Pp
42The syntax for
43.Nm bc
67aa4194
KM
44programs is as follows;
45L means letter a-z,
46E means expression, S means statement.
b5dc1377 47.Pp
67aa4194 48Comments
b5dc1377
CL
49.Dl are enclosed in /* and */.
50.Pp
67aa4194 51Names
b5dc1377
CL
52.Dl simple variables: L
53.Df I
54array elements: L
55.Op E
56.De
57.Df I
67aa4194 58The words `ibase', `obase', and `scale'
b5dc1377
CL
59.De
60.Pp
67aa4194 61Other 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 69Operators
b5dc1377
CL
70.Dl \&+ \- * / % ^ (% is remainder; ^ is power)
71.Dl \&++ \-\- (prefix and postfix; apply to names)
72.Dl \&== <= >= != < >
73.Dl \&= += \-= *= /= %= ^=
74.Pp
67aa4194 75Statements
b5dc1377 76.Ds I
67aa4194 77E
67aa4194 78{ S ; ... ; S }
67aa4194 79if ( E ) S
67aa4194 80while ( E ) S
67aa4194 81for ( E ; E ; E ) S
67aa4194 82null statement
67aa4194 83break
67aa4194 84quit
b5dc1377
CL
85.De
86.Pp
67aa4194 87Function definitions
b5dc1377 88.Ds I
67aa4194 89define L ( L ,..., L ) {
67aa4194 90 auto L, ... , L
67aa4194 91 S; ... S
67aa4194 92 return ( E )
67aa4194 93}
b5dc1377
CL
94.De
95.Pp
96Functions in
97.Fl l
67aa4194 98math library
b5dc1377
CL
99.Dw ss(x)
100.Dp s(x)
101sine
102.Dp c(x)
103cosine
104.Dp e(x)
105exponential
106.Dp l(x)
107log
108.Dp a(x)
109arctangent
110.Dp j(n,x)
111Bessel function
112.Dp
113.Pp
67aa4194 114All function arguments are passed by value.
b5dc1377 115.Pp
67aa4194
KM
116The value of a statement that is an expression is printed
117unless the main operator is an assignment.
118Either semicolons or newlines may separate statements.
119Assignment to
b5dc1377 120.Ar scale
67aa4194
KM
121influences the number of digits to be retained on arithmetic
122operations in the manner of
b5dc1377 123.Xr dc 1 .
67aa4194 124Assignments to
b5dc1377 125.Ar ibase
67aa4194 126or
b5dc1377 127.Ar obase
67aa4194 128set the input and output number radix respectively.
b5dc1377 129.Pp
67aa4194
KM
130The same letter may be used as an array, a function,
131and a simple variable simultaneously.
132All variables are global to the program.
133`Auto' variables are pushed down during function calls.
134When using arrays as function arguments
135or defining them as automatic variables
136empty square brackets must follow the array name.
b5dc1377 137.Pp
67aa4194 138For example
b5dc1377
CL
139.Pp
140.Ds I
67aa4194
KM
141scale = 20
142define 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
158defines a function to compute an approximate value of
159the exponential function and
b5dc1377
CL
160.Pp
161.Dl for(i=1; i<=10; i++) e(i)
162.Pp
67aa4194
KM
163prints approximate values of the exponential function of
164the 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
175The
176.Nm bc
177command appeared in Version 7 AT&T UNIX.
178.Sh BUGS
179No &&, \(or\\(or, or ! operators.
67aa4194 180.br
b5dc1377 181.Li For
67aa4194
KM
182statement must have all three E's.
183.br
b5dc1377 184.Li Quit
67aa4194 185is interpreted when read, not when executed.