[BACK]Return to bc.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / bc

Annotation of src/usr.bin/bc/bc.1, Revision 1.8

1.8     ! jmc         1: .\"    $OpenBSD: bc.1,v 1.7 2003/10/19 19:21:48 otto 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
1.6       otto      123: continue
1.1       otto      124: quit
1.6       otto      125: a string of characters, enclosed in double quotes
1.1       otto      126: .Ed
                    127: .Pp
1.8     ! jmc       128: All three E's in a for statement may be empty.
1.7       otto      129: This is a non-portable extension.
1.8     ! jmc       130: The continue statement is also a non-portable extension.
1.7       otto      131: .Pp
1.1       otto      132: Function definitions
                    133: .Bd -unfilled -offset indent -compact
                    134: define L ( L ,..., L ) {
                    135:        auto L, ... , L
                    136:        S; ... S
                    137:        return ( E )
                    138: }
                    139: .Ed
1.5       otto      140: .Pp
                    141: The sequence
                    142: .Sq \e\<newline><whitespace>
                    143: is ignored within numbers.
1.6       otto      144: A string may contain any character, except double quote.
1.1       otto      145: .Pp
                    146: Functions in
1.4       jmc       147: .Fl lm
1.1       otto      148: math library
                    149: .Bl -tag -width j(n,x) -offset indent -compact
                    150: .It s(x)
                    151: sine
                    152: .It c(x)
                    153: cosine
                    154: .It e(x)
                    155: exponential
                    156: .It l(x)
                    157: log
                    158: .It a(x)
                    159: arctangent
                    160: .It j(n,x)
                    161: Bessel function
                    162: .El
                    163: .Pp
                    164: All function arguments are passed by value.
                    165: .Pp
                    166: The value of a statement that is an expression is printed
                    167: unless the main operator is an assignment.
                    168: Either semicolons or newlines may separate statements.
                    169: Assignment to
                    170: .Ar scale
                    171: influences the number of digits to be retained on arithmetic
                    172: operations in the manner of
1.4       jmc       173: .Xr dc 1 .
1.1       otto      174: Assignments to
                    175: .Ar ibase
                    176: or
                    177: .Ar obase
                    178: set the input and output number radix respectively.
                    179: .Pp
                    180: The same letter may be used as an array, a function,
                    181: and a simple variable simultaneously.
                    182: All variables are global to the program.
                    183: `Auto' variables are pushed down during function calls.
                    184: When using arrays as function arguments
1.4       jmc       185: or defining them as automatic variables,
1.1       otto      186: empty square brackets must follow the array name.
                    187: .Pp
                    188: For example
                    189: .Bd -literal -offset indent
                    190: scale = 20
                    191: define e(x){
                    192:        auto a, b, c, i, s
                    193:        a = 1
                    194:        b = 1
                    195:        s = 1
                    196:        for(i=1; 1==1; i++){
                    197:                a = a*x
                    198:                b = b*i
                    199:                c = a/b
                    200:                if(c == 0) return(s)
                    201:                s = s+c
                    202:        }
                    203: }
                    204: .Ed
                    205: .Pp
                    206: defines a function to compute an approximate value of
                    207: the exponential function and
                    208: .Pp
                    209: .Dl for(i=1; i<=10; i++) e(i)
                    210: .Pp
                    211: prints approximate values of the exponential function of
                    212: the first ten integers.
                    213: .Sh SEE ALSO
1.4       jmc       214: .Xr dc 1
1.1       otto      215: .Rs
                    216: .%A L. L. Cherry
                    217: .%A R. Morris
                    218: .%T "BC \- An arbitrary precision desk-calculator language"
                    219: .Re
1.3       otto      220: .Sh STANDARDS
                    221: The
                    222: .Nm
                    223: utility is expected to conform to the
                    224: .St -p1003.2
1.4       jmc       225: specification.
1.1       otto      226: .Sh HISTORY
                    227: The
1.4       jmc       228: .Nm
1.1       otto      229: command appeared in
                    230: .At v6 .
                    231: .Sh BUGS
1.4       jmc       232: No
                    233: .Sq && ,
                    234: .Sq \(or\(or ,
                    235: or
                    236: .Sq \&!
                    237: operators.
1.1       otto      238: .Pp
                    239: .Ql Quit
                    240: is interpreted when read, not when executed.
1.3       otto      241: .Pp
                    242: Some non-portable extensions, as found in the GNU version of the
                    243: .Nm
                    244: utility are not implemented (yet).