BSD 4_3_Reno development
[unix-history] / usr / share / man / cat1 / bc.0
CommitLineData
b2cd844e
C
1BC(1) UNIX Reference Manual BC(1)
2
3N\bNA\bAM\bME\bE
4 b\bbc\bc - arbitrary-precision arithmetic language and calculator
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 b\bbc\bc [-\b-c\bc] [-\b-l\bl] [_\bf_\bi_\bl_\be ...]
8
9D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
10 B\bBc\bc is an interactive processor for a language which resembles C but pro-
11 vides unlimited precision arithmetic. It takes input from any files
12 given, then reads the standard input. The
13
14 -\b-l\bl allow specification of an arbitrary precision math library.
15
16 -\b-c\bc B\bBc\bc is actually a preprocessor for _\bd_\bc _\b1, which it invokes au-
17 tomatically, unless the -\b-c\bc compile only. option is present.
18 In this case the _\bd_\bc input is sent to the standard output in-
19 stead.
20
21 The syntax for b\bbc\bc programs is as follows; L means letter a-z, E means ex-
22 pression, S means statement.
23
24 Comments
25 are enclosed in /* and */.
26
27 Names
28 simple variables: L
29 array elements: L [ E ]
30 The words `ibase', `obase', and `scale'
31
32 Other operands
33 arbitrarily long numbers with optional sign and decimal point.
34 ( E )
35 sqrt ( E )
36 length ( E ) number of significant decimal digits
37 scale ( E ) number of digits right of decimal point
38 L ( E , ... , E )
39
40 Operators
41 + - * / % ^ (% is remainder; ^ is power)
42 ++ -- (prefix and postfix; apply to names)
43 == <= >= != < >
44 = += -= *= /= %= ^=
45
46 Statements
47 E
48 { S ; ... ; S }
49 if ( E ) S
50 while ( E ) S
51 for ( E ; E ; E ) S
52 null statement
53 break
54 quit
55
56 Function definitions
57 define L ( L ,..., L ) {
58 auto L, ... , L
59 S; ... S
60 return ( E )
61 }
62
63 Functions in -\b-l\bl math library
64
65 s(x) sine
66 c(x) cosine
67 e(x) exponential
68 l(x) log
69 a(x) arctangent
70 j(n,x) Bessel function
71
72
73 All function arguments are passed by value.
74
75 The value of a statement that is an expression is printed unless the main
76 operator is an assignment. Either semicolons or newlines may separate
77 statements. Assignment to _\bs_\bc_\ba_\bl_\be influences the number of digits to be
78 retained on arithmetic operations in the manner of dc(1). Assignments to
79 _\bi_\bb_\ba_\bs_\be or _\bo_\bb_\ba_\bs_\be set the input and output number radix respectively.
80
81 The same letter may be used as an array, a function, and a simple vari-
82 able simultaneously. All variables are global to the program. `Auto'
83 variables are pushed down during function calls. When using arrays as
84 function arguments or defining them as automatic variables empty square
85 brackets must follow the array name.
86
87 For example
88
89 scale = 20
90 define e(x){
91 auto a, b, c, i, s
92 a = 1
93 b = 1
94 s = 1
95 for(i=1; 1==1; i++){
96 a = a*x
97 b = b*i
98 c = a/b
99 if(c == 0) return(s)
100 s = s+c
101 }
102 }
103
104 defines a function to compute an approximate value of the exponential
105 function and
106
107 for(i=1; i<=10; i++) e(i)
108
109 prints approximate values of the exponential function of the first ten
110 integers.
111
112F\bFI\bIL\bLE\bES\bS
113 _\bd_\bc(_\b1) _\bd_\be_\bs_\bk _\bc_\ba_\bl_\bc_\bu_\bl_\ba_\bt_\bo_\br _\bp_\br_\bo_\bp_\be_\br
114
115
116S\bSE\bEE\bE A\bAL\bLS\bSO\bO
117 dc(1)
118 L. L. Cherry and R. Morris, _\bB_\bC - _\bA_\bn _\ba_\br_\bb_\bi_\bt_\br_\ba_\br_\by _\bp_\br_\be_\bc_\bi_\bs_\bi_\bo_\bn _\bd_\be_\bs_\bk-_\bc_\ba_\bl_\bc_\bu_\bl_\ba_\bt_\bo_\br
119 _\bl_\ba_\bn_\bg_\bu_\ba_\bg_\be
120
121H\bHI\bIS\bST\bTO\bOR\bRY\bY
122 The b\bbc\bc command appeared in Version 7 AT&T UNIX.
123
124B\bBU\bUG\bGS\bS
125 No &&, |\(or, or ! operators.
126 `For' statement must have all three E's.
127 `Quit' is interpreted when read, not when executed.