summaryrefslogtreecommitdiff
path: root/doc/bc.1
diff options
context:
space:
mode:
Diffstat (limited to 'doc/bc.1')
-rw-r--r--doc/bc.1115
1 files changed, 73 insertions, 42 deletions
diff --git a/doc/bc.1 b/doc/bc.1
index c0b03f7..eeda08b 100644
--- a/doc/bc.1
+++ b/doc/bc.1
@@ -2,7 +2,7 @@
.\" bc.1 - the *roff document processor source for the bc manual
.\"
.\" This file is part of GNU bc.
-.\" Copyright (C) 1991-1994, 1997, 2000 Free Software Foundation, Inc.
+.\" Copyright (C) 1991-1994, 1997, 2000, 2003, 2006, 2017 Free Software Foundation, Inc.
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
@@ -17,8 +17,8 @@
.\" You should have received a copy of the GNU General Public License
.\" along with this program; see the file COPYING. If not, write to:
.\" The Free Software Foundation, Inc.
-.\" 59 Temple Place, Suite 330
-.\" Boston, MA 02111 USA
+.\" 51 Franklin Street, Fifth Floor
+.\" Boston, MA 02110-1301 USA
.\"
.\" You may contact the author by:
.\" e-mail: philnelson@acm.org
@@ -28,13 +28,11 @@
.\" Bellingham, WA 98226-9062
.\"
.\"
-.TH bc 1 .\" "Command Manual" v1.06 "Sept 12, 2000"
+.TH bc 1 "2006-06-11" "GNU Project"
.SH NAME
bc - An arbitrary precision calculator language
.SH SYNTAX
\fBbc\fR [ \fB-hlwsqv\fR ] [long-options] [ \fI file ...\fR ]
-.SH VERSION
-This man page documents GNU bc version 1.06.
.SH DESCRIPTION
\fBbc\fR is a language that supports arbitrary precision numbers
with interactive execution of statements. There are some similarities
@@ -75,9 +73,9 @@ 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:
+total number of decimal digits used by \fBbc\fR to represent a number
+and the scale is the total number of decimal digits after the decimal
+point. For example:
.nf
.RS
.000001 has a length of 6 and scale of 6.
@@ -124,15 +122,16 @@ detail later, are defined when encountered.)
A simple expression is just a constant. \fBbc\fR converts constants
into internal decimal numbers using the current input base, specified
by the variable \fBibase\fR. (There is an exception in functions.)
-The legal values of \fBibase\fR are 2 through 16. Assigning a
-value outside this range to \fBibase\fR 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 \fBibase\fR. (i.e. A = 10.) For multi-digit numbers,
-\fBbc\fR changes all input digits greater or equal to ibase to the
-value of \fBibase\fR-1. This makes the number \fBFFF\fR always be
-the largest 3 digit number of the input base.
+The legal values of \fBibase\fR are 2 through 36. (Bases greater than
+16 are an extension.) Assigning a value outside this range to
+\fBibase\fR will result in a value of 2 or 36. Input numbers may
+contain the characters 0-9 and A-Z. (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
+\fBibase\fR. (i.e. A = 10.) For multi-digit numbers, \fBbc\fR changes
+all input digits greater or equal to ibase to the value of
+\fBibase\fR-1. This makes the number \fBZZZ\fR always be the largest
+3 digit number of the input base.
.PP
Full expressions are similar to many other high level languages.
Since there is only one kind of number, there are no rules for mixing
@@ -207,7 +206,7 @@ This is equivalent to "var = var <op> expr" with the exception that
the "var" part is evaluated only once. This can make a difference if
"var" is an array.
.PP
- Relational expressions are a special kind of expression
+Relational expressions are a special kind of expression
that always evaluate to 0 or 1, 0 if the relation is false and 1 if
the relation is true. These may appear in any legal expression.
(POSIX bc requires that relational expressions are used only in if,
@@ -434,12 +433,12 @@ A function call is just an expression of the form
.PP
Parameters are numbers or arrays (an extension). In the function definition,
zero or more parameters are defined by listing their names separated by
-commas. Numbers are only call by value parameters. Arrays are only
-call by variable. Arrays are specified in the parameter definition by
+commas. All parameters are call by value parameters.
+Arrays are specified in the parameter definition by
the notation "\fIname\fB[]\fR". In the function call, actual parameters
are full expressions for number parameters. The same notation is used
for passing arrays as for defining array parameters. The named array is
-passed by variable to the function. Since function definitions are dynamic,
+passed by value to the function. Since function definitions are dynamic,
parameter numbers and types are checked when a function is called. Any
mismatch in number or types of parameters will cause a runtime error.
A runtime error will also occur for the call to an undefined function.
@@ -478,12 +477,12 @@ will be ignored during the execution of the function except for the
standard function \fBread\fR, which will always use the current value
of \fBibase\fR for conversion of numbers.
.PP
-As an extension, the format of the definition has been slightly relaxed.
-The standard requires the opening brace be on the same line as the
-\fBdefine\fR keyword and all other parts must be on following lines.
-This version of \fBbc\fR will allow any number of newlines before and
-after the opening brace of the function. For example, the following
-definitions are legal.
+Several extensions have been added to functions. First, the format of
+the definition has been slightly relaxed. The standard requires the
+opening brace be on the same line as the \fBdefine\fR keyword and all
+other parts must be on following lines. This version of \fBbc\fR will
+allow any number of newlines before and after the opening brace of the
+function. For example, the following definitions are legal.
.nf
.RS
\f(CW
@@ -493,6 +492,36 @@ define d (n)
\fR
.RE
.fi
+.PP
+Functions may be defined as \fBvoid\fR. A void
+funtion returns no value and thus may not be used in any place that needs
+a value. A void function does not produce any output when called by itself
+on an input line. The key word \fBvoid\fR is placed between the key word
+\fBdefine\fR and the function name. For example, consider the following
+session.
+.nf
+.RS
+\f(CW
+define py (y) { print "--->", y, "<---", "\en"; }
+define void px (x) { print "--->", x, "<---", "\en"; }
+py(1)
+--->1<---
+0
+px(1)
+--->1<---
+\fR
+.RE
+.fi
+Since \fBpy\fR is not a void function, the call of \fBpy(1)\fR prints
+the desired output and then prints a second line that is the value of
+the function. Since the value of a function that is not given an
+explicit return statement is zero, the zero is printed. For \fBpx(1)\fR,
+no zero is printed because the function is a void function.
+.PP
+Also, call by variable for arrays was added. To declare
+a call by variable array, the declaration of the array parameter in the
+function definition looks like "\fI*name\fB[]\fR". The call to the
+function remains the same as call by value arrays.
.SS MATH LIBRARY
If \fBbc\fR is invoked with the \fB-l\fR option, a math library is preloaded
and the default scale is set to 20. The math functions will calculate their
@@ -509,7 +538,7 @@ The natural logarithm of x.
.IP "e (\fIx\fR)"
The exponential function of raising e to the value x.
.IP "j (\fIn,x\fR)"
-The bessel function of integer order n of x.
+The Bessel function of integer order n of x.
.SS EXAMPLES
In /bin/sh, the following will assign the value of "pi" to the shell
variable \fBpi\fR.
@@ -639,23 +668,23 @@ A major source of differences is
extensions, where a feature is extended to add more functionality and
additions, where new features are added.
The following is the list of differences and extensions.
-.IP LANG environment
+.IP "LANG environment"
This version does not conform to the POSIX standard in the processing
of the LANG environment variable and all environment variables starting
with LC_.
-.IP names
+.IP "names"
Traditional and POSIX
.B bc
have single letter names for functions, variables and arrays. They have
been extended to be multi-character names that start with a letter and
may contain letters, numbers and the underscore character.
-.IP Strings
+.IP "Strings"
Strings are not allowed to contain NUL characters. POSIX says all characters
must be included in strings.
-.IP last
+.IP "last"
POSIX \fBbc\fR does not have a \fBlast\fR variable. Some implementations
of \fBbc\fR use the period (.) in a similar way.
-.IP comparisons
+.IP "comparisons"
POSIX \fBbc\fR allows comparisons only in the if statement, the while
statement, and the second expression of the for statement. Also, only
one relational operation is allowed in each of those statements.
@@ -737,19 +766,19 @@ The following are the limits currently in place for this
.B bc
processor. Some of them may have been changed by an installation.
Use the limits statement to see the actual values.
-.IP BC_BASE_MAX
+.IP "BC_BASE_MAX"
The maximum output base is currently set at 999. The maximum input base
is 16.
-.IP BC_DIM_MAX
+.IP "BC_DIM_MAX"
This is currently an arbitrary limit of 65535 as distributed. Your
installation may be different.
-.IP BC_SCALE_MAX
+.IP "BC_SCALE_MAX"
The number of digits after the decimal point is limited to INT_MAX digits.
Also, the number of digits before the decimal point is limited to INT_MAX
digits.
-.IP BC_STRING_MAX
+.IP "BC_STRING_MAX"
The limit on the number of characters in a string is INT_MAX characters.
-.IP exponent
+.IP "exponent"
The value of the exponent in the raise operation (^) is limited to LONG_MAX.
.IP "variable names"
The current limit on the number of unique names is 32767 for each of
@@ -761,16 +790,18 @@ This is the same as the \fB-s\fR option.
.IP "BC_ENV_ARGS"
This is another mechanism to get arguments to \fBbc\fR. The
format is the same as the command line arguments. These arguments
-are processed first, so any files listed in the environent arguments
+are processed first, so any files listed in the environment arguments
are processed before any command line argument files. This allows
the user to set up "standard" options and files to be processed
at every invocation of \fBbc\fR. The files in the environment
variables would typically contain function definitions for functions
the user wants defined every time \fBbc\fR is run.
.IP "BC_LINE_LENGTH"
-This should be an integer specifing the number of characters in an
+This should be an integer specifying the number of characters in an
output line for numbers. This includes the backslash and newline characters
-for long numbers.
+for long numbers. As an extension, the value of zero disables the
+multi-line feature. Any other value of this variable that is less than
+3 sets the line length to 70.
.SH DIAGNOSTICS
If any file on the command line can not be opened, \fBbc\fR will report
that the file is unavailable and terminate. Also, there are compile