BC(1)BC(1)

## NAME

bc – arbitrary-precision arithmetic language

## SYNOPSIS

`bc``-cdls`*file ...*

## DESCRIPTION

*Bc*

The
`-d``-l``-s``print`

The following syntax for
*bc**L*`a`-`z`,*E**S*

**unhandled troff command .HP**

comments are enclosed in
`/* */`

**unhandled troff command .HP**

newlines end statements

simple variables:
*L*

array elements:
*L*`[`*E*`]`

The words
`ibase`,`obase`,`scale`

arbitrarily long numbers with optional sign and decimal point.

`(`

*E*

`)`

`sqrt(`

*E*

`)`

`length(`

*E*

`)`

number of significant decimal digits

`scale(`

*E*

`)`

number of digits right of decimal point

*L*

`(`

*E*

`,`

*...*

`,`

*E*)function call

**unhandled troff command .HP**

`+ - * / % ^ ``%``^`

**unhandled troff command .HP**

`++ -- `

`== <= >= != < >`

`= += -= *= /= %= ^=`

*E*

`{`*S*`;``;`*S*`}`

`print `*E*

`if ( `*E*`)`*S*

`while ( `*E*`)`*S*

`for ( `*E*`;`*E*`;`*E*`) `*S*

null statement

`break`

`quit`

`"`text`"`

`define`*L*`(`*L*`,``,`*L*`){`

`auto`*L*`,``,`*L*

*S*`;``;`*S*

`return`*E*

`}`

`-l`

`s(`

*x*

`)`

sine

`c(`

*x*

`)`

cosine

`e(`

*x*

`)`

exponential

`l(`

*x*

`)`

log

`a(`

*x*

`)`

arctangent

`j(`

*n, x*

`)`

Bessel function

**unhandled troff command .DT**

All function arguments are passed by value.

The value of an expression at the top level is printed
unless the main operator is an assignment or the
`-s``scale`*dc*(1).`ibase``obase`

The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. Automatic variables are pushed down during function calls. In a declaration of an array as a function argument or automatic variable empty square brackets must follow the array name.

*Bc**dc*(1),`-c`*dc*

## EXAMPLE

Define a function to compute an approximate value of the exponential. Use it to print 10 values. (The exponential function in the library gives better answers.)

scale = 20 define e(x) { auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1; 1; i++) { a *= x b *= i c = a/b if(c == 0) return s s += c } } for(i=1; i<=10; i++) print e(i)

## FILES

`/sys/lib/bclib`

## SOURCE

`/sys/src/cmd/bc.y`

## SEE ALSO

## BUGS

No
`&&`,`||`,`!`

A
`for``E`s.

A
`quit`