~ubuntu-branches/ubuntu/raring/bc/raring-proposed

« back to all changes in this revision

Viewing changes to doc/bc.1

  • Committer: Bazaar Package Importer
  • Author(s): John Hasler
  • Date: 2007-12-02 14:46:56 UTC
  • mto: (3.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20071202144656-vz98qh9dd1zwdyny
Tags: upstream-1.06.94
ImportĀ upstreamĀ versionĀ 1.06.94

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
.\" bc.1 - the *roff document processor source for the bc manual
3
3
.\"
4
4
.\" This file is part of GNU bc.
5
 
.\" Copyright (C) 1991-1994, 1997, 2000 Free Software Foundation, Inc.
 
5
.\" Copyright (C) 1991-1994, 1997, 2000, 2003, 2006 Free Software Foundation, Inc.
6
6
.\"
7
7
.\" This program is free software; you can redistribute it and/or modify
8
8
.\" it under the terms of the GNU General Public License as published by
17
17
.\" You should have received a copy of the GNU General Public License
18
18
.\" along with this program; see the file COPYING.  If not, write to:
19
19
.\"   The Free Software Foundation, Inc.
20
 
.\"   59 Temple Place, Suite 330
21
 
.\"   Boston, MA 02111 USA
 
20
.\"   51 Franklin Street, Fifth Floor
 
21
.\"   Boston, MA 02110-1301  USA
22
22
.\"
23
23
.\" You may contact the author by:
24
24
.\" e-mail: philnelson@acm.org
207
207
the "var" part is evaluated only once.  This can make a difference if
208
208
"var" is an array.
209
209
.PP
210
 
 Relational expressions are a special kind of expression
 
210
Relational expressions are a special kind of expression
211
211
that always evaluate to 0 or 1, 0 if the relation is false and 1 if
212
212
the relation is true.  These may appear in any legal expression.
213
213
(POSIX bc requires that relational expressions are used only in if,
434
434
.PP
435
435
Parameters are numbers or arrays (an extension).  In the function definition,
436
436
zero or more parameters are defined by listing their names separated by
437
 
commas.  Numbers are only call by value parameters.  Arrays are only
438
 
call by variable.  Arrays are specified in the parameter definition by
 
437
commas.  All parameters are call by value parameters.  
 
438
Arrays are specified in the parameter definition by
439
439
the notation "\fIname\fB[]\fR".   In the function call, actual parameters
440
440
are full expressions for number parameters.  The same notation is used
441
441
for passing arrays as for defining array parameters.  The named array is
442
 
passed by variable to the function.  Since function definitions are dynamic,
 
442
passed by value to the function.  Since function definitions are dynamic,
443
443
parameter numbers and types are checked when a function is called.  Any
444
444
mismatch in number or types of parameters will cause a runtime error.
445
445
A runtime error will also occur for the call to an undefined function.
478
478
standard function \fBread\fR, which will always use the current value
479
479
of \fBibase\fR for conversion of numbers.
480
480
.PP
481
 
As an extension, the format of the definition has been slightly relaxed.
482
 
The standard requires the opening brace be on the same line as the 
483
 
\fBdefine\fR keyword and all other parts must be on following lines.
484
 
This version of \fBbc\fR will allow any number of newlines before and
485
 
after the opening brace of the function.  For example, the following
486
 
definitions are legal.
 
481
Several extensions have been added to functions.  First, the format of
 
482
the definition has been slightly relaxed.  The standard requires the
 
483
opening brace be on the same line as the \fBdefine\fR keyword and all
 
484
other parts must be on following lines.  This version of \fBbc\fR will
 
485
allow any number of newlines before and after the opening brace of the
 
486
function.  For example, the following definitions are legal.
487
487
.nf
488
488
.RS
489
489
\f(CW
493
493
\fR
494
494
.RE
495
495
.fi
 
496
.PP
 
497
Functions may be defined as \fBvoid\fR.  A void
 
498
funtion returns no value and thus may not be used in any place that needs
 
499
a value.  A void function does not produce any output when called by itself
 
500
on an input line.  The key word \fBvoid\fR is placed between the key word
 
501
\fBdefine\fR and the function name.  For example, consider the following
 
502
session.
 
503
.nf
 
504
.RS
 
505
\f(CW
 
506
define py (y) { print "--->", y, "<---", "\n"; }
 
507
define void px (x) { print "--->", x, "<---", "\n"; }
 
508
py(1)
 
509
--->1<---
 
510
0
 
511
px(1)
 
512
--->1<---
 
513
\fR
 
514
.RE
 
515
.fi
 
516
Since \fBpy\fR is not a void function, the call of \fBpy(1)\fR prints
 
517
the desired output and then prints a second line that is the value of
 
518
the function.  Since the value of a function that is not given an
 
519
explicit return statement is zero, the zero is printed.  For \fBpx(1)\fR,
 
520
no zero is printed because the function is a void function.
 
521
.PP
 
522
Also, call by variable for arrays was added.  To declare
 
523
a call by variable array, the declaration of the array parameter in the
 
524
function definition looks like "\fI*name\fB[]\fR".  The call to the
 
525
function remains the same as call by value arrays. 
496
526
.SS MATH LIBRARY
497
527
If \fBbc\fR is invoked with the \fB-l\fR option, a math library is preloaded
498
528
and the default scale is set to 20.   The math functions will calculate their
509
539
.IP "e (\fIx\fR)"
510
540
The exponential function of raising e to the value x.
511
541
.IP "j (\fIn,x\fR)"
512
 
The bessel function of integer order n of x.
 
542
The Bessel function of integer order n of x.
513
543
.SS EXAMPLES
514
544
In /bin/sh,  the following will assign the value of "pi" to the shell
515
545
variable \fBpi\fR.
639
669
extensions, where a feature is extended to add more functionality and
640
670
additions, where new features are added. 
641
671
The following is the list of differences and extensions.
642
 
.IP LANG environment
 
672
.IP "LANG environment"
643
673
This version does not conform to the POSIX standard in the processing
644
674
of the LANG environment variable and all environment variables starting
645
675
with LC_.
646
 
.IP names
 
676
.IP "names"
647
677
Traditional and POSIX
648
678
.B bc
649
679
have single letter names for functions, variables and arrays.  They have
650
680
been extended to be multi-character names that start with a letter and
651
681
may contain letters, numbers and the underscore character.
652
 
.IP Strings
 
682
.IP "Strings"
653
683
Strings are not allowed to contain NUL characters.  POSIX says all characters
654
684
must be included in strings.
655
 
.IP last
 
685
.IP "last"
656
686
POSIX \fBbc\fR does not have a \fBlast\fR variable.  Some implementations
657
687
of \fBbc\fR use the period (.) in a similar way.  
658
 
.IP comparisons
 
688
.IP "comparisons"
659
689
POSIX \fBbc\fR allows comparisons only in the if statement, the while
660
690
statement, and the second expression of the for statement.  Also, only
661
691
one relational operation is allowed in each of those statements.
737
767
.B bc
738
768
processor.  Some of them may have been changed by an installation.
739
769
Use the limits statement to see the actual values.
740
 
.IP BC_BASE_MAX
 
770
.IP "BC_BASE_MAX"
741
771
The maximum output base is currently set at 999.  The maximum input base
742
772
is 16.
743
 
.IP BC_DIM_MAX
 
773
.IP "BC_DIM_MAX"
744
774
This is currently an arbitrary limit of 65535 as distributed.  Your
745
775
installation may be different.
746
 
.IP BC_SCALE_MAX
 
776
.IP "BC_SCALE_MAX"
747
777
The number of digits after the decimal point is limited to INT_MAX digits.
748
778
Also, the number of digits before the decimal point is limited to INT_MAX
749
779
digits.
750
 
.IP BC_STRING_MAX
 
780
.IP "BC_STRING_MAX"
751
781
The limit on the number of characters in a string is INT_MAX characters.
752
 
.IP exponent
 
782
.IP "exponent"
753
783
The value of the exponent in the raise operation (^) is limited to LONG_MAX.
754
784
.IP "variable names"
755
785
The current limit on the number of unique names is 32767 for each of
761
791
.IP "BC_ENV_ARGS"
762
792
This is another mechanism to get arguments to \fBbc\fR.  The
763
793
format is the same as the command line arguments.  These arguments
764
 
are processed first, so any files listed in the environent arguments
 
794
are processed first, so any files listed in the environment arguments
765
795
are processed before any command line argument files.  This allows
766
796
the user to set up "standard" options and files to be processed
767
797
at every invocation of \fBbc\fR.  The files in the environment
768
798
variables would typically contain function definitions for functions
769
799
the user wants defined every time \fBbc\fR is run.
770
800
.IP "BC_LINE_LENGTH"
771
 
This should be an integer specifing the number of characters in an
 
801
This should be an integer specifying the number of characters in an
772
802
output line for numbers. This includes the backslash and newline characters
773
 
for long numbers.
 
803
for long numbers.  As an extension, the value of zero disables the 
 
804
multi-line feature.  Any other value of this variable that is less than
 
805
3 sets the line length to 70.
774
806
.SH DIAGNOSTICS
775
807
If any file on the command line can not be opened, \fBbc\fR will report
776
808
that the file is unavailable and terminate.  Also, there are compile