hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

bc.1 (5240B)


      1 .\"
      2 .\" Sccsid @(#)bc.1	1.7 (gritter) 10/11/03
      3 .\" Derived from bc(1), Unix 7th edition:
      4 .\" Copyright(C) Caldera International Inc. 2001-2002. 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 .\"   Redistributions of source code and documentation must retain the
     10 .\"    above copyright notice, this list of conditions and the following
     11 .\"    disclaimer.
     12 .\"   Redistributions in binary form must reproduce the above copyright
     13 .\"    notice, this list of conditions and the following disclaimer in the
     14 .\"    documentation and/or other materials provided with the distribution.
     15 .\"   All advertising materials mentioning features or use of this software
     16 .\"    must display the following acknowledgement:
     17 .\"      This product includes software developed or owned by Caldera
     18 .\"      International, Inc.
     19 .\"   Neither the name of Caldera International, Inc. nor the names of
     20 .\"    other contributors may be used to endorse or promote products
     21 .\"    derived from this software without specific prior written permission.
     22 .\"
     23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
     24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
     25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     26 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27 .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
     28 .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     31 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     33 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     34 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35 .TH BC 1 "10/11/03" "Heirloom Toolchest" "User Commands"
     36 .SH NAME
     37 bc \- arbitrary-precision arithmetic language
     38 .SH SYNOPSIS
     39 \fBbc\fR [\fB\-c\fR] [\fB\-l\fR] [\fIfile\fR ... ]
     40 .SH DESCRIPTION
     41 .I Bc
     42 is an interactive processor for a language which resembles
     43 C but provides unlimited precision arithmetic.
     44 It takes input from any files given, then reads
     45 the standard input.
     46 The
     47 .B \-l
     48 argument stands for the name
     49 of an arbitrary precision math library.
     50 The syntax for 
     51 .I bc
     52 programs is as follows;
     53 L means letter a-z,
     54 E means expression, S means statement.
     55 .HP 6
     56 Comments
     57 .br
     58 are enclosed in /* and */.
     59 .HP 6
     60 Names
     61 .br
     62 simple variables: L
     63 .br
     64 array elements: L [ E ]
     65 .br
     66 The words `ibase', `obase', and `scale'
     67 .HP 6
     68 Other operands
     69 .br
     70 arbitrarily long numbers with optional sign and decimal point.
     71 .br
     72 ( E )
     73 .br
     74 sqrt ( E )
     75 .br
     76 length ( E )	number of significant decimal digits
     77 .br
     78 scale ( E )	number of digits right of decimal point
     79 .br
     80 L ( E , ... , E )
     81 .HP 6
     82 Operators
     83 .br
     84 +  \-  *  /  %  ^
     85 (% is remainder; ^ is power)
     86 .br
     87 ++   \-\-         (prefix and postfix; apply to names)
     88 .br
     89 ==  <=  >=  !=  <  >
     90 .br
     91 =  =+  =\-  =*  =/  =%  =^
     92 .br
     93 .HP 6
     94 Statements
     95 .br
     96 E
     97 .br
     98 { S ; ... ; S }
     99 .br
    100 if ( E ) S
    101 .br
    102 while ( E ) S
    103 .br
    104 for ( E ; E ; E ) S
    105 .br
    106 null statement
    107 .br
    108 break
    109 .br
    110 quit
    111 .HP 6
    112 Function definitions
    113 .br
    114 define L ( L ,..., L ) {
    115 .br
    116 	auto L, ... , L
    117 .br
    118 	S; ... S
    119 .br
    120 	return ( E )
    121 .br
    122 }
    123 .HP 6
    124 Functions in 
    125 .B \-l
    126 math library
    127 .br
    128 s(x)	sine
    129 .br
    130 c(x)	cosine
    131 .br
    132 e(x)	exponential
    133 .br
    134 l(x)	log
    135 .br
    136 a(x)	arctangent
    137 .br
    138 j(n,x)	Bessel function
    139 .PP
    140 .DT
    141 All function arguments are passed by value.
    142 .PP
    143 The value of a statement that is an expression is printed
    144 unless the main operator is an assignment.
    145 Either semicolons or newlines may separate statements.
    146 Assignment to
    147 .I scale
    148 influences the number of digits to be retained on arithmetic
    149 operations in the manner of
    150 .IR dc (1).
    151 Assignments to
    152 .I ibase
    153 or
    154 .I obase
    155 set the input and output number radix respectively.
    156 .PP
    157 The same letter may be used as an array, a function,
    158 and a simple variable simultaneously.
    159 All variables are global to the program.
    160 `Auto' variables are pushed down during function calls.
    161 When using arrays as function arguments
    162 or defining them as automatic variables
    163 empty square brackets must follow the array name.
    164 .PP
    165 For example
    166 .PP
    167 .nf
    168 scale = 20
    169 define e(x){
    170 	auto a, b, c, i, s
    171 	a = 1
    172 	b = 1
    173 	s = 1
    174 	for(i=1; 1==1; i++){
    175 		a = a*x
    176 		b = b*i
    177 		c = a/b
    178 		if(c == 0) return(s)
    179 		s = s+c
    180 	}
    181 }
    182 .PP
    183 .fi
    184 defines a function to compute an approximate value of
    185 the exponential function and
    186 .PP
    187 .nf
    188 	for(i=1; i<=10; i++) e(i)
    189 .fi
    190 .PP
    191 prints approximate values of the exponential function of
    192 the first ten integers.
    193 .PP
    194 .I Bc
    195 is actually a preprocessor for
    196 .IR dc (1),
    197 which it invokes automatically, unless the
    198 .B \-c
    199 (compile only)
    200 option is present.
    201 In this case the
    202 .I dc
    203 input is sent to the standard output instead.
    204 .SH FILES
    205 .ta \w'/usr/5lib/lib.b 'u
    206 /usr/5lib/lib.b	mathematical library
    207 .br
    208 dc(1)	desk calculator proper
    209 .SH "SEE ALSO"
    210 dc(1)
    211 .br
    212 L. L. Cherry and R. Morris,
    213 .I
    214 BC \- An arbitrary precision desk-calculator language
    215 .SH BUGS
    216 No &&, \(or\|\(or, or ! operators.
    217 .br
    218 .I For
    219 statement must have all three E's.
    220 .br
    221 .I Quit
    222 is interpreted when read, not when executed.