Est. 1991 Beginner

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

Paradigm Procedural
Typing Dynamic, Weak
First Appeared 1991
Latest Version GNU bc 1.08.2 (2025)

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:

FeaturePOSIX bcGNU bc
Variable namesSingle lowercase letterMulti-character identifiers
Comments/* ... */ only/* ... */ and # to end of line
else clauseNot specifiedSupported
print statementNot specifiedSupported, with formatting
read() functionNot specifiedReads a number from stdin
continue in loopsNot specifiedSupported
Boolean operatorsNot specified&&, `
String valuesOnly in printAssignable to variables
last / . variableNot specifiedHolds the last result
Command-line -e / -qNot specifiedSupported

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:

  1. Parser: A YACC/Bison grammar parses bc source into an abstract representation.
  2. Bytecode compiler: Functions are compiled to an internal bytecode representation, stored in memory until invoked.
  3. 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:

FunctionDescription
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Floating-point arithmetic in shell scripts
echo "scale=4; 355/113" | bc            # 3.1415

# Percentage calculation
echo "scale=2; (47/200) * 100" | bc     # 23.50

# Math library: e to six places
echo "scale=6; e(1)" | bc -l            # 2.718281

# Hex to decimal conversion
echo "ibase=16; FF" | bc                # 255

# Large exponentiation
echo "2^100" | bc                       # 1267650600228229401496703205376

It is also frequently used as an interactive REPL:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ bc -l
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
define factorial(n) {
    if (n <= 1) return 1
    return n * factorial(n - 1)
}
factorial(50)
30414093201713378043612608166064768844377641568960512000000000000
quit

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:

  1. It made bc free. Before GNU bc, the only bc was the AT&T Unix bc, 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.

  2. 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.

  3. 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 bc binary. 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

1975
Original bc appears in Unix Version 6, written by Lorinda Cherry and Robert Morris at Bell Labs as a preprocessor that translated C-like syntax into dc postfix and piped it through dc
1991
Philip A. Nelson releases the first version of GNU bc, a complete rewrite that does not depend on dc; instead it parses bc source, compiles it to an internal bytecode, and executes the bytecode directly
1992
bc is standardized as part of POSIX.2 (IEEE Std 1003.2-1992, Shell and Utilities), defining the minimum feature set that all bc implementations — including GNU bc — must support
2000
GNU bc 1.06 is released, the long-stable branch that ships in most late-1990s and early-2000s Linux distributions including Red Hat and Debian
2006
GNU bc 1.06.95 released; this version remains the bundled bc in enterprise Linux distributions and is the version many users encounter for over a decade
2017
GNU bc 1.07.1 released in September 2017; becomes the version shipped in Ubuntu 18.04 LTS, Debian Buster, and many other major distributions
2024
GNU bc 1.08 released in late 2024, adding long-requested readline/libedit command-line editing support and bundling dc bug fixes
2025
GNU bc 1.08.2 released as the current stable version, available in Arch Linux, Alpine, Homebrew, and other rolling-release distributions

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:latest

Example usage:

docker run --rm alpine sh -c 'apk add -q bc && echo "scale=20; 4*a(1)" | bc -l'
Last updated: