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

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