home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
bc-1.03-bin.lha
/
GNU
/
man
/
cat1
/
bc.0
Wrap
Text File
|
1993-12-07
|
42KB
|
1,057 lines
bc(1) bc(1)
NNAAMMEE
bc - An arbitrary precision calculator language
SSYYNNTTAAXX
bbcc [ --llwwss ] [ _f_i_l_e _._._. ]
VVEERRSSIIOONN
This man page documents GNU bc version 1.02.
DDEESSCCRRIIPPTTIIOONN
bbcc is a language that supports arbitrary precision numbers
with interactive execution of statements. There are some
similarities in the syntax to the C programming language.
A standard math library is available by command line
option. If requested, the math library is defined before
processing any files. bbcc starts by processing code from
all the files listed on the command line in the order
listed. After all files have been processed, bbcc reads
from the standard input. All code is executed as it is
read. (If a file contains a command to halt the proces-
sor, bbcc will never read from the standard input.)
This version of bbcc contains several extensions beyond tra-
ditional bbcc implementations and the POSIX draft standard.
Command line options can cause these extensions to print a
warning or to be rejected. This document describes the
language accepted by this processor. Extensions will be
identified as such.
OOPPTTIIOONNSS
-l Define the standard math library.
-w Give warnings for extensions to POSIX bbcc.
-s Process exactly the POSIX bbcc language.
NNUUMMBBEERRSS
The most basic element in bbcc is the number. Numbers are
arbitrary precision numbers. This precision is both in
the integer part and the fractional part. All numbers are
represented internally in decimal and all computation is
done in decimal. (This version truncates results from
divide and multiply operations.) There are two attributes
of numbers, the length and the scale. The length is the
total number of significant decimal digits in a number and
the scale is the total number of decimal digits after the
decimal point. For example:
.000001 has a length of 6 and scale of 6.
1935.000 has a length of 7 and a scale of 3.
VVAARRIIAABBLLEESS
Numbers are stored in two types of variables, simple vari-
ables and arrays. Both simple variables and array vari-
ables are named. Names begin with a letter followed by
. 1
bc(1) bc(1)
any number of letters, digits and underscores. All let-
ters must be lower case. (Full alpha-numeric names are an
extension. In POSIX bbcc all names are a single lower case
letter.) The type of variable is clear by the context
because all array variable names will be followed by
brackets ([]).
There are four special variables, ssccaallee,, iibbaassee,, oobbaassee,, and
llaasstt. ssccaallee defines how some operations use digits after
the decimal point. The default value of ssccaallee is 0. iibbaassee
and oobbaassee define the conversion base for input and output
numbers. The default for both input and output is base
10. llaasstt (an extension) is a variable that has the value
of the last printed number. These will be discussed in
further detail where appropriate. All of these variables
may have values assigned to them as well as used in
expressions.
CCOOMMMMEENNTTSS
Comments in bbcc start with the characters //** and end with
the characters **//. Comments may start anywhere and appear
as a single space in the input. (This causes comments to
delimit other input items. For example, a comment can not
be found in the middle of a variable name.) Comments
include any newlines (end of line) between the start and
the end of the comment.
EEXXPPRREESSSSIIOONNSS
The numbers are manipulated by expressions and statements.
Since the language was designed to be interactive, state-
ments and expressions are executed as soon as possible.
There is no "main" program. Instead, code is executed as
it is encountered. (Functions, discussed in detail later,
are defined when encountered.)
A simple expression is just a constant. bbcc converts con-
stants into internal decimal numbers using the current
input base, specified by the variable iibbaassee. (There is an
exception in functions.) The legal values of iibbaassee are 2
through 16 (F). Assigning a value outside this range to
iibbaassee will result in a value of 2 or 16. Input numbers
may contain the characters 0-9 and A-F. (Note: They must
be capitals. Lower case letters are variable names.)
Single digit numbers always have the value of the digit
regardless of the value of iibbaassee. (i.e. A = 10.) For
multi-digit numbers, bbcc changes all input digits greater
or equal to ibase to the value of iibbaassee-1. This makes the
number FFFFFF always be the largest 3 digit number of the
input base.
Full expressions are similar to many other high level lan-
guages. Since there is only one kind of number, there are
no rules for mixing types. Instead, there are rules on
the scale of expressions. Every expression has a scale.
. 2
bc(1) bc(1)
This is derived from the scale of original numbers, the
operation performed and in many cases, the value of the
variable ssccaallee. Legal values of the variable ssccaallee are 0
to the maximum number representable by a C integer.
In the following descriptions of legal expressions, "expr"
refers to a complete expression and "var" refers to a sim-
ple or an array variable. A simple variable is just a
_n_a_m_e
and an array variable is specified as
_n_a_m_e[_e_x_p_r]
Unless specifically mentioned the scale of the result is
the maximum scale of the expressions involved.
- expr The result is the negation of the expression.
++ var The variable is incremented by one and the new
value is the result of the expression.
-- var The variable is decremented by one and the new
value is the result of the expression.
var ++ The result of the expression is the value of the
variable and then the variable is incremented by
one.
var -- The result of the expression is the value of the
variable and then the variable is decremented by
one.
expr + expr
The result of the expression is the sum of the two
expressions.
expr - expr
The result of the expression is the difference of
the two expressions.
expr * expr
The result of the expression is the product of the
two expressions.
expr / expr
The result of the expression is the quotient of the
two expressions. The scale of the result is the
value of the variable ssccaallee.
expr % expr
The result of the expression is the "remainder" and
it is computed in the following way. To compute
a%b, first a/b is computed to ssccaallee digits. That
result is used to compute a-(