~ubuntu-branches/ubuntu/vivid/bc/vivid-proposed

« back to all changes in this revision

Viewing changes to doc/bc.texi

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-05 12:24:03 UTC
  • mfrom: (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20071205122403-rv1a7x90ktu1wl95
Tags: 1.06.94-3ubuntu1
* Merge with Debian; remaining changes:
  - Make bc/dc notice read and write errors on its input and output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
@c \overfullrule=0pt
14
14
@c end tex
15
15
 
 
16
@ifinfo
 
17
@direntry
 
18
* bc: (bc).                    An arbitrary precision calculator language.
 
19
@end direntry
 
20
@end ifinfo
 
21
 
16
22
@titlepage
17
23
@title @command{bc}
18
24
@subtitle an arbitrary precision calculator language
24
30
This manual documents @command{bc}, an arbitrary precision calculator language.
25
31
 
26
32
This manual is part of GNU @command{bc}.@*
27
 
@sp4
28
 
Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
29
 
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
33
@sp 4
 
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.
30
36
 
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.
34
40
 
35
 
@iftex
 
41
@ignore
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).
40
 
@end iftex
 
46
@end ignore
41
47
 
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
68
74
* Functions::
69
75
* Examples::
70
76
* Readline and Libedit Options::
71
 
* GNU @command{bc} and Other Implementations::
 
77
* Comparison with Other Implementations::
72
78
* Limits::
73
79
* Environment Variables::
74
80
@end menu
613
619
 
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.
660
666
 
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.
667
673
 
668
674
@example
669
675
   define d (n) @{ return (2*n); @}
671
677
       @{ return (2*n); @}
672
678
@end example
673
679
 
 
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
 
685
session.
 
686
 
 
687
@example
 
688
define py (y) @{ print "--->", y, "<---", "\n"; @}
 
689
define void px (x) @{ print "--->", x, "<---", "\n"; @}
 
690
py(1)
 
691
--->1<---
 
692
0
 
693
px(1)
 
694
--->1<---
 
695
@end example
 
696
 
 
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.
 
702
 
 
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.
674
707
 
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}.
695
728
 
696
 
@item @var{e} (@var{x})
 
729
@item e (@var{x})
697
730
The exponential function of raising @var{e} to the value @var{x}.
698
731
 
699
 
@item @var{j} (@var{n,x})
700
 
The bessel function of integer order @var{n} of @var{x}.
 
732
@item j (@var{n,x})
 
733
The Bessel function of integer order @var{n} of @var{x}.
701
734
@end table
702
735
 
703
736
@node Examples, Readline and Libedit Options, Functions, Top
797
830
 
798
831
@end example
799
832
 
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
802
835
 
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.
817
850
 
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
820
853
 
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
943
976
of @command{bc}.
944
977
@end table
945
978
 
946
 
@node Limits, Environment Variables, GNU @command{bc} and Other Implementations, Top
 
979
@node Limits, Environment Variables, Comparison with Other Implementations, Top
947
980
@chapter Limits
948
981
 
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.
1004
1037
 
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.
1009
1044
@end table
1010
1045
 
1011
1046
@contents