A flexible calculator that ships with a Windows GUI front end and a cross-platform CLI. Both layers share the same C parser so complex expressions behave identically.
All platforms require the GNU compiler gcc.
Windows note: the easiest path to
gccis through Cygwin.
The CLI can be compiled on macOS. Install the toolchain via Homebrew:
brew install gccThe CLI runs on common Linux distributions. Install the essentials with apt:
sudo apt update
sudo apt install build-essentialTo write changes to help.txt, you'll need xxd.
sudo apt install xxdFirst, use Windows Package Manager (winget) to install Cygwin:
winget install Cygwin.CygwinNext, download the Cygwin installer setup-x86_64.exe. Move it to
/usr/bin (or another location on your PATH) so it can be invoked from the command prompt, then
install gcc:
setup-x86_64.exe -P gcc-coreTo write changes to help.txt, you'll need xxd.
setup-x86_64.exe -P xxdFollow the installer prompts until you reach Select Packages.
If
gcc-coreis not listed, search for it, mark it for installation, then continue.
The CLI builds on macOS, Linux, and Windows. Compile the core engine:
gcc ccal.c -o ccal.exeTo include updates to help.txt, regenerate the header before compiling:
xxd -i help.txt > help.hThis embeds the latest help text in the executable.
Start by cloning the code and switching into the working directory:
git clone https://github.com/jhauga/ccal.git
cd ccalCompile the GUI without bundling extra resources:
gcc -DBUILDING_GUI ccal.c ccal_gui.c -o ccal_gui.exe -mwindowsFirst compile the resource script into a COFF object:
windres ccal_gui.rc -O coff -o ccal_gui.resThen link the GUI, resource object, and core engine together:
gcc -DBUILDING_GUI ccal_gui.c ccal.c ccal_gui.res -o ccal_gui.exe -mwindows- Launch
ccal_gui.exefrom Explorer or the command line. - Enter expressions using the on-screen buttons or the keyboard.
- Press
Enteror click=to evaluate. - Press
dto clear the current expression and result. - Use
Ctrl + Cto copy the result to the clipboard.
Comma formatting is applied automatically while you type, and backspace/delete skip over commas so numbers stay nicely grouped.
To use the CLI, pass digits, arithmetic operators, and nesting characters ((, ), {, }, [, ]) separated with spaces.
Important: use
xinstead of*, andpinstead of^, unless you pass-q/--quote.
+ -> addition
- -> subtraction
/ -> division
x -> multiplication
* -> multiplication (use -q/--quote)
p -> exponentiation (power of)
^ -> exponentiation (use -q/--quote)
To use the command line tool either input all elements of the equation separated with a space
character, or use the quote option -q, --quote which does not require elements to be separated
with a space character.
If nested brackets cause argument parsing issues, escape them or wrap the expression in quotes. Square brackets generally require the fewest escapes.
Add two numbers:
> ccal 1 + 1
> 2Perform a complex equation:
> ccal [ [ 34 x 11 ] / [ 10 - 5 ] ] - [ 4 x 53 x [ 30 / 10 ] ]
> -561.2Without
-q/--quote, order of operations can break across spaced tokens, so expressions like:
> ccal [ [ 34 x 11 ] / [ 10 - 5 ] ] - [ 4 x 53 x [ 30 / 10 ] + [ 2 x [ 40 - 20 ] ] ] / [ 8 x 6 x [ 12 / 2 ] + 4 ]
> -2.058904109589041will evaluate incorrectly (the correct answer is 72.4849). Use -q/--quote—recommended—or add explicit parentheses to force the intended precedence:
Quote option (recommended):
> ccal -q "[[34x11]/[10-5]]-[4x53x[30/10]+[2x[40-20]]]/[8x6x[12/2]+4]"
> 72.48493150684931Manual grouping:
> ccal [ [ 34 x 11 ] / [ 10 - 5 ] ] - [ [ [ 4 x 53 ] x [ 30 / 10 ] + [ 2 x [ 40 - 20 ] ] ] / [ 8 x 6 x [ 12 / 2 ] + 4 ] ]
> 72.48493150684931Both approaches return the correct value.
Terminals treat commas as separators, so wrap comma-separated numbers in quotes or use
-q/--quote. Instead of:
> ccal 1,000 - 1
> Error: Invalid expressionUse the quote option or wrap comma numbers manually:
Quote option:
> ccal --quote "2,000-1,000"
> 1000Manual quoting:
> ccal "2,000" - "1,000"
> 1000to get the correct calculation.
To calculate exponentiation, use p as the operator. With -q/--quote, you can also use ^.
> ccal 2 p 2
> 4
> ccal --quote "2^2"
> 4