summaryrefslogtreecommitdiff
path: root/doc/bc.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/bc.texi')
-rw-r--r--doc/bc.texi166
1 files changed, 101 insertions, 65 deletions
diff --git a/doc/bc.texi b/doc/bc.texi
index a7cb9f6..40034ab 100644
--- a/doc/bc.texi
+++ b/doc/bc.texi
@@ -4,6 +4,8 @@
@settitle bc Command Manual
@c %**end of header
+@include texi-ver.incl
+
@c This file has the new style title page commands.
@c Run `makeinfo' rather than `texinfo-format-buffer'.
@@ -13,10 +15,16 @@
@c \overfullrule=0pt
@c end tex
+@ifinfo
+@direntry
+* bc: (bc). An arbitrary precision calculator language.
+@end direntry
+@end ifinfo
+
@titlepage
@title @command{bc}
@subtitle an arbitrary precision calculator language
-@subtitle version 1.06
+@subtitle version @value{BC_VERSION}
@author Philip A. Nelson
@page
@@ -24,20 +32,20 @@
This manual documents @command{bc}, an arbitrary precision calculator language.
This manual is part of GNU @command{bc}.@*
-@sp4
-Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
-59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+@sp 4
+Copyright (C) 1991, 1992, 1993, 1994, 1997, 2003, 2006 Free Software Foundation, Inc.
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
-@iftex
+@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
-@end iftex
+@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
@@ -68,7 +76,7 @@ Bellingham, WA 98226-9062
* Functions::
* Examples::
* Readline and Libedit Options::
-* GNU @command{bc} and Other Implementations::
+* Comparison with Other Implementations::
* Limits::
* Environment Variables::
@end menu
@@ -149,15 +157,15 @@ Print the version number and copyright and quit.
@section Numbers
The most basic element in @command{bc} 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, while 1935.000 has a length of 7 and a scale
-of 3.
+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 digits used by @command{bc} to represent 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, while
+1935.000 has a length of 7 and a scale of 3.
@node Variables, Comments, Numbers, Basic Elements
@section Variables
@@ -219,14 +227,15 @@ detail later, are defined when encountered.)
A simple expression is just a constant. @command{bc} converts constants
into internal decimal numbers using the current input base, specified by
the variable @var{ibase}. (There is an exception in functions.) The
-legal values of @var{ibase} are 2 through 16. Assigning a value outside
-this range to @var{ibase} will result in a value of 2 or 16. Input
-numbers may contain the characters 0-9 and A-F. (Note: They must be
+legal values of @var{ibase} are 2 through 36. (Bases greater than
+16 are an extension.) Assigning a value outside
+this range to @var{ibase} 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
@var{ibase}. (i.e. A = 10.) For multi-digit numbers, @command{bc}
changes all input digits greater or equal to @var{ibase} to the value of
-@var{ibase}-1. This makes the number @code{FFF} always be the largest
+@var{ibase}-1. This makes the number @code{ZZZ} always be the largest
3 digit number of the input base.
Full expressions are similar to many other high level languages.
@@ -412,7 +421,7 @@ functions. They all appear as
user-defined functions. The standard functions are:
@table @code
-@item length ( expression )
+@item length ( @var{expression} )
The value of the length function is the number of significant digits in the
expression.
@@ -426,11 +435,11 @@ be input from the user. The value of the @code{read} function is the
number read from the standard input using the current value of the
variable @var{ibase} for the conversion base.
-@item scale ( expression )
+@item scale ( @var{expression} )
The value of the @code{scale} function is the number of digits after the
decimal point in the expression.
-@item sqrt ( expression )
+@item sqrt ( @var{expression} )
The value of the @code{sqrt} function is the square root of the
expression. If the expression is negative, a run time error is
generated.
@@ -457,8 +466,8 @@ series of statements separated by semicolons and newlines. The
following is a list of @command{bc} statements and what they do: (Things
enclosed in brackets ( [ ] ) are optional parts of the statement.)
-@table @var
-@item expression
+@table @code
+@item @var{expression}
This statement does one of two things. If the expression starts with
"<variable> <assignment> ...", it is considered to be an assignment
statement. If the expression is not an assignment statement, the
@@ -488,13 +497,13 @@ until the next number is printed or another value is assigned to
(.) which is not part of a number as a short hand notation for for
@var{last}.)
-@item string
+@item @var{string}
The string is printed to the output. Strings start with a double quote
character and contain all characters until the next double quote character.
All characters are taken literally, including any newline. No newline
character is printed after the string.
-@item @code{print} @var{list}
+@item print @var{list}
The @code{print} statement (an extension) provides another method of
output. The @var{list} is a list of strings and expressions separated by
commas. Each string or expression is printed in the order of the list.
@@ -507,24 +516,24 @@ bell), "b" (backspace), "f" (form feed), "n" (newline), "r" (carriage
return), "q" (double quote), "t" (tab), and "\e" (backslash). Any other
character following the backslash will be ignored.
-@item @{ statement_list @}
+@item @{ @var{statement_list} @}
This is the compound statement. It allows multiple statements to be
grouped together for execution.
-@item @code{if} ( expression ) statement1 [@code{else} statement2]
+@item if ( @var{expression} ) @var{statement1} [else @var{statement2}]
The if statement evaluates the expression and executes statement1 or
statement2 depending on the value of the expression. If the expression
is non-zero, statement1 is executed. If statement2 is present and
the value of the expression is 0, then statement2 is executed. (The
@code{else} clause is an extension.)
-@item @code{while} ( expression ) statement
+@item while ( @var{expression} ) @var{statement}
The while statement will execute the statement while the expression
is non-zero. It evaluates the expression before each execution of
the statement. Termination of the loop is caused by a zero
expression value or the execution of a @code{break} statement.
-@item @code{for} ( [expression1] ; [expression2] ; [expression3] ) statement
+@item for ( [@var{expression1}] ; [@var{expression2}] ; [@var{expression3}] ) @var{statement}
The @code{for} statement controls repeated execution of the statement.
@var{Expression1} is evaluated before the loop. @var{Expression2} is
evaluated before each execution of the statement. If it is non-zero,
@@ -546,24 +555,24 @@ while (expression2) @{
@}
@end example
-@item @code{break}
+@item break
This statement causes a forced exit of the most recent enclosing @code{while}
statement or @code{for} statement.
-@item @code{continue}
+@item continue
The @code{continue} statement (an extension) causes the most recent enclosing
@code{for} statement to start the next iteration.
-@item @code{halt}
+@item halt
The @code{halt} statement (an extension) is an executed statement that
causes the @command{bc} processor to quit only when it is executed. For
example, "if (0 == 1) halt" will not cause @command{bc} to terminate
because the @code{halt} is not executed.
-@item @code{return}
+@item return
Return the value 0 from a function. (@xref{Functions}.)
-@item @code{return} ( expression )
+@item return ( @var{expression} )
Return the value of the expression from a function. (@xref{Functions}.)
As an extension, the parenthesis are not required.
@end table
@@ -613,12 +622,12 @@ A function call is just an expression of the form
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 "@var{name}@code{[ ]}". 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.
@@ -658,12 +667,12 @@ will be ignored during the execution of the function except for the
standard function @code{read}, which will always use the current value
of @var{ibase} for conversion of numbers.
-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
-@code{define} keyword and all other parts must be on following lines.
-This version of @command{bc} 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 @code{define} keyword and all
+other parts must be on following lines. This version of @command{bc}
+will allow any number of newlines before and after the opening brace of
+the function. For example, the following definitions are legal.
@example
define d (n) @{ return (2*n); @}
@@ -671,6 +680,33 @@ definitions are legal.
@{ return (2*n); @}
@end example
+Functions may be defined as @code{void}. 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 @code{void} is placed between the key word
+@code{define} and the function name. For example, consider the following
+session.
+
+@example
+define py (y) @{ print "--->", y, "<---", "\n"; @}
+define void px (x) @{ print "--->", x, "<---", "\n"; @}
+py(1)
+--->1<---
+0
+px(1)
+--->1<---
+@end example
+
+Since @code{py} is not a void function, the call of @code{py(1)} 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 @code{px(1)},
+no zero is printed because the function is a void function.
+
+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 "@code{*}@var{name}@code{[]}". The call
+to the function remains the same as call by value arrays.
@node Math Library Functions, , Functions, Functions
@section Math Library Functions
@@ -693,11 +729,11 @@ The arctangent of @var{x}, arctangent returns radians.
@item l (@var{x})
The natural logarithm of @var{x}.
-@item @var{e} (@var{x})
+@item e (@var{x})
The exponential function of raising @var{e} to the value @var{x}.
-@item @var{j} (@var{n,x})
-The bessel function of integer order @var{n} of @var{x}.
+@item j (@var{n}, @var{x})
+The Bessel function of integer order @var{n} of @var{x}.
@end table
@node Examples, Readline and Libedit Options, Functions, Top
@@ -797,7 +833,7 @@ define f (x) @{
@end example
-@node Readline and Libedit Options, GNU @command{bc} and Other Implementations, Examples, Top
+@node Readline and Libedit Options, Comparison with Other Implementations, Examples, Top
@chapter Readline and Libedit Options
GNU @command{bc} can be compiled (via a configure option) to use the GNU
@@ -815,8 +851,8 @@ more information, read the user manuals for the GNU @command{readline},
@command{history} and BSD @command{libedit} libraries. One can not
enable both @command{readline} and @command{libedit} at the same time.
-@node GNU @command{bc} and Other Implementations, Limits, Readline and Libedit Options, Top
-@chapter GNU @command{bc} and Other Implementations
+@node Comparison with Other Implementations, Limits, Readline and Libedit Options, Top
+@chapter Comparison with Other Implementations
This version of @command{bc} was implemented from the POSIX P1003.2/D11
draft and contains several differences and extensions relative to the
@@ -831,7 +867,7 @@ 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.
-@table @var
+@table @asis
@item LANG environment
This version does not conform to the POSIX standard in the processing
@@ -858,23 +894,23 @@ the @code{while} statement, and the second expression of the @code{for}
statement. Also, only one relational operation is allowed in each of
those statements.
-@item if statement, else clause
+@item @code{if} statement, @code{else} clause
POSIX @command{bc} does not have an @code{else} clause.
-@item for statement
+@item @code{for} statement
POSIX @command{bc} requires all expressions to be present in the
@code{for} statement.
-@item &&, ||, !
+@item @code{&&,} @code{||}, @code{!}
POSIX @command{bc} does not have the logical operators.
-@item read function
+@item @code{read} function
POSIX @command{bc} does not have a @code{read} function.
-@item print statement
+@item @code{print} statement
POSIX @command{bc} does not have a @code{print} statement.
-@item continue statement
+@item @code{continue} statement
POSIX @command{bc} does not have a continue statement.
@item array parameters
@@ -888,7 +924,7 @@ of @command{bc} have only call by value array parameters.
POSIX @command{bc} requires the opening brace on the same line as the
@code{define} key word and the @code{auto} statement on the next line.
-@item =+, =-, =*, =/, =%, =^
+@item @code{=+}, @code{=-}, @code{=*}, @code{=/}, @code{=%}, @code{=^}
POSIX @command{bc} does not require these "old style" assignment
operators to be defined. This version may allow these "old style"
assignments. Use the @code{limits} statement to see if the installed
@@ -943,7 +979,7 @@ non-interactive session, the SIGINT signal will terminate the entire run
of @command{bc}.
@end table
-@node Limits, Environment Variables, GNU @command{bc} and Other Implementations, Top
+@node Limits, Environment Variables, Comparison with Other Implementations, Top
@chapter Limits
The following are the limits currently in place for this @command{bc}
@@ -995,7 +1031,7 @@ This is the same as the -s option (@pxref{Command Line Options}).
@item BC_ENV_ARGS
This is another mechanism to get arguments to @command{bc}. 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 @command{bc}. The files in the environment variables
@@ -1003,12 +1039,12 @@ would typically contain function definitions for functions the user
wants defined every time @command{bc} is run.
@item 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.
+characters 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.
@end table
@contents
@bye
-
-