386BSD 0.1 development
[unix-history] / usr / othersrc / public / bc-1.01 / bc.1
CommitLineData
f87489ac
WJ
1.\"
2.\" bc.1 - the *roff document processor source for the bc manual
3.\"
4.\" This file is part of bc written for MINIX.
5.\" Copyright (C) 1991 Free Software Foundation, Inc.
6.\"
7.\" This program is free software; you can redistribute it and/or modify
8.\" it under the terms of the GNU General Public License as published by
9.\" the Free Software Foundation; either version 2 of the License , or
10.\" (at your option) any later version.
11.\"
12.\" This program is distributed in the hope that it will be useful,
13.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
14.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15.\" GNU General Public License for more details.
16.\"
17.\" You should have received a copy of the GNU General Public License
18.\" along with this program; see the file COPYING. If not, write to
19.\" the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20.\"
21.\" You may contact the author by:
22.\" e-mail: phil@cs.wwu.edu
23.\" us-mail: Philip A. Nelson
24.\" Computer Science Department, 9062
25.\" Western Washington University
26.\" Bellingham, WA 98226-9062
27.\"
28.\"
29.TH bc 1 .\" "Command Manual" v1.01 "Nov 22, 1991"
30.SH NAME
31bc - An arbitrary precision calculator language
32.SH SYNTAX
33\fBbc\fR [ \fB-lws\fR ] [ \fI file ...\fR ]
34.SH DESCRIPTION
35\fBbc\fR is a language that supports arbitrary precision numbers
36with interactive execution of statements. There are some similarities
37in the syntax to the C programming language.
38A standard math library is available by command line option.
39If requested, the math library is defined before processing any files.
40\fBbc\fR starts by processing code from all the files listed
41on the command line in the order listed. After all files have been
42processed, \fBbc\fR reads from the standard input. All code is
43executed as it is read. (If a file contains a command to halt the
44processor, \fBbc\fR will never read from the standard input.)
45.PP
46This version of \fBbc\fR contains several extensions beyond
47traditional \fBbc\fR implementations and the POSIX draft standard.
48Command line options can cause these extensions to print a warning
49or to be rejected. This
50document describes the language accepted by this processor.
51Extensions will be identified as such.
52.SS OPTIONS
53.IP -l
54Define the standard math library.
55.IP -w
56Give warnings for extensions to POSIX \fBbc\fR.
57.IP -s
58Process exactly the POSIX \fBbc\fR language.
59.SS NUMBERS
60The most basic element in \fBbc\fR is the number. Numbers are
61arbitrary precision numbers. This precision is both in the integer
62part and the fractional part. All numbers are represented internally
63in decimal and all computation is done in decimal. (This version
64truncates results from divide and multiply operations.) There are two
65attributes of numbers, the length and the scale. The length is the
66total number of significant decimal digits in a number and the scale
67is the total number of decimal digits after the decimal point. For
68example:
69.nf
70.RS
71 .000001 has a length of 6 and scale of 6.
72 1935.000 has a length of 7 and a scale of 3.
73.RE
74.fi
75.SS VARIABLES
76Numbers are stored in two types of variables, simple variables and
77arrays. Both simple variables and array variables are named. Names
78begin with a letter followed by any number of letters, digits and
79underscores. All letters must be lower case. (Full alpha-numeric
80names are an extension. In POSIX \fBbc\fR all names are a single
81lower case letter.) The type of variable is clear by the context
82because all array variable names will be followed by brackets ([]).
83.PP
84There are four special variables, \fBscale, ibase, obase,\fR and
85\fBlast\fR. \fBscale\fR defines how some operations use digits after the
86decimal point. The default value of \fBscale\fR is 0. \fBibase\fR
87and \fBobase\fR define the conversion base for input and output
88numbers. The default for both input and output is base 10.
89\fBlast\fR (an extension) is a variable that has the value of the last
90printed number. These will be discussed in further detail where
91appropriate. All of these variables may have values assigned to them
92as well as used in expressions.
93.SS COMMENTS
94Comments in \fBbc\fR start with the characters \fB/*\fR and end with
95the characters \fB*/\fR. Comments may start anywhere and appear as a
96single space in the input. (This causes comments to delimit other
97input items. For example, a comment can not be found in the middle of
98a variable name.) Comments include any newlines (end of line) between
99the start and the end of the comment.
100.SS EXPRESSIONS
101The numbers are manipulated by expressions and statements. Since
102the language was designed to be interactive, statements and expressions
103are executed as soon as possible. There is no "main" program. Instead,
104code is executed as it is encountered. (Functions, discussed in
105detail later, are defined when encountered.)
106.PP
107A simple expression is just a constant. \fBbc\fR converts constants
108into internal decimal numbers using the current input base, specified
109by the variable \fBibase\fR. (There is an exception in functions.)
110The legal values of \fBibase\fR are 2 through 16 (F). Assigning a
111value outside this range to \fBibase\fR will result in a value of 2
112or 16. Input numbers may contain the characters 0-9 and A-F. (Note:
113They must be capitals. Lower case letters are variable names.)
114Single digit numbers always have the value of the digit regardless of
115the value of \fBibase\fR. (i.e. A = 10.) For multi-digit numbers,
116\fBbc\fR changes all input digits greater or equal to ibase to the
117value of \fBibase\fR-1. This makes the number \fBFFF\fR always be
118the largest 3 digit number of the input base.
119.PP
120Full expressions are similar to many other high level languages.
121Since there is only one kind of number, there are no rules for mixing
122types. Instead, there are rules on the scale of expressions. Every
123expression has a scale. This is derived from the scale of original
124numbers, the operation performed and in many cases, the value of the
125variable \fBscale\fR. Legal values of the variable \fBscale\fR are
1260 to the maximum number representable by a C integer.
127.PP
128In the following descriptions of legal expressions, "expr" refers to a
129complete expression and "var" refers to a simple or an array variable.
130A simple variable is just a
131.RS
132\fIname\fR
133.RE
134and an array variable is specified as
135.RS
136\fIname\fR[\fIexpr\fR]
137.RE
138Unless specifically
139mentioned the scale of the result is the maximum scale of the
140expressions involved.
141.IP "- expr"
142The result is the negation of the expression.
143.IP "++ var"
144The variable is incremented by one and the new value is the result of
145the expression.
146.IP "-- var"
147The variable
148is decremented by one and the new value is the result of the
149expression.
150.IP "var ++"
151 The result of the expression is the value of
152the variable and then the variable is incremented by one.
153.IP "var --"
154The result of the expression is the value of the variable and then
155the variable is decremented by one.
156.IP "expr + expr"
157The result of the expression is the sum of the two expressions.
158.IP "expr - expr"
159The result of the expression is the difference of the two expressions.
160.IP "expr * expr"
161The result of the expression is the product of the two expressions.
162.IP "expr / expr"
163The result of the expression is the quotient of the two expressions.
164The scale of the result is the value of the variable \fBscale\fR.
165.IP "expr % expr"
166The result of the expression is the "remainder" and it is computed in the
167following way. To compute a%b, first a/b is computed to \fBscale\fR
168digits. That result is used to compute a-(a/b)*b to the scale of the
169maximum of \fBscale\fR+scale(b) and scale(a). If \fBscale\fR is set
170to zero and both expressions are integers this expression is the
171integer remainder function.
172.IP "expr ^ expr"
173The result of the expression is the value of the first raised to the
174second. The second expression must be an integer. (If the second
175expression is not an integer, a warning is generated and the
176expression is truncated to get an integer value.) The scale of the
177result is \fBscale\fR if the exponent is negative. If the exponent
178is positive the scale of the result is the minimum of the scale of the
179first expression times the value of the exponent and the maximum of
180\fBscale\fR and the scale of the first expression. (e.g. scale(a^b)
181= min(scale(a)*b, max( \fBscale,\fR scale(a))).) It should be noted
182that expr^0 will always return the value of 1.
183.IP "( expr )"
184This alters the standard precedence to force the evaluation of the
185expression.
186.IP "var = expr"
187The variable is assigned the value of the expression.
188.IP "var <op>= expr"
189This is equivalent to "var = var <op> expr" with the exception that
190the "var" part is evaluated only once. This can make a difference if
191"var" is an array.
192.PP
193 Relational expressions are a special kind of expression
194that always evaluate to 0 or 1, 0 if the relation is false and 1 if
195the relation is true. These may appear in any legal expression.
196(POSIX bc requires that relational expressions are used only in if,
197while, and for statements and that only one relational test may be
198done in them.) The relational operators are
199.IP "expr1 < expr2"
200The result is 1 if expr1 is strictly less than expr2.
201.IP "expr1 <= expr2"
202The result is 1 if expr1 is less than or equal to expr2.
203.IP "expr1 > expr2"
204The result is 1 if expr1 is strictly greater than expr2.
205.IP "expr1 >= expr2"
206The result is 1 if expr1 is greater than or equal to expr2.
207.IP "expr1 == expr2"
208The result is 1 if expr1 is equal to expr2.
209.IP "expr1 != expr2"
210The result is 1 if expr1 is not equal to expr2.
211.PP
212Boolean operations are also legal. (POSIX \fBbc\fR does NOT have
213boolean operations). The result of all boolean operations are 0 and 1
214(for false and true) as in relational expressions. The boolean
215operators are:
216.IP "!expr"
217The result is 1 if expr is 0.
218.IP "expr && expr"
219The result is 1 if both expressions are non-zero.
220.IP "expr || expr"
221The result is 1 if either expression is non-zero.
222.PP
223The expression precedence is as follows: (lowest to highest)
224.nf
225.RS
226|| operator, left associative
227&& operator, left associative
228! operator, nonassociative
229Relational operators, left associative
230Assignment operator, right associative
231+ and - operators, left associative
232*, / and % operators, left associative
233^ operator, right associative
234unary - operator, nonassociative
235++ and -- operators, nonassociative
236.RE
237.fi
238.PP
239This precedence was chosen so that POSIX compliant \fBbc\fR programs
240will run correctly. This will cause the use of the relational and
241logical operators to have some unusual behavior when used with
242assignment expressions. Consider the expression:
243.RS
244a = 3 < 5
245.RE
246.PP
247Most C programmers would assume this would assign the result of "3 <
2485" (the value 1) to the variable "a". What this does in \fBbc\fR is
249assign the value 3 to the variable "a" and then compare 3 to 5. It is
250best to use parenthesis when using relational and logical operators
251with the assignment operators.
252.PP
253There are a few more special expressions that are provided in \fBbc\fR.
254These have to do with user defined functions and standard
255functions. They all appear as "\fIname\fB(\fIparameters\fB)\fR".
256See the section on functions for user defined functions. The standard
257functions are:
258.IP "length ( expression )"
259The value of the length function is the number of significant digits in the
260expression.
261.IP "read ( )"
262The read function (an extension) will read a number from the standard
263input, regardless of where the function occurs. Beware, this can
264cause problems with the mixing of data and program in the standard input.
265The best use for this function is in a previously written program that
266needs input from the user, but never allows program code to be input
267from the user. The value of the read function is the number read from
268the standard input using the current value of the variable
269\fBibase\fR for the conversion base.
270.IP "scale ( expression )"
271The value of the scale function is the number of digits after the decimal
272point in the expression.
273.IP "sqrt ( expression )"
274The value of the sqrt function is the square root of the expression. If
275the expression is negative, a run time error is generated.
276.SS STATEMENTS
277Statements (as in most algebraic languages) provide the sequencing of
278expression evaluation. In \fBbc\fR statements are executed "as soon
279as possible." Execution happens when a newline in encountered and
280there is one or more complete statements. Due to this immediate
281execution, newlines are very important in \fBbc\fR. In fact, both a
282semicolon and a newline are used as statement separators. An
283improperly placed newline will cause a syntax error. Because newlines
284are statement separators, it is possible to hide a newline by using
285the backslash character. The sequence "\e<nl>", where <nl> is the
286newline appears to \fBbc\fR as whitespace instead of a newline. A
287statement list is a series of statements separated by semicolons and
288newlines. The following is a list of \fBbc\fR statements and what
289they do: (Things enclosed in brackets ([]) are optional parts of the
290statement.)
291.IP "expression"
292This statement does one of two things. If the expression starts with
293"<variable> <assignment> ...", it is considered to be an assignment
294statement. If the expression is not an assignment statement, the
295expression is evaluated and printed to the output. After the number
296is printed, a newline is printed. For example, "a=1" is an assignment
297statement and "(a=1)" is an expression that has an embedded
298assignment. All numbers that are printed are printed in the base
299specified by the variable \fBobase\fR. The legal values for \fB
300obase\fR are 2 through BC_BASE_MAX. (See the section LIMITS.) For
301bases 2 through 16, the usual method of writing numbers is used. For
302bases greater than 16, \fBbc\fR uses a multi-character digit method
303of printing the numbers where each higher base digit is printed as a
304base 10 number. The multi-character digits are separated by spaces.
305Each digit contains the number of characters required to represent the
306base ten value of "obase-1". Since numbers are of arbitrary
307precision, some numbers may not be printable on a single output line.
308These long numbers will be split across lines using the "\e" as the
309last character on a line. The maximum number of characters printed
310per line is 70. Due to the interactive nature of \fBbc\fR printing
311a number cause the side effect of assigning the printed value the the
312special variable \fBlast\fR. This allows the user to recover the
313last value printed without having to retype the expression that
314printed the number. Assigning to \fBlast\fR is legal and will
315overwrite the last printed value with the assigned value. The newly
316assigned value will remain until the next number is printed or another
317value is assigned to \fBlast\fR.
318.IP "string"
319The string is printed to the output. Strings start with a double quote
320character and contain all characters until the next double quote character.
321All characters are take literally, including any newline. No newline
322character is printed after the string.
323.IP "\fBprint\fR list"
324The print statement (an extension) provides another method of output.
325The "list" is a list of strings and expressions separated by commas.
326Each string or expression is printed in the order of the list. No
327terminating newline is printed. Expressions are evaluated and their
328value is printed and assigned the the variable \fBlast\fR. Strings
329in the print statement are printed to the output and may contain
330special characters. Special characters start with the backslash
331character (\e). The special characters recognized by \fBbc\fR are
332"b" (bell), "f" (form feed), "n" (newline), "r" (carriage return), "t"
333(tab), and "\e" (backslash). Any other character following the
334backslash will be ignored. This still does not allow the double quote
335character to be part of any string.
336.IP "{ statement_list }"
337This is the compound statement. It allows multiple statements to be
338grouped together for execution.
339.IP "\fBif\fR ( expression ) \fBthen\fR statement1 [\fBelse\fR statement2]"
340The if statement evaluates the expression and executes statement1 or
341statement2 depending on the value of the expression. If the expression
342is non-zero, statement1 is executed. If statement2 is present and
343the value of the expression is 0, then statement2 is executed. (The
344else clause is an extension.)
345.IP "\fBwhile\fR ( expression ) statement"
346The while statement will execute the statement while the expression
347is non-zero. It evaluates the expression before each execution of
348the statement. Termination of the loop is caused by a zero
349expression value or the execution of a break statement.
350.IP "\fBfor\fR ( [expression1] ; [expression2] ; [expression3] ) statement"
351The for statement controls repeated execution of the statement.
352Expression1 is evaluated before the loop. Expression2 is evaluated
353before each execution of the statement. If it is non-zero, the statement
354is evaluated. If it is zero, the loop is terminated. After each
355execution of the statement, expression3 is evaluated before the reevaluation
356of expression2. If expression1 or expression3 are missing, nothing is
357evaluated at the point they would be evaluated.
358If expression2 is missing, it is the same as substituting
359the value 1 for expression2. (The optional expressions are an
360extension. POSIX \fBbc\fR requires all three expressions.)
361The following is equivalent code for the for statement:
362.nf
363.RS
364expression1;
365while (expression2) {
366 statement;
367 expression3;
368}
369.RE
370.fi
371.IP "\fBbreak\fR"
372This statement causes a forced exit of the most recent enclosing while
373statement or for statement.
374.IP "\fBcontinue\fR"
375The continue statement (an extension) causes the most recent enclosing
376for statement to start the next iteration.
377.IP "\fBhalt\fR"
378The halt statement (an extension) is an executed statement that causes
379the \fBbc\fR processor to quit only when it is executed. For example,
380"if (0 == 1) halt" will not cause \fBbc\fR to terminate because the halt is
381not executed.
382.IP "\fBreturn\fR"
383Return the value 0 from a function. (See the section on functions.)
384.IP "\fBreturn\fR ( expression )"
385Return the value of the expression from a function. (See the section on
386functions.)
387.SS PSEUDO STATEMENTS
388These statements are not statements in the traditional sense. They are
389not executed statements. Their function is performed at "compile" time.
390.IP "\fBlimits\fR"
391Print the local limits enforced by the local version of \fBbc\fR. This
392is an extension.
393.IP "\fBquit\fR"
394When the quit statement is read, the \fBbc\fR processor
395is terminated, regardless of where the quit statement is found. For
396example, "if (0 == 1) quit" will cause \fBbc\fR to terminate.
397.IP "\fBwarranty\fR"
398Print a longer warranty notice. This is an extension.
399.SS FUNCTIONS
400Functions provide a method of defining a computation that can be executed
401later. Functions in
402.B bc
403always compute a value and return it to the caller. Function definitions
404are "dynamic" in the sense that a function is undefined until a definition
405is encountered in the input. That definition is then used until another
406definition function for the same name is encountered. The new definition
407then replaces the older definition. A function is defined as follows:
408.nf
409.RS
410\fBdefine \fIname \fB( \fIparameters \fB) { \fInewline
411\fI auto_list statement_list \fB}\fR
412.RE
413.fi
414A function call is just an expression of the form
415"\fIname\fB(\fIparameters\fB)\fR".
416.PP
417Parameters are numbers or arrays (an extension). In the function definition,
418zero or more parameters are defined by listing their names separated by
419commas. Numbers are only call by value parameters. Arrays are only
420call by variable. Arrays are specified in the parameter definition by
421the notation "\fIname\fB[]\fR". In the function call, actual parameters
422are full expressions for number parameters. The same notation is used
423for passing arrays as for defining array parameters. The named array is
424passed by variable to the function. Since function definitions are dynamic,
425parameter numbers and types are checked when a function is called. Any
426mismatch in number or types of parameters will cause a runtime error.
427A runtime error will also occur for the call to an undefined function.
428.PP
429The \fIauto_list\f is an optional list of variables that are for
430"local" use. The syntax of the auto list (if present) is "\fBauto
431\fIname\fR, ... ;". (The semicolon is optional.) Each \fIname\fR is
432the name of an auto variable. Arrays may be specified by using the
433same notation as used in parameters. These variables have their
434values pushed onto a stack at the start of the function. The
435variables are then initialized to zero and used throughout the
436execution of the function. At function exit, these variables are
437popped so that the original value (at the time of the function call)
438of these variables are restored. The parameters are really auto
439variables that are initialized to a value provided in the function
440call. Auto variables are different than traditional local variables
441in the fact that if function A calls function B, B may access function
442A's auto variables by just using the same name, unless function B has
443called them auto variables. Due to the fact that auto variables and
444parameters are pushed onto a stack, \fBbc\fR supports recursive functions.
445.PP
446The function body is a list of \fBbc\fR statements. Again, statements
447are separated by semicolons or newlines. Return statements cause the
448termination of a function and the return of a value. There are two
449versions of the return statement. The first form, "\fBreturn\fR", returns
450the value 0 to the calling expression. The second form,
451"\fBreturn ( \fIexpression \fB)\fR", computes the value of the expression
452and returns that value to the calling expression. There is an implied
453"\fBreturn (0)\fR" at the end of every function. This allows a function
454to terminate and return 0 without an explicit return statement.
455.PP
456Functions also change the usage of the variable \fBibase\fR. All
457constants in the function body will be converted using the value of
458\fBibase\fR at the time of the function call. Changes of \fBibase\fR
459will be ignored during the execution of the function except for the
460standard function \fBread\fR, which will always use the current value
461of \fBibase\fR for conversion of numbers.
462.SS MATH LIBRARY
463If \fBbc\fR is invoked with the \fB-l\fR option, a math library is preloaded
464and the default scale is set to 20. The math functions will calculate their
465results to the scale set at the time of their call.
466The math library defines the following functions:
467.IP "s (\fIx\fR)"
468The sine of x in radians.
469.IP "c (\fIx\fR)"
470The cosine of x in radians.
471.IP "a (\fIx\fR)"
472The arctangent of x.
473.IP "l (\fIx\fR)"
474The natural logarithm of x.
475.IP "e (\fIx\fR)"
476The exponential function of raising e to the value x.
477.IP "j (\fIn,x\fR)"
478The bessel function of integer order n of x.
479.SS EXAMPLES
480In /bin/sh, the following will assign the value of "pi" to the shell
481variable \fBpi\fR.
482.RS
483\f(CW
484pi=$(echo "scale=10; 4*a(1)" | bc -l)
485\fR
486.RE
487.PP
488The following is the definition of the exponential function used in the
489math library. This function is written in POSIX \fBbc\fR.
490.nf
491.RS
492\f(CW
493scale = 20
494
495/* Uses the fact that e^x = (e^(x/2))^2
496 When x is small enough, we use the series:
497 e^x = 1 + x + x^2/2! + x^3/3! + ...
498*/
499
500define e(x) {
501 auto a, d, e, f, i, m, v, z
502
503 /* Check the sign of x. */
504 if (x<0) {
505 m = 1
506 x = -x
507 }
508
509 /* Precondition x. */
510 z = scale;
511 scale = 4 + z + .44*x;
512 while (x > 1) {
513 f += 1;
514 x /= 2;
515 }
516
517 /* Initialize the variables. */
518 v = 1+x
519 a = x
520 d = 1
521
522 for (i=2; 1; i++) {
523 e = (a *= x) / (d *= i)
524 if (e == 0) {
525 if (f>0) while (f--) v = v*v;
526 scale = z
527 if (m) return (1/v);
528 return (v/1);
529 }
530 v += e
531 }
532}
533\fR
534.RE
535.fi
536.PP
537The following is code that uses the extended features of \fBbc\fR to
538implement a simple program for calculating checkbook balances. This
539program is best kept in a file so that it can be used many times
540without having to retype it at every use.
541.nf
542.RS
543\f(CW
544scale=2
545print "\enCheck book program!\en"
546print " Remember, deposits are negative transactions.\en"
547print " Exit by a 0 transaction.\en\en"
548
549print "Initial balance? "; bal = read()
550bal /= 1
551print "\en"
552while (1) {
553 "current balance = "; bal
554 "transaction? "; trans = read()
555 if (trans == 0) break;
556 bal -= trans
557 bal /= 1
558}
559quit
560\fR
561.RE
562.fi
563.PP
564The following is the definition of the recursive factorial function.
565.nf
566.RS
567\f(CW
568define f (x) {
569 if (x <= 1) return (1);
570 return (f(x-1) * x);
571}
572\fR
573.RE
574.fi
575.SS DIFFERENCES
576This version of
577.B bc
578was implemented from the POSIX P1003.2/D11 draft and contains
579several differences and extensions relative to the draft and
580traditional implementations.
581It is not implemented in the traditional way using
582.I dc(1).
583This version is a single process which parses and runs a byte code
584translation of the program. There is an "undocumented" option (-c)
585that causes the program to output the byte code to
586the standard output instead of running it. It was mainly used for
587debugging the parser and preparing the math library.
588.PP
589A major source of differences is
590extensions, where a feature is extended to add more functionality and
591 additions, where new features are added.
592The following is the list of differences and extensions.
593.IP LANG environment
594This version does not conform to the POSIX standard in the processing
595of the LANG environment variable and all environment variables starting
596with LC_.
597.IP names
598Traditional and POSIX
599.B bc
600have single letter names for functions, variables and arrays. They have
601been extended to be multi-character names that start with a letter and
602may contain letters, numbers and the underscore character.
603.IP last
604POSIX \fBbc\fR does not have a \fBlast\fR variable. Some implementations
605of \fBbc\fR use the period (.) in a similar way.
606.IP comparisons
607POSIX \fBbc\fR allows comparisons only in the if statement, the while
608statement, and the second expression of the for statement. Also, only
609one relational operation is allowed in each of those statements.
610.IP "if statement, else clause"
611POSIX \fBbc\fR does not have an else clause.
612.IP "for statement"
613POSIX \fBbc\fR requires all expressions to be present in the for statement.
614.IP "&&, ||, !"
615POSIX \fBbc\fR does not have the logical operators.
616.IP "read function"
617POSIX \fBbc\fR does not have a read function.
618.IP "print statement"
619POSIX \fBbc\fR does not have a print statement .
620.IP "continue statement"
621POSIX \fBbc\fR does not have a continue statement.
622.IP "array parameters"
623POSIX \fBbc\fR does not have array parameters. Other implementations
624of \fBbc\fR may have call by value array parameters.
625.IP "=+, =-, =*, =/, =%, =^"
626POSIX \fBbc\fR does not require these "old style" assignment operators to
627be defined. This version may allow these "old style" assignments. Use
628the limits statement to see if the installed version supports them. If
629it does support the "old style" assignment operators, the statement
630"a =- 1" will decrement \fBa\fR by 1 instead of setting \fBa\fR to the
631value -1.
632.IP "spaces in numbers"
633Other implementations of \fBbc\fR allow spaces in numbers. For example,
634"x=1 3" would assign the value 13 to the variable x. The same statement
635would cause a syntax error in this version of \fBbc\fR.
636.IP "errors and execution"
637This implementation varies from other implementations in terms of what
638code will be executed when syntax and other errors are found in the
639program. If a syntax error is found in a function definition, error
640recovery tries to find the beginning of a statement and continue to
641parse the function. Once a syntax error is found in the function, the
642function will not be callable and becomes undefined.
643Syntax errors in the interactive execution code will invalidate the
644current execution block. The execution block is terminated by an
645end of line that appears after a complete sequence of statements.
646For example,
647.nf
648.RS
649a = 1
650b = 2
651.RE
652.fi
653has two execution blocks and
654.nf
655.RS
656{ a = 1
657 b = 2 }
658.RE
659.fi
660has one execution block. Any runtime error will terminate the execution
661of the current execution block. A runtime warning will not terminate the
662current execution block.
663.SS LIMITS
664The following are the limits currently in place for this
665.B bc
666processor. Some of them may have been changed by an installation.
667Use the limits statement to see the actual values.
668.IP BC_BASE_MAX
669The maximum output base is currently set at 999. The maximum input base
670is 16.
671.IP BC_DIM_MAX
672This is currently an arbitrary limit of 65535 as distributed. Your
673installation may be different.
674.IP BC_SCALE_MAX
675The number of digits after the decimal point is limited to INT_MAX digits.
676Also, the number of digits before the decimal point is limited to INT_MAX
677digits.
678.IP BC_STRING_MAX
679The limit on the number of characters in a string is INT_MAX characters.
680.IP exponent
681The value of the exponent in the raise operation (^) is limited to LONG_MAX.
682.IP multiply
683The multiply routine may yield incorrect results if a number
684has more than LONG_MAX / 90 total digits. For 32 bit longs, this number is
68523,860,929 digits.
686.IP "code size"
687Each function and the "main" program are limited to 10240 bytes of
688compiled byte code each. This limit (BC_MAX_SEGS) can be easily changed
689to have more than 10 segments of 1024 bytes.
690.IP "variable names"
691The current limit on the number of unique names is 32767 for each of
692simple variables, arrays and functions.
693.SH FILES
694In most installations, \fBbc\fR is completely self-contained.
695Where executable size is of importance or the C compiler does
696not deal with very long strings, \fBbc\fR will read
697the standard math library from the file /usr/local/lib/libmath.b.
698(The actual location may vary. It may be /lib/libmath.b.)
699.SH DIAGNOSTICS
700If any file on the command line can not be opened, \fBbc\fR will report
701that the file is unavailable and terminate. Also, there are compile
702and run time diagnostics that should be self-explanatory.
703.SH BUGS
704Error recovery is not very good yet.
705.SH AUTHOR
706.nf
707Philip A. Nelson
708phil@cs.wwu.edu
709.fi
710.SH ACKNOWLEDGEMENTS
711The author would like to thank Steve Sommars (sesv@iwtsf.att.com) for
712his extensive help in testing the implementation. Many great suggestions
713were given. This is a much better product due to his involvement.