GNU bc
The GNU Project implementation of the POSIX bc arbitrary-precision calculator language, a standalone bytecode interpreter first released by Philip A. Nelson in 1991 and shipped by default on most Linux distributions.
Created by Philip A. Nelson
GNU bc is the GNU Project’s implementation of the POSIX bc arbitrary-precision calculator language. First released by Philip A. Nelson in 1991, it is a complete rewrite of the original 1975 Bell Labs bc — and unlike that original, GNU bc has no dependency on dc. Instead it parses bc source code, compiles it to an internal bytecode, and executes the bytecode directly. GNU bc ships as the default bc on virtually every Linux distribution and is licensed under the GNU GPL.
For the history of the bc language itself — its 1975 origin at Bell Labs, the relationship to dc, and the other implementations (OpenBSD bc, Gavin Howard’s bc) — see the bc encyclopedia page. This page focuses specifically on the GNU implementation.
Origins
By the late 1980s, the GNU Project was systematically producing free-software replacements for every component of a Unix system. The original AT&T bc and dc were not free software, and a GPL-licensed replacement was needed to complete a fully free Unix-like environment.
Philip A. Nelson took on the task and produced GNU bc, with an initial release in 1991. Rather than reproducing the original architecture — a YACC-based preprocessor that compiled bc source into dc postfix and shelled out to dc for evaluation — Nelson made a deliberate design departure: GNU bc would be a self-contained interpreter with no runtime dependency on dc at all.
The GNU Project later took on the maintenance of dc separately. As of recent GNU bc releases, the GNU bc source distribution actually bundles a dc implementation as well, but the two programs no longer have the producer–consumer relationship of the original Bell Labs design.
Design Departures from Original bc
GNU bc adheres to the POSIX bc specification but layers practical extensions on top. The headline differences from the original 1975 bc and from a strictly POSIX-conforming bc are:
| Feature | POSIX bc | GNU bc |
|---|---|---|
| Variable names | Single lowercase letter | Multi-character identifiers |
| Comments | /* ... */ only | /* ... */ and # to end of line |
else clause | Not specified | Supported |
print statement | Not specified | Supported, with formatting |
read() function | Not specified | Reads a number from stdin |
continue in loops | Not specified | Supported |
| Boolean operators | Not specified | &&, ` |
| String values | Only in print | Assignable to variables |
last / . variable | Not specified | Holds the last result |
Command-line -e / -q | Not specified | Supported |
These extensions are documented in the GNU bc manual page and are common enough that many shell scripts rely on them — which is why those scripts often break when run on a strict POSIX bc or on the BSD bc shipped with macOS.
Architecture
GNU bc is implemented in C and has three logical layers:
- Parser: A YACC/Bison grammar parses bc source into an abstract representation.
- Bytecode compiler: Functions are compiled to an internal bytecode representation, stored in memory until invoked.
- Bytecode interpreter: A stack-based virtual machine executes the bytecode, calling into an arbitrary-precision arithmetic library for numeric operations.
The arbitrary-precision arithmetic library represents numbers as arrays of decimal digits (one digit per byte, in older versions; more recent versions reportedly pack multiple decimal digits per machine word to improve performance). All arithmetic is performed in decimal, not binary — this is what makes bc correct for financial calculations and reproducibly comparable across machines, at the cost of being slower than hardware floating point.
Numbers have a scale attribute that records the number of decimal places to the right of the decimal point. The global scale variable controls how many decimal places division and the math-library functions produce.
Built-in Math Library
The -l (load math library) flag activates six built-in mathematical functions and sets the default scale to 20:
| Function | Description |
|---|---|
s(x) | Sine of x (x in radians) |
c(x) | Cosine of x |
a(x) | Arctangent of x |
l(x) | Natural logarithm of x |
e(x) | Exponential function (e^x) |
j(n,x) | Bessel function of integer order n |
The classic high-precision pi calculation uses the arctangent identity:
scale=1000
4 * a(1)
This produces pi to one thousand decimal places using only what is built into GNU bc — no external library or compilation needed.
Typical Usage
GNU bc is most commonly invoked as a one-shot expression evaluator from a shell pipeline:
| |
It is also frequently used as an interactive REPL:
| |
Version History
GNU bc’s release cadence has historically been slow, with multi-year gaps between releases — appropriate for a small, mature tool whose specification is set by POSIX:
- 1.06 / 1.06.95 (around 2000–2006): The long-stable line shipped in many early-2000s Linux distributions.
- 1.07.1 (September 2017): The version adopted by Ubuntu 18.04 LTS, Debian Buster, and many other distributions.
- 1.08 (late 2024): Added readline/libedit command-line editing — a long-standing user request — and incorporated dc bug fixes.
- 1.08.2 (2025): The current stable release, available in Arch Linux, Alpine, Homebrew, and other rolling-release distributions.
The seven-year gap between 1.07.1 and 1.08 was a frequent source of complaint in the wider community and contributed to the rise of alternative implementations such as Gavin Howard’s bc, which was eventually adopted as the default bc by FreeBSD and the Android Open Source Project.
Licensing
GNU bc is licensed under the GNU General Public License, version 3 or later (older releases used GPL-2.0-or-later). This is one of the practical reasons FreeBSD and Android chose alternative implementations: both projects prefer permissively-licensed base-system components, and Gavin Howard’s bc is BSD 2-clause.
Current Status
GNU bc is actively maintained as of 2025. Development happens on the GNU Savannah hosting infrastructure, and the project remains the dominant bc implementation in the GNU/Linux ecosystem. The release in late 2024 of version 1.08 — and the follow-up 1.08.2 in 2025 — ended a long quiet period and demonstrates that the project still receives attention from its maintainers.
For day-to-day use, GNU bc is essentially invisible infrastructure: it is the thing that happens when you type bc at a Linux shell prompt, and the thing that runs when a shell script pipes an expression into bc -l. Half a century after Bell Labs invented the bc language, the GNU implementation is the version that the majority of bc invocations on Earth actually run through.
Why GNU bc Matters
GNU bc matters for three reasons that are easy to overlook:
It made bc free. Before GNU bc, the only
bcwas the AT&T Unixbc, which was not free software. Without GNU bc, every GNU/Linux distribution from the 1990s onward would have needed to either omit a POSIX-required utility or ship a non-free one.It demonstrated an architectural alternative. By separating bc from dc, GNU bc showed that the language could stand on its own as a self-contained interpreter, rather than being permanently coupled to the older RPN calculator. Every subsequent rewrite (OpenBSD bc, Gavin Howard’s bc) has followed that same independent-interpreter model.
It is the de facto bc on Linux. A very large number of Linux installations — servers, containers, developer workstations, embedded devices — carry GNU bc as the default
bcbinary. When a CI pipeline computes a percentage, when a backup script calculates remaining disk space, when an interactive terminal session needs a quick decimal multiplication, GNU bc is the program doing the work.
It is not a flashy piece of software. It is exactly the kind of small, correct, long-lived utility the GNU Project was created to produce.
Timeline
Notable Uses & Legacy
Linux Distributions
GNU bc is the default bc implementation in Debian, Ubuntu, Fedora, Arch Linux, openSUSE, Alpine Linux, and the vast majority of GNU/Linux distributions, where it ships as the 'bc' package and is available out of the box or via a one-line install.
Shell Script Arithmetic
Because the POSIX shell and Bash perform only integer arithmetic, GNU bc is the canonical tool invoked from shell scripts when decimal or arbitrary-precision math is required. The idiom 'echo "scale=4; $a / $b" | bc -l' appears throughout system administration scripts and CI pipelines.
Homebrew on macOS
Homebrew packages GNU bc as the 'bc' formula, allowing macOS users to replace Apple's bundled BSD bc with the GNU implementation to gain extensions like multi-character variable names, the print statement, and # line comments.
POSIX Conformance Testing
GNU bc serves as one of the widely-deployed reference implementations against which POSIX bc conformance tests are run, contributing to the practical interpretation of the POSIX.1-2024 bc specification on Linux platforms.
Computational Demonstrations
GNU bc with the -l math library is commonly used in educational settings and online code golf challenges to compute high-precision values of constants such as pi and e, since 'scale=1000; 4*a(1)' yields pi to one thousand decimal places with no extra tooling.
Language Influence
Influenced By
Running Today
Run examples using the official Docker image:
docker pull alpine:latestExample usage:
docker run --rm alpine sh -c 'apk add -q bc && echo "scale=20; 4*a(1)" | bc -l'