<s>
bc	B-Application
,	O
for	O
basic	O
calculator	O
(	O
often	O
referred	O
to	O
as	O
bench	O
calculator	O
)	O
,	O
is	O
"	O
an	O
arbitrary-precision	B-Algorithm
calculator	O
language	O
"	O
with	O
syntax	O
similar	O
to	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
bc	B-Application
is	O
typically	O
used	O
as	O
either	O
a	O
mathematical	O
scripting	O
language	O
or	O
as	O
an	O
interactive	O
mathematical	O
shell	O
.	O
</s>
<s>
A	O
typical	O
interactive	O
usage	O
is	O
typing	O
the	O
command	B-Application
bc	B-Application
on	O
a	O
Unix	B-Application
command	B-Application
prompt	O
and	O
entering	O
a	O
mathematical	O
expression	O
,	O
such	O
as	O
,	O
whereupon	O
will	O
be	O
output	O
.	O
</s>
<s>
While	O
bc	B-Application
can	O
work	O
with	O
arbitrary	B-Algorithm
precision	I-Algorithm
,	O
it	O
actually	O
defaults	O
to	O
zero	O
digits	O
after	O
the	O
decimal	O
point	O
,	O
so	O
the	O
expression	O
yields	O
(	O
results	O
are	O
truncated	O
,	O
not	O
rounded	O
)	O
.	O
</s>
<s>
This	O
can	O
surprise	O
new	O
bc	B-Application
users	O
unaware	O
of	O
this	O
fact	O
.	O
</s>
<s>
The	O
option	O
to	O
bc	B-Application
sets	O
the	O
default	O
scale	O
(	O
digits	O
after	O
the	O
decimal	O
point	O
)	O
to	O
20	O
and	O
adds	O
several	O
additional	O
mathematical	O
functions	O
to	O
the	O
language	O
.	O
</s>
<s>
bc	B-Application
first	O
appeared	O
in	O
Version	B-Operating_System
6	I-Operating_System
Unix	I-Operating_System
in	O
1975	O
.	O
</s>
<s>
It	O
was	O
written	O
by	O
Lorinda	O
Cherry	O
of	O
Bell	O
Labs	O
as	O
a	O
front	O
end	O
to	O
dc	B-Application
,	O
an	O
arbitrary-precision	B-Algorithm
calculator	O
written	O
by	O
Robert	O
Morris	O
and	O
Cherry	O
.	O
</s>
<s>
dc	B-Application
performed	O
arbitrary-precision	B-Algorithm
computations	O
specified	O
in	O
reverse	O
Polish	O
notation	O
.	O
</s>
<s>
bc	B-Application
provided	O
a	O
conventional	O
programming-language	O
interface	O
to	O
the	O
same	O
capability	O
via	O
a	O
simple	O
compiler	B-Language
(	O
a	O
single	O
yacc	B-Application
source	O
file	O
comprising	O
a	O
few	O
hundred	O
lines	O
of	O
code	O
)	O
,	O
which	O
converted	O
a	O
C-like	O
syntax	O
into	O
dc	B-Application
notation	O
and	O
piped	B-Operating_System
the	O
results	O
through	O
dc	B-Application
.	O
</s>
<s>
In	O
1991	O
,	O
POSIX	O
rigorously	O
defined	O
and	O
standardized	O
bc	B-Application
.	O
</s>
<s>
Three	O
implementations	O
of	O
this	O
standard	O
survive	O
today	O
:	O
The	O
first	O
is	O
the	O
traditional	B-Application
Unix	I-Application
implementation	O
,	O
a	O
front-end	O
to	O
dc	B-Application
,	O
which	O
survives	O
in	O
Unix	B-Application
and	O
Plan	B-Operating_System
9	I-Operating_System
systems	O
.	O
</s>
<s>
The	O
second	O
is	O
the	O
free	B-Application
software	I-Application
GNU	B-Operating_System
bc	B-Application
,	O
first	O
released	O
in	O
1991	O
by	O
Philip	O
A	O
.	O
Nelson	O
.	O
</s>
<s>
The	O
GNU	B-Operating_System
implementation	O
has	O
numerous	O
extensions	O
beyond	O
the	O
POSIX	O
standard	O
and	O
is	O
no	O
longer	O
a	O
front-end	O
to	O
dc	B-Application
(	O
it	O
is	O
a	O
bytecode	O
interpreter	O
)	O
.	O
</s>
<s>
The	O
POSIX	O
standardized	O
bc	B-Application
language	O
is	O
traditionally	O
written	O
as	O
a	O
program	O
in	O
the	O
dc	B-Application
programming	I-Application
language	I-Application
to	O
provide	O
a	O
higher	O
level	O
of	O
access	O
to	O
the	O
features	O
of	O
the	O
dc	B-Application
language	O
without	O
the	O
complexities	O
of	O
dc	B-Application
's	O
terse	O
syntax	O
.	O
</s>
<s>
In	O
this	O
form	O
,	O
the	O
bc	B-Application
language	O
contains	O
single-letter	O
variable	O
,	O
array	B-Data_Structure
and	O
function	O
names	O
and	O
most	O
standard	O
arithmetic	O
operators	O
,	O
as	O
well	O
as	O
the	O
familiar	O
control-flow	O
constructs	O
(if(cond )	O
...	O
,	O
while(cond )	O
...	O
and	O
for( init	O
;	O
cond	O
;	O
inc	O
)	O
...	O
)	O
from	O
C	B-Language
.	O
Unlike	O
C	B-Language
,	O
an	O
if	O
clause	O
may	O
not	O
be	O
followed	O
by	O
an	O
else	O
.	O
</s>
<s>
The	O
auto	O
keyword	O
(	O
optional	O
in	O
C	B-Language
)	O
is	O
used	O
to	O
declare	O
a	O
variable	O
as	O
local	O
to	O
a	O
function	O
.	O
</s>
<s>
All	O
numbers	O
and	O
variable	O
contents	O
are	O
arbitrary-precision	B-Algorithm
numbers	O
whose	O
precision	O
(	O
in	O
decimal	O
places	O
)	O
is	O
determined	O
by	O
the	O
global	O
scale	O
variable	O
.	O
</s>
<s>
Comments	O
may	O
be	O
added	O
to	O
bc	B-Application
code	O
by	O
use	O
of	O
the	O
C	B-Language
/	O
*	O
and	O
*	O
/	O
(	O
start	O
and	O
end	O
comment	O
)	O
symbols	O
.	O
</s>
<s>
The	O
following	O
POSIX	O
bc	B-Application
operators	O
behave	O
exactly	O
like	O
their	O
C	B-Language
counterparts	O
:	O
</s>
<s>
The	O
modulus	O
operators	O
,	O
%	O
and	O
%	O
=	O
behave	O
exactly	O
like	O
their	O
C	B-Language
counterparts	O
only	O
when	O
the	O
global	O
scale	O
variable	O
is	O
set	O
to	O
0	O
,	O
i.e.	O
</s>
<s>
superficially	O
resemble	O
the	O
C	B-Language
bitwise	O
exclusive-or	O
operators	O
,	O
but	O
are	O
in	O
fact	O
the	O
bc	B-Application
integer	O
exponentiation	O
operators	O
.	O
</s>
<s>
Of	O
particular	O
note	O
,	O
the	O
use	O
of	O
the	O
^	O
operator	O
with	O
negative	O
numbers	O
does	O
not	O
follow	O
the	O
C	B-Language
operator	O
precedence	O
.	O
</s>
<s>
-2	O
^2	O
gives	O
the	O
answer	O
of	O
4	O
under	O
bc	B-Application
rather	O
than	O
−4	O
.	O
</s>
<s>
The	O
bitwise	O
,	O
boolean	O
and	O
conditional	B-Language
operators	O
:	O
</s>
<s>
are	O
not	O
available	O
in	O
POSIX	O
bc	B-Application
.	O
</s>
<s>
The	O
sqrt( )	O
function	O
for	O
calculating	O
square	O
roots	O
is	O
POSIX	O
bc	B-Application
's	O
only	O
built-in	O
mathematical	O
function	O
.	O
</s>
<s>
bc	B-Application
's	O
standard	O
math	O
library	O
(	O
defined	O
with	O
the	O
-l	O
option	O
)	O
contains	O
functions	O
for	O
calculating	O
sine	O
,	O
cosine	O
,	O
arctangent	O
,	O
natural	O
logarithm	O
,	O
the	O
exponential	O
function	O
and	O
the	O
two	O
parameter	O
Bessel	O
function	O
J	O
.	O
</s>
<s>
+The	O
bc	B-Application
standard	O
librarybc	O
commandFunctionDescriptions(x )	O
SineTakes	O
x	O
,	O
an	O
angle	O
in	O
radiansc(x )	O
CosineTakes	O
x	O
,	O
an	O
angle	O
in	O
radiansa(x )	O
ArctangentReturns	O
radiansl(x )	O
Natural	O
logarithme(x )	O
Exponential	O
function	O
j(n,x )	O
Bessel	O
functionReturns	O
the	O
order-n	O
Bessel	O
function	O
of	O
x	O
.	O
</s>
<s>
For	O
example	O
,	O
writing	O
bc	B-Application
-l	O
and	O
then	O
the	O
command	B-Application
print	O
3%2	O
outputs	O
0	O
.	O
</s>
<s>
But	O
writing	O
scale	O
=	O
0	O
after	O
bc	B-Application
-l	O
and	O
then	O
the	O
command	B-Application
print	O
3%2	O
will	O
output	O
1	O
.	O
</s>
<s>
Plan	B-Operating_System
9	I-Operating_System
bc	B-Application
is	O
identical	O
to	O
POSIX	O
bc	B-Application
but	O
for	O
an	O
additional	O
print	O
statement	O
.	O
</s>
<s>
GNU	B-Operating_System
bc	B-Application
derives	O
from	O
the	O
POSIX	O
standard	O
and	O
includes	O
many	O
enhancements	O
.	O
</s>
<s>
It	O
is	O
entirely	O
separate	O
from	O
dc-based	O
implementations	O
of	O
the	O
POSIX	O
standard	O
and	O
is	O
instead	O
written	O
in	O
C	B-Language
.	O
Nevertheless	O
,	O
it	O
is	O
fully	O
backwards	O
compatible	O
as	O
all	O
POSIX	O
bc	B-Application
programs	O
will	O
run	O
unmodified	O
as	O
GNU	B-Operating_System
bc	B-Application
programs	O
.	O
</s>
<s>
GNU	B-Operating_System
bc	B-Application
variables	O
,	O
arrays	O
and	O
function	O
names	O
may	O
contain	O
more	O
than	O
one	O
character	O
,	O
some	O
more	O
operators	O
have	O
been	O
included	O
from	O
C	B-Language
,	O
and	O
notably	O
,	O
an	O
if	O
clause	O
may	O
be	O
followed	O
by	O
an	O
else	O
.	O
</s>
<s>
In	O
addition	O
to	O
C-style	O
comments	O
,	O
a	O
#	O
character	O
will	O
cause	O
everything	O
after	O
it	O
until	O
the	O
next	O
new-line	O
to	O
be	O
ignored	O
.	O
</s>
<s>
The	O
following	O
logical	O
operators	O
are	O
additional	O
to	O
those	O
in	O
POSIX	O
bc	B-Application
:	O
</s>
<s>
They	O
are	O
available	O
for	O
use	O
in	O
conditional	B-Language
statements	O
(	O
such	O
as	O
within	O
an	O
if	O
statement	O
)	O
.	O
</s>
<s>
All	O
functions	O
available	O
in	O
GNU	B-Operating_System
bc	B-Application
are	O
inherited	O
from	O
POSIX	O
.	O
</s>
<s>
No	O
further	O
functions	O
are	O
provided	O
as	O
standard	O
with	O
the	O
GNU	B-Operating_System
distribution	O
.	O
</s>
<s>
Since	O
the	O
bc	B-Application
^	O
operator	O
only	O
allows	O
an	O
integer	O
power	O
to	O
its	O
right	O
,	O
one	O
of	O
the	O
first	O
functions	O
a	O
bc	B-Application
user	O
might	O
write	O
is	O
a	O
power	O
function	O
with	O
a	O
floating-point	O
exponent	O
.	O
</s>
<s>
Because	O
the	O
syntax	O
of	O
bc	B-Application
is	O
similar	O
to	O
that	O
of	O
C	B-Language
,	O
published	O
numerical	O
functions	O
written	O
in	O
C	B-Language
can	O
often	O
be	O
translated	O
into	O
bc	B-Application
quite	O
easily	O
,	O
which	O
immediately	O
provides	O
the	O
arbitrary	B-Algorithm
precision	I-Algorithm
of	O
bc	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
Journal	O
of	O
Statistical	O
Software	O
(	O
July	O
2004	O
,	O
Volume	O
11	O
,	O
Issue	O
5	O
)	O
,	O
George	O
Marsaglia	O
published	O
the	O
following	O
C	B-Language
code	O
for	O
the	O
cumulative	O
normal	O
distribution	O
:	O
</s>
<s>
With	O
some	O
necessary	O
changes	O
to	O
accommodate	O
bc	B-Application
's	O
different	O
syntax	O
,	O
and	O
realizing	O
that	O
the	O
constant	O
"	O
9189	O
...	O
"	O
is	O
actually	O
log( 2*PI	O
)	O
/2	O
,	O
this	O
can	O
be	O
translated	O
to	O
the	O
following	O
GNU	B-Operating_System
bc	B-Application
code	O
:	O
</s>
<s>
bc	B-Application
can	O
be	O
used	O
non-interactively	O
,	O
with	O
input	O
through	O
a	O
pipe	B-Operating_System
.	O
</s>
<s>
This	O
is	O
useful	O
inside	O
shell	B-Language
scripts	I-Language
.	O
</s>
<s>
In	O
contrast	O
,	O
note	O
that	O
the	O
bash	B-Operating_System
shell	I-Operating_System
only	O
performs	O
integer	O
arithmetic	O
,	O
e.g.	O
</s>
<s>
One	O
can	O
also	O
use	O
the	O
here-string	O
idiom	O
(	O
in	O
bash	B-Operating_System
,	O
ksh	O
,	O
csh	O
)	O
:	O
</s>
