bc(1)bc(1)

NAME

bc - arbitrary-precision arithmetic language

SYNOPSIS

bc [-c] [-l] [ ®le ... ]

DESCRIPTION

bc is an interactive processor for a language that resembles C but provides unlimited-precision arithmetic. It takes input from any ®les given, then reads the standard input.

Options:

bc recognizes the following command-line options:

-cCompile only. bc is actually a preprocessor for dc which bc invokes automatically (see dc(1)). Specifying -cprevents invoking dc, and sends the dc input to standard output.

-lcauses an arbitrary-precision math library to be prede®ned. As a side effect, the scale factor is set.

Program Syntax:

La single letter in the range a through z; E expression;

S statement;

R relational expression.

Comments:

Comments are enclosed in /* and */.

Names:

Names include:

simple variables: L

array elements: L [ E ]

The words ibase,obase, and scale stacks: L

Other Operands

Other operands include:

Arbitrarily long numbers with optional sign and decimal point.

( E )

 

sqrt ( E )

 

length ( E )

number of signi®cant decimal digits

scale ( E )

number of digits right of decimal point

L ( E , ... , E )

 

Strings of ASCII characters enclosed in quotes ( " ).

Arithmetic Operators:

Arithmetic operators yield an E as a result and include:

+

- * / % Ã

( % is remainder (not mod, see below); Ã is power).

++

- -

(pre®x and append; apply to names)

=+= -= *= /= %= Ã=

Relational Operators

Relational operators yield an R when used as E op E:

== <= >= != < >

b

HP-UX Release 11i: December 2000

− 1 −

Section 141