Annotation of src/usr.bin/bc/bc.1, Revision 1.1
1.1 ! otto 1: .\" $OpenBSD$
! 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
! 40: .Nm \&bc
! 41: .Nd arbitrary-precision arithmetic language and calculator
! 42: .Sh SYNOPSIS
! 43: .Nm \&bc
! 44: .Op Fl c
! 45: .Op Fl l
! 46: .Ar
! 47: .Sh DESCRIPTION
! 48: .Nm \&Bc
! 49: is an interactive processor for a language which resembles
! 50: C but provides unlimited precision arithmetic.
! 51: It takes input from any files given, then reads
! 52: the standard input.
! 53: .Pp
! 54: Options available:
! 55: .Bl -tag -width flag
! 56: .It Fl l
! 57: allow specification
! 58: of an arbitrary precision math library.
! 59: .It Fl c
! 60: .Nm \&Bc
! 61: is actually a preprocessor for
! 62: .Ar \&dc 1 ,
! 63: which it invokes automatically, unless the
! 64: .Fl c
! 65: compile only.
! 66: option is present.
! 67: In this case the
! 68: .Ar \&dc
! 69: input is sent to the standard output instead.
! 70: .El
! 71: .Pp
! 72: The syntax for
! 73: .Nm \&bc
! 74: programs is as follows;
! 75: L means letter a-z,
! 76: E means expression, S means statement.
! 77: .Pp
! 78: Comments
! 79: .Bd -unfilled -offset indent -compact
! 80: are enclosed in /* and */.
! 81: .Ed
! 82: .Pp
! 83: Names
! 84: .Bd -unfilled -offset indent -compact
! 85: simple variables: L
! 86: array elements: L [ E ]
! 87: The words `ibase', `obase', and `scale'
! 88: .Ed
! 89: .Pp
! 90: Other operands
! 91: .Bd -unfilled -offset indent -compact
! 92: arbitrarily long numbers with optional sign and decimal point.
! 93: \&( E \&)
! 94: sqrt ( E )
! 95: length ( E ) number of significant decimal digits
! 96: scale ( E ) number of digits right of decimal point
! 97: L ( E , ... , E )
! 98: .Ed
! 99: .Pp
! 100: Operators
! 101: .Bd -unfilled -offset indent -compact
! 102: \&+ \- * / % ^ (% is remainder; ^ is power)
! 103: \&++ \-\- (prefix and postfix; apply to names)
! 104: \&== <= >= != < >
! 105: \&= += \-= *= /= %= ^=
! 106: .Ed
! 107: .Pp
! 108: Statements
! 109: .Bd -unfilled -offset indent -compact
! 110: E
! 111: { S ; ... ; S }
! 112: if ( E ) S
! 113: while ( E ) S
! 114: for ( E ; E ; E ) S
! 115: null statement
! 116: break
! 117: quit
! 118: .Ed
! 119: .Pp
! 120: Function definitions
! 121: .Bd -unfilled -offset indent -compact
! 122: define L ( L ,..., L ) {
! 123: auto L, ... , L
! 124: S; ... S
! 125: return ( E )
! 126: }
! 127: .Ed
! 128: .Pp
! 129: Functions in
! 130: .Fl l
! 131: math library
! 132: .Bl -tag -width j(n,x) -offset indent -compact
! 133: .It s(x)
! 134: sine
! 135: .It c(x)
! 136: cosine
! 137: .It e(x)
! 138: exponential
! 139: .It l(x)
! 140: log
! 141: .It a(x)
! 142: arctangent
! 143: .It j(n,x)
! 144: Bessel function
! 145: .El
! 146: .Pp
! 147: All function arguments are passed by value.
! 148: .Pp
! 149: The value of a statement that is an expression is printed
! 150: unless the main operator is an assignment.
! 151: Either semicolons or newlines may separate statements.
! 152: Assignment to
! 153: .Ar scale
! 154: influences the number of digits to be retained on arithmetic
! 155: operations in the manner of
! 156: .Xr \&dc 1 .
! 157: Assignments to
! 158: .Ar ibase
! 159: or
! 160: .Ar obase
! 161: set the input and output number radix respectively.
! 162: .Pp
! 163: The same letter may be used as an array, a function,
! 164: and a simple variable simultaneously.
! 165: All variables are global to the program.
! 166: `Auto' variables are pushed down during function calls.
! 167: When using arrays as function arguments
! 168: or defining them as automatic variables
! 169: empty square brackets must follow the array name.
! 170: .Pp
! 171: For example
! 172: .Bd -literal -offset indent
! 173: scale = 20
! 174: define e(x){
! 175: auto a, b, c, i, s
! 176: a = 1
! 177: b = 1
! 178: s = 1
! 179: for(i=1; 1==1; i++){
! 180: a = a*x
! 181: b = b*i
! 182: c = a/b
! 183: if(c == 0) return(s)
! 184: s = s+c
! 185: }
! 186: }
! 187: .Ed
! 188: .Pp
! 189: defines a function to compute an approximate value of
! 190: the exponential function and
! 191: .Pp
! 192: .Dl for(i=1; i<=10; i++) e(i)
! 193: .Pp
! 194: prints approximate values of the exponential function of
! 195: the first ten integers.
! 196: .Sh FILES
! 197: .\" /usr/lib/lib.b mathematical library
! 198: .Bl -tag -width xxxxx -compact
! 199: .It Xr \&dc 1
! 200: Desk calculator Proper.
! 201: .El
! 202: .Sh SEE ALSO
! 203: .Xr \&dc 1
! 204: .Rs
! 205: .%A L. L. Cherry
! 206: .%A R. Morris
! 207: .%T "BC \- An arbitrary precision desk-calculator language"
! 208: .Re
! 209: .Sh HISTORY
! 210: The
! 211: .Nm \&bc
! 212: command appeared in
! 213: .At v6 .
! 214: .Sh BUGS
! 215: No &&, \(or\\(or, or ! operators.
! 216: .Pp
! 217: .Ql For
! 218: statement must have all three E's.
! 219: .Pp
! 220: .Ql Quit
! 221: is interpreted when read, not when executed.