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

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