[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.9

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