pc is a substantially enhanced fork of the SGI/Be/Haiku programmers calculator.
- Automatic input and output base conversions::
- Binary (base 2):
0b111101001101001 - Octal (base 8):
0o75151(or0075151) - Decimal (base 10):
31337 - Hex (base 16):
0x7a69 - Roman:
0rMCCCXXXVII - ASCII:
'zi'
- Binary (base 2):
- Optional support for:
- Explicit modes:
- Three calculation modes are available, via named commands:
auto,signed, andunsigned. Themodecommand can be used to query the current calculation mode.- All operations except comparisons are performed using
unsigned integer calculations in the default
automode.
- Braces (e.g.,
{ … }) force signed calculation (overriding global mode). - Brackets (e.g.,
[ … ]) force unsigned calculation (overriding global mode).
- Three calculation modes are available, via named commands:
- Variables:
- Builtins:
- Registers:
- Perform time formatting or casting by storing to special purpose registers
(i.e., unsigned C types
char,short,int,long,long long), list via theregscommand).- Stores to registers clamp and mask to the register width.
- Perform time formatting or casting by storing to special purpose registers
(i.e., unsigned C types
- Easily portable to any POSIX-ish system with a C99 compiler (or Ch 7.0+), less easily to others.
- Currently developed on IBM AIX, and regularly tested on PASE for IBM i (OS/400), macOS, FreeBSD, NetBSD, OpenBSD, Solaris, illumos, Haiku, Windows (MSVC, MinGW-w64), Atari ST (TOS and MINT, built using CrossMINT), Amiga 68K (built using Amiga-GCC), Linux, ELKS (built using IA16-GCC), Mac OS 68K (built using Retro68), and DOS (built using DJGPP, IA16-GCC, and Open Watcom V2).
- You can try out
pcby executing./pc.cdirectly, and it should just run (using shell magic), or, - Build it with
make. Standard environment variables (e.g.,CC,CFLAGS,LDFLAGS) are respected. - Build with Microsoft Visual C/C++ using:
cl pc.c /O2 /W4 - Common line editing packages (
libedit,editline,readline, andlinenoise) are supported and usually automatically configured (viapkg-configmagic). - Review the
Makefileto see available build options.
- Interactive examples:
easter.pcis a program that calculates the date of Easter (and checks if it's today).- You can modify the program or use something like
faketime(i.e.,faketime -m '2025-04-20 12:00:00') if you want to test arbitrary dates. You can see the full output of this program here (with all optional base conversions enabled).
- You can modify the program or use something like
sqrt.pcis a program that calculates the square root ofn(wherenis, by default, a large random number). You can see the full output of this program here.
weekday.pcis a program that calculates the day of the week. The formatted date is also displayed (via a store to theGTregister) for confirmation. You can see the full output of this program here.
- Linting:
- C code must pass Cppcheck,
Clang Analyzer,
GCC Analyzer,
PVS-Studio,
NetBSD Lint,
Oracle Lint,
Flawfinder (
-m3), Cppi, Ch, andclang -Weverythinglinting and static analysis. - All shell code in the repository must pass
ShellCheck, and the
Makefileis compatible with POSIX, AIX, BSD, and GNU stylemaketools.
- C code must pass Cppcheck,
Clang Analyzer,
GCC Analyzer,
PVS-Studio,
NetBSD Lint,
Oracle Lint,
Flawfinder (
pcis distributed under the terms of the MIT License.- The repository is compliant with version 3.3 of the REUSE specification.