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