Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bc(1) — A/UX 3.0.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

dc(1)




bc(1) bc(1)
NAME bc - processes an arbitrary-precision arithmetic language SYNOPSIS bc [-c] [-l] [file]... ARGUMENTS -c Causes bc not to invoke dc. If you specify this option, bc output that is normally sent as input to dc is sent to the standard output instead. file Specifies a file that contains statements that bc can interpret. You can use a file argument to set built-in names, such as scale. -l Causes bc to use an arbitrary-precision math library. DESCRIPTION bc is an interactive processor for a language that resembles C but provides unlimited-precision arithmetic. Actually, bc is a preprocessor for the dc command, which it invokes automatically. The bc command reads the standard input, but you can put bc commands in a file that bc reads when it starts up. The section that follow describe the syntax of the bc language, where name is a variable or function name, expression is an expression, and statement is a statement. Comments Comments begin with a slash and an asterisk (/*) and end with an asterisk and a slash (*/). Names You can construct variable names with the letters a through z. Uppercase letters are not allowed. You can reference array elements by using square brackets, as in name[expression]. You can also use these built-in names: ibase Sets the input number radix. obase Sets the output number radix. scale Sets the number of digits that are retained to the right of the decimal point after an arithmetic operation. auto Defines variables that are pushed down during January 1992 1



bc(1) bc(1)
function calls. You can use the same name for an array, a function, and a simple variable simultaneously. All variables are global to the program. When using arrays as function arguments or defining them as automatic variables, you must put empty square brackets after the array name. Other Operands Other operands are constructed from arbitrarily long numbers with an optional sign or an optional decimal point. Here are some examples: (expression) Evaluates the value of expression. sqrt(expression) Returns the square root of expression. length(expression) Returns the number of significant decimal digits in expression. scale(expression) Returns the current value of scale. abc (expression , ... , expression) Calls the function abc with the specified arguments. Operators Here are the available operators: + - * / % ^ ++ -- == <= >= != < > = =+ =- =* =/ =% =^ The percent sign (%) is the modulo operator, and the caret (^) is the exponentiation operator. You can use a double plus sign (++) and a double minus sign (--) as prefix and postfix operators on names. Statements Here are the forms that a statement can take: expression 2 January 1992



bc(1) bc(1)
{statement ; ... ; statement} if (expression) statement while (expression) statement for (expression; expression; expression) statement break quit The value of a statement that is an expression is printed unless the main operator is an assignment. You can separate statements by using a semicolon or a newline character. Two newline characters cannot follow a left brace ({). Function Definitions Here is the form of a function definition: define name (name,..., name) { auto name, ... , name statement; ... statement return (expression) } The bc command passes all function arguments by value. Math Library These functions make up the math library that becomes available when you use the -l option: s(x) sine c(x) cosine e(x) exponential l(x) log a(x) arctangent j(n,x) Bessel function EXAMPLES This sequence defines a function that computes an approximate value for the exponential function: scale = 20 define e(x){ auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1; 1==1; i++){ January 1992 3



bc(1) bc(1)
a = a*x b = b*i c = a/b if(c == 0) return(s) s = s+c } } This sequence calculates approximate values of the exponential function of the integers 1-10: for(i=1; i<=10; i++) e(i) LIMITATIONS The bc command supports neither the logical AND operator (&&) nor the logical OR operator (||). The for statement must have all three expressions. The quit statement is interpreted when it is read rather than when it is executed. FILES /usr/lib/bc Executable file /usr/bin/dc Executable file that bc calls /usr/lib/lib.b Mathematical library file invoked by the -l option SEE ALSO dc(1) ``bc Reference'' in A/UX Programming Languages and Tools, Volume 2 4 January 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026