winbc is a GNU bc-compatible arbitrary-precision calculator for Windows and Linux, written in pure Go with no C dependencies.
It implements the full GNU bc language: arbitrary-precision decimal arithmetic, user-defined functions, arrays, control flow (if/else/while/for/break/continue/return), the print statement, the read() built-in, ibase/obase/scale special variables, and the -l math library (s, c, a, l, e, j functions).
Grab the latest release from the Releases page:
| Platform | File |
|---|---|
| Windows (amd64) | winbc-windows-amd64.exe |
| Linux (amd64) | winbc-linux-amd64 |
Rename / add to your PATH as desired.
go install github.com/fermat-tech/winbc@latestRequires Go 1.21 or later.
winbc [-hlwsqv] [long-options] [FILE ...]
-h, --help print this help and exit
-l, --mathlib load standard math library (sets scale=20)
-w, --warn warn about POSIX extensions used
-s, --standard process only POSIX bc language
-q, --quiet suppress welcome banner
-v, --version print version and exit
Files are processed in order before reading standard input. When stdin is a terminal, an interactive REPL prompt is shown.
# Interactive
winbc
# One-liner
echo "scale=10; 4*a(1)" | winbc -l # pi to 10 decimal places
# Script file
winbc script.bcThe internal packages are documented on pkg.go.dev:
| Package | Description |
|---|---|
lexer |
Tokenises bc source into a Token stream |
parser |
Recursive-descent parser; produces AST nodes |
interp |
Tree-walk interpreter / evaluator |
num |
Arbitrary-precision decimal arithmetic |
MIT — see LICENSE.md.