Annotation of 43BSDReno/usr.bin/bc/bc.1, revision 1.1.1.1

1.1       root        1: .\" Copyright (c) 1990 Regents of the University of California.
                      2: .\" All rights reserved.  The Berkeley software License Agreement
                      3: .\" specifies the terms and conditions for redistribution.
                      4: .\"
                      5: .\"     @(#)bc.1       6.6 (Berkeley) 7/24/90
                      6: .\"
                      7: .Dd July 24, 1990
                      8: .Dt BC 1
                      9: .Os ATT 7th
                     10: .Sh NAME
                     11: .Nm bc
                     12: .Nd arbitrary-precision arithmetic language and calculator
                     13: .Sh SYNOPSIS
                     14: .Nm bc
                     15: .Op Fl c
                     16: .Op Fl l
                     17: .Ar
                     18: .Sh DESCRIPTION
                     19: .Nm Bc
                     20: is an interactive processor for a language which resembles
                     21: C but provides unlimited precision arithmetic.
                     22: It takes input from any files given, then reads
                     23: the standard input.
                     24: The
                     25: .Tp Fl l
                     26: allow specification
                     27: of an arbitrary precision math library.
                     28: .Tp Fl c
                     29: .Nm Bc
                     30: is actually a preprocessor for
                     31: .Ar dc 1 ,
                     32: which it invokes automatically, unless the
                     33: .Fl c
                     34: compile only.
                     35: option is present.
                     36: In this case the
                     37: .Ar dc
                     38: input is sent to the standard output instead.
                     39: .Tp 
                     40: .Pp
                     41: The syntax for
                     42: .Nm bc
                     43: programs is as follows;
                     44: L means letter a-z,
                     45: E means expression, S means statement.
                     46: .Pp
                     47: Comments
                     48: .Ds I
                     49: are enclosed in /* and */.
                     50: .De
                     51: .Pp
                     52: Names
                     53: .Ds I
                     54: simple variables: L
                     55: array elements: L [ E ]
                     56: The words `ibase', `obase', and `scale'
                     57: .De
                     58: .Pp
                     59: Other operands
                     60: .Ds I
                     61: arbitrarily long numbers with optional sign and decimal point.
                     62: \&( E \&)
                     63: sqrt ( E )
                     64: length ( E )   number of significant decimal digits
                     65: scale ( E )    number of digits right of decimal point
                     66: L ( E , ... , E )
                     67: .De
                     68: .Pp
                     69: Operators
                     70: .Ds I
                     71: \&+  \-  *  /  %  ^ (% is remainder; ^ is power)
                     72: \&++   \-\-         (prefix and postfix; apply to names)
                     73: \&==  <=  >=  !=  <  >
                     74: \&=  +=  \-=  *=  /=  %=  ^=
                     75: .De
                     76: .Pp
                     77: Statements
                     78: .Ds I
                     79: E
                     80: { S ; ... ; S }
                     81: if ( E ) S
                     82: while ( E ) S
                     83: for ( E ; E ; E ) S
                     84: null statement
                     85: break
                     86: quit
                     87: .De
                     88: .Pp
                     89: Function definitions
                     90: .Ds I
                     91: define L ( L ,..., L ) {
                     92:        auto L, ... , L
                     93:        S; ... S
                     94:        return ( E )
                     95: }
                     96: .De
                     97: .Pp
                     98: Functions in
                     99: .Fl l
                    100: math library
                    101: .Dw j(n,x)
                    102: .Dp s(x)
                    103: sine
                    104: .Dp c(x)
                    105: cosine
                    106: .Dp e(x)
                    107: exponential
                    108: .Dp l(x)
                    109: log
                    110: .Dp a(x)
                    111: arctangent
                    112: .Dp j(n,x)
                    113: Bessel function
                    114: .Dp
                    115: .Pp
                    116: All function arguments are passed by value.
                    117: .Pp
                    118: The value of a statement that is an expression is printed
                    119: unless the main operator is an assignment.
                    120: Either semicolons or newlines may separate statements.
                    121: Assignment to
                    122: .Ar scale
                    123: influences the number of digits to be retained on arithmetic
                    124: operations in the manner of
                    125: .Xr dc 1 .
                    126: Assignments to
                    127: .Ar ibase
                    128: or
                    129: .Ar obase
                    130: set the input and output number radix respectively.
                    131: .Pp
                    132: The same letter may be used as an array, a function,
                    133: and a simple variable simultaneously.
                    134: All variables are global to the program.
                    135: `Auto' variables are pushed down during function calls.
                    136: When using arrays as function arguments
                    137: or defining them as automatic variables
                    138: empty square brackets must follow the array name.
                    139: .Pp
                    140: For example
                    141: .Pp
                    142: .Ds I
                    143: scale = 20
                    144: define e(x){
                    145:        auto a, b, c, i, s
                    146:        a = 1
                    147:        b = 1
                    148:        s = 1
                    149:        for(i=1; 1==1; i++){
                    150:                a = a*x
                    151:                b = b*i
                    152:                c = a/b
                    153:                if(c == 0) return(s)
                    154:                s = s+c
                    155:        }
                    156: }
                    157: .De
                    158: .Pp
                    159: .fi
                    160: defines a function to compute an approximate value of
                    161: the exponential function and
                    162: .Pp
                    163: .Dl for(i=1; i<=10; i++) e(i)
                    164: .Pp
                    165: prints approximate values of the exponential function of
                    166: the first ten integers.
                    167: .Sh FILES
                    168: .\" /usr/lib/lib.b     mathematical library
                    169: .Dw Dc(1)
                    170: .Di L
                    171: .Dp Pa dc(1)   desk calculator proper
                    172: .Dp
                    173: .Sh SEE ALSO
                    174: .Xr dc 1
                    175: .br
                    176: L. L. Cherry and R. Morris,
                    177: .Em BC \- An arbitrary precision desk-calculator language
                    178: .Sh HISTORY
                    179: The
                    180: .Nm bc
                    181: command appeared in Version 7 AT&T UNIX.
                    182: .Sh BUGS
                    183: No &&, \(or\\(or, or ! operators.
                    184: .br
                    185: .Ql For
                    186: statement must have all three E's.
                    187: .br
                    188: .Ql Quit
                    189: is interpreted when read, not when executed.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.