A simple command-line calculator written in Go
A simple, fast, and intuitive command-line calculator written in Go.
Install calc as you would any other Go program:
go get github.com/alfredxing/calc
You can use calc in two ways: shell mode and command.
This is probably the mode you'll want to use. It's like the
irb. The shell mode uses the
terminalpackage provided by
golang.org/x/crypto/ssh/terminal, which means it supports many of the shell features you know and love (like history, pasting, and the
1+1 2 3(5/(3-4)) -15 3pi^2 29.608813203268074 @+1 30.608813203268074 @@@*2 -30 ln(-1) NaN ```
You can also use calc to evaluate an expression with just a single command (i.e. without opening the shell). To do this, just use
shell bash$ calc 1+1 2 bash$
calc supports all the standard stuff, and I'm definitely adding more later (also feel free to fork and add your own!)
Previous results can be accessed with the
@symbol. A single
@returns the result of the last computation, while multiple
@gets the nth last result, where n is the number of
@s used (for example,
@@returns the second-last result,
@@@@@returns the fifth-last result).
The alternatives above are all great, and have their own advantages over calc. I highly recommend looking into these if you don't like how calc works.