24
30
This manual documents @command{bc}, an arbitrary precision calculator language.
26
32
This manual is part of GNU @command{bc}.@*
28
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
29
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
34
Copyright (C) 1991, 1992, 1993, 1994, 1997, 2003, 2006 Free Software Foundation, Inc.
35
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31
37
Permission is granted to make and distribute verbatim copies of
32
38
this manual provided the copyright notice and this permission notice
33
39
are preserved on all copies.
36
42
Permission is granted to process this file through TeX and print the
37
43
results, provided the printed document carries copying permission
38
44
notice identical to this one except for the removal of this paragraph
39
45
(this paragraph not being relevant to the printed manual).
42
48
Permission is granted to copy and distribute modified versions of this
43
49
manual under the conditions for verbatim copying, provided that the entire
614
620
Parameters are numbers or arrays (an extension). In the function definition,
615
621
zero or more parameters are defined by listing their names separated by
616
commas. Numbers are only call by value parameters. Arrays are only
617
call by variable. Arrays are specified in the parameter definition by
622
commas. All parameters are call by value parameters.
623
Arrays are specified in the parameter definition by
618
624
the notation "@var{name}@code{[ ]}". In the function call, actual parameters
619
625
are full expressions for number parameters. The same notation is used
620
626
for passing arrays as for defining array parameters. The named array is
621
passed by variable to the function. Since function definitions are dynamic,
627
passed by value to the function. Since function definitions are dynamic,
622
628
parameter numbers and types are checked when a function is called. Any
623
629
mismatch in number or types of parameters will cause a runtime error.
624
630
A runtime error will also occur for the call to an undefined function.
658
664
standard function @code{read}, which will always use the current value
659
665
of @var{ibase} for conversion of numbers.
661
As an extension, the format of the definition has been slightly relaxed.
662
The standard requires the opening brace be on the same line as the
663
@code{define} keyword and all other parts must be on following lines.
664
This version of @command{bc} will allow any number of newlines before and
665
after the opening brace of the function. For example, the following
666
definitions are legal.
667
Several extensions have been added to functions. First, the format of
668
the definition has been slightly relaxed. The standard requires the
669
opening brace be on the same line as the @code{define} keyword and all
670
other parts must be on following lines. This version of @command{bc}
671
will allow any number of newlines before and after the opening brace of
672
the function. For example, the following definitions are legal.
669
675
define d (n) @{ return (2*n); @}
671
677
@{ return (2*n); @}
680
Functions may be defined as @code{void}. A void
681
funtion returns no value and thus may not be used in any place that needs
682
a value. A void function does not produce any output when called by itself
683
on an input line. The key word @code{void} is placed between the key word
684
@code{define} and the function name. For example, consider the following
688
define py (y) @{ print "--->", y, "<---", "\n"; @}
689
define void px (x) @{ print "--->", x, "<---", "\n"; @}
697
Since @code{py} is not a void function, the call of @code{py(1)} prints
698
the desired output and then prints a second line that is the value of
699
the function. Since the value of a function that is not given an
700
explicit return statement is zero, the zero is printed. For @code{px(1)},
701
no zero is printed because the function is a void function.
703
Also, call by variable for arrays was added. To declare a
704
call by variable array, the declaration of the array parameter in the
705
function definition looks like "@code{*}@var{name}@code{[]}". The call
706
to the function remains the same as call by value arrays.
675
708
@node Math Library Functions, , Functions, Functions
676
709
@section Math Library Functions
693
726
@item l (@var{x})
694
727
The natural logarithm of @var{x}.
696
@item @var{e} (@var{x})
697
730
The exponential function of raising @var{e} to the value @var{x}.
699
@item @var{j} (@var{n,x})
700
The bessel function of integer order @var{n} of @var{x}.
733
The Bessel function of integer order @var{n} of @var{x}.
703
736
@node Examples, Readline and Libedit Options, Functions, Top
800
@node Readline and Libedit Options, GNU @command{bc} and Other Implementations, Examples, Top
833
@node Readline and Libedit Options, Comparison with Other Implementations, Examples, Top
801
834
@chapter Readline and Libedit Options
803
836
GNU @command{bc} can be compiled (via a configure option) to use the GNU
815
848
@command{history} and BSD @command{libedit} libraries. One can not
816
849
enable both @command{readline} and @command{libedit} at the same time.
818
@node GNU @command{bc} and Other Implementations, Limits, Readline and Libedit Options, Top
819
@chapter GNU @command{bc} and Other Implementations
851
@node Comparison with Other Implementations, Limits, Readline and Libedit Options, Top
852
@chapter Comparison with Other Implementations
821
854
This version of @command{bc} was implemented from the POSIX P1003.2/D11
822
855
draft and contains several differences and extensions relative to the
946
@node Limits, Environment Variables, GNU @command{bc} and Other Implementations, Top
979
@node Limits, Environment Variables, Comparison with Other Implementations, Top
949
982
The following are the limits currently in place for this @command{bc}
995
1028
@item BC_ENV_ARGS
996
1029
This is another mechanism to get arguments to @command{bc}. The format
997
1030
is the same as the command line arguments. These arguments are
998
processed first, so any files listed in the environent arguments are
1031
processed first, so any files listed in the environment arguments are
999
1032
processed before any command line argument files. This allows the user
1000
1033
to set up "standard" options and files to be processed at every
1001
1034
invocation of @command{bc}. The files in the environment variables
1003
1036
wants defined every time @command{bc} is run.
1005
1038
@item BC_LINE_LENGTH
1006
This should be an integer specifing the number of characters in an
1039
This should be an integer specifying the number of characters in an
1007
1040
output line for numbers. This includes the backslash and newline
1008
characters for long numbers.
1041
characters for long numbers. As an extension, the value of zero disables the
1042
multi-line feature. Any other value of this variable that is less than
1043
3 sets the line length to 70.