Annotation of src/usr.bin/bc/bc.1, Revision 1.5
1.5 ! otto 1: .\" $OpenBSD: bc.1,v 1.4 2003/09/26 11:21:26 jmc Exp $
1.1 otto 2: .\"
3: .\" Copyright (C) Caldera International Inc. 2001-2002.
4: .\" All rights reserved.
5: .\"
6: .\" Redistribution and use in source and binary forms, with or without
7: .\" modification, are permitted provided that the following conditions
8: .\" are met:
9: .\" 1. Redistributions of source code and documentation must retain the above
10: .\" copyright notice, this list of conditions and the following disclaimer.
11: .\" 2. Redistributions in binary form must reproduce the above copyright
12: .\" notice, this list of conditions and the following disclaimer in the
13: .\" documentation and/or other materials provided with the distribution.
14: .\" 3. All advertising materials mentioning features or use of this software
15: .\" must display the following acknowledgement:
16: .\" This product includes software developed or owned by Caldera
17: .\" International, Inc.
18: .\" 4. Neither the name of Caldera International, Inc. nor the names of other
19: .\" contributors may be used to endorse or promote products derived from
20: .\" this software without specific prior written permission.
21: .\"
22: .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23: .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24: .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25: .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26: .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
27: .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28: .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29: .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31: .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32: .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33: .\" POSSIBILITY OF SUCH DAMAGE.
34: .\"
35: .\" @(#)bc.1 6.8 (Berkeley) 8/8/91
36: .\"
37: .Dd August 8, 1991
38: .Dt BC 1
39: .Sh NAME
1.4 jmc 40: .Nm bc
1.1 otto 41: .Nd arbitrary-precision arithmetic language and calculator
42: .Sh SYNOPSIS
1.4 jmc 43: .Nm bc
44: .Op Fl cl
1.5 ! otto 45: .Op Ar file ...
1.1 otto 46: .Sh DESCRIPTION
1.4 jmc 47: .Nm
1.1 otto 48: is an interactive processor for a language which resembles
49: C but provides unlimited precision arithmetic.
50: It takes input from any files given, then reads
51: the standard input.
52: .Pp
53: Options available:
1.4 jmc 54: .Bl -tag -width Ds
1.1 otto 55: .It Fl c
1.4 jmc 56: .Nm
1.1 otto 57: is actually a preprocessor for
1.4 jmc 58: .Xr dc 1 ,
1.1 otto 59: which it invokes automatically, unless the
60: .Fl c
1.4 jmc 61: .Pq compile only
1.1 otto 62: option is present.
1.4 jmc 63: In this case the generated
64: .Xr dc 1
65: instructions are sent to the standard output,
66: instead of being interpreted by a running
67: .Xr dc 1
68: process.
69: .It Fl l
70: Allow specification
71: of an arbitrary precision math library.
1.2 deraadt 72: .El
1.1 otto 73: .Pp
74: The syntax for
1.4 jmc 75: .Nm
76: programs is as follows:
77: .Sq L
78: means letter a-z;
79: .Sq E
80: means expression;
81: .Sq S
82: means statement.
1.1 otto 83: .Pp
84: Comments
85: .Bd -unfilled -offset indent -compact
1.4 jmc 86: are enclosed in /* and */
1.1 otto 87: .Ed
88: .Pp
89: Names
90: .Bd -unfilled -offset indent -compact
91: simple variables: L
92: array elements: L [ E ]
93: The words `ibase', `obase', and `scale'
94: .Ed
95: .Pp
96: Other operands
97: .Bd -unfilled -offset indent -compact
1.4 jmc 98: arbitrarily long numbers with optional sign and decimal point
99: ( E )
1.1 otto 100: sqrt ( E )
101: length ( E ) number of significant decimal digits
102: scale ( E ) number of digits right of decimal point
103: L ( E , ... , E )
104: .Ed
105: .Pp
106: Operators
107: .Bd -unfilled -offset indent -compact
1.4 jmc 108: + \- * / % ^ (`%' is remainder; `^' is power)
109: ++ \-\- (prefix and postfix; apply to names)
110: == <= >= != < >
111: = += \-= *= /= %= ^=
1.1 otto 112: .Ed
113: .Pp
114: Statements
115: .Bd -unfilled -offset indent -compact
116: E
117: { S ; ... ; S }
118: if ( E ) S
119: while ( E ) S
120: for ( E ; E ; E ) S
121: null statement
122: break
123: quit
1.5 ! otto 124: a string of letters, enclosed in double quotes
1.1 otto 125: .Ed
126: .Pp
127: Function definitions
128: .Bd -unfilled -offset indent -compact
129: define L ( L ,..., L ) {
130: auto L, ... , L
131: S; ... S
132: return ( E )
133: }
134: .Ed
1.5 ! otto 135: .Pp
! 136: The sequence
! 137: .Sq \e\<newline><whitespace>
! 138: is ignored within numbers.
! 139: The newline character may be part part of a string.
1.1 otto 140: .Pp
141: Functions in
1.4 jmc 142: .Fl lm
1.1 otto 143: math library
144: .Bl -tag -width j(n,x) -offset indent -compact
145: .It s(x)
146: sine
147: .It c(x)
148: cosine
149: .It e(x)
150: exponential
151: .It l(x)
152: log
153: .It a(x)
154: arctangent
155: .It j(n,x)
156: Bessel function
157: .El
158: .Pp
159: All function arguments are passed by value.
160: .Pp
161: The value of a statement that is an expression is printed
162: unless the main operator is an assignment.
163: Either semicolons or newlines may separate statements.
164: Assignment to
165: .Ar scale
166: influences the number of digits to be retained on arithmetic
167: operations in the manner of
1.4 jmc 168: .Xr dc 1 .
1.1 otto 169: Assignments to
170: .Ar ibase
171: or
172: .Ar obase
173: set the input and output number radix respectively.
174: .Pp
175: The same letter may be used as an array, a function,
176: and a simple variable simultaneously.
177: All variables are global to the program.
178: `Auto' variables are pushed down during function calls.
179: When using arrays as function arguments
1.4 jmc 180: or defining them as automatic variables,
1.1 otto 181: empty square brackets must follow the array name.
182: .Pp
183: For example
184: .Bd -literal -offset indent
185: scale = 20
186: define e(x){
187: auto a, b, c, i, s
188: a = 1
189: b = 1
190: s = 1
191: for(i=1; 1==1; i++){
192: a = a*x
193: b = b*i
194: c = a/b
195: if(c == 0) return(s)
196: s = s+c
197: }
198: }
199: .Ed
200: .Pp
201: defines a function to compute an approximate value of
202: the exponential function and
203: .Pp
204: .Dl for(i=1; i<=10; i++) e(i)
205: .Pp
206: prints approximate values of the exponential function of
207: the first ten integers.
208: .Sh SEE ALSO
1.4 jmc 209: .Xr dc 1
1.1 otto 210: .Rs
211: .%A L. L. Cherry
212: .%A R. Morris
213: .%T "BC \- An arbitrary precision desk-calculator language"
214: .Re
1.3 otto 215: .Sh STANDARDS
216: The
217: .Nm
218: utility is expected to conform to the
219: .St -p1003.2
1.4 jmc 220: specification.
1.1 otto 221: .Sh HISTORY
222: The
1.4 jmc 223: .Nm
1.1 otto 224: command appeared in
225: .At v6 .
226: .Sh BUGS
1.4 jmc 227: No
228: .Sq && ,
229: .Sq \(or\(or ,
230: or
231: .Sq \&!
232: operators.
1.1 otto 233: .Pp
234: .Ql For
1.4 jmc 235: statements must have all three E's.
1.1 otto 236: .Pp
237: .Ql Quit
238: is interpreted when read, not when executed.
1.3 otto 239: .Pp
240: Some non-portable extensions, as found in the GNU version of the
241: .Nm
242: utility are not implemented (yet).