Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Calc – A fast and intuitive command-line calculator written in Go (github.com/alfredxing)
94 points by alfredxing on Feb 16, 2015 | hide | past | favorite | 33 comments


An alternative that isn't discussed in the Why not use ...? section is calc:

http://www.isthe.com/chongo/tech/comp/calc

It is very powerful, has history, shows previous calculations, and it's pretty darn quick too.

Of course, there are plenty more calculators, powerful too. I only mention calc because it bothers me that the name of this new project collides with it, without really providing anything useful beyond having been written in a fashionable language.


Thanks for bringing the original(?) calc to light.

without really providing anything useful beyond having been written in a fashionable language

The latter part of your comment sounds a bit discouraging. I think the developer didn't mean any harm an probably didn't know about this one.

PS: The dev had replied in the thread. All is well I guess.


Upvoted for calc. I use it for all the small calculation, as it most often behaves slightly better than bc

  $ echo "1/2" | bc
  0

  $ echo "1/2" | bc -l
  .50000000000000000000

  $ echo "scale=1; 1/2" | bc
  .5

  $ echo "1/2" | calc -p
  0.5

  $ echo "+1+1+1+1" | bc -l
  (standard_in) 1: syntax error

  $ echo "+1+1+1+1" | calc -p
  4

  $ echo "sqrt(-1)" | bc -l
  Runtime error (func=(main), adr=4): Square root of a negative number

  $ echo "sqrt(-1)" | calc -p
  1i

  $ echo "s(pi)" | bc -l
  0

  $ echo "sin(pi())" | calc -p
  0


Slightly shorter, and it's nice to have the expression at the end of the line:

    $ bc -l <<< "1+1"


I've been using wcalc personally, haven't had many reasons to use something else.


wcalc is pretty much the best terminal-mode calculator anywhere. It handles significant digits very well and knows about a bunch of mathematical constants in unicode form!

-> √7×2÷π−ε0×σ+α+γ+R∞×Mτ-Φ0 = 2.26885

http://w-calc.sourceforge.net/download.php


and it's apt-gettable from wheezy upwards!


Did not know about this. It looks great, I'll definitely be trying it out!

The project name was originally calc.go, but as you can imagine that didn't work out too well with `go get`.


This developer could have at least chosen a different name.

Two programs, same funcionality, same name. Haven't we learnt anything?


As I mentioned below, I chose "calc.go", but that didn't work well with the `go get` command, so I had to get rid of the ".go"


calc package is called apcalc on dbian/ubuntu.


Other comments are reasonable, but fantastic work alfredxing, played around with it just now and loved how simple and intuitive it was. The only feature I really miss here is being able to use the previous answer -- is this there and I just didn't find it? Thinking of an 'ans' constant that holds the previous answer


Thanks, and great suggestion! Would you mind opening an issue on GitHub for it? I'll probably get around to implementing it soon.


Sorry HN doesn't have reply notifications and just saw this, just added the issue!


I stopped using infix calculators a while back in favor of RPN/stack calculators (dc) because I get quite tired of parens. Is the program structured such that this change would be simple? Otherwise I feel like this is simply yet another CLI calculator.


People interested in this calculator might be interested in my project, which is written in Python:

https://github.com/ConceptJunkie/rpn

My rpn calculator started out comparable to the project described here, once I discovered the mpmath library, the project took on a life of its own and now has over 400 operations covering basic math, number theory, combinatorics, unit conversions (comparable to the GNU units program, or the Frink programming language), algebra and anything else that strikes my fancy.


The algorithm I use combines shunting-yard and postfix (RPN) evaluation, but I guess it wouldn't be too hard to modify the source to just do the RPN part.

If you want to try that, the relevant code is the Evaluate function in `compute/compute.go`.

A Google search for "command line calculator" doesn't turn up much, so I honestly didn't think there were many decent ones out there (aside from dc/bc). Are there any you have in mind?


Incidentally I wrote a simple CLI RPN calc in half an hour recently: https://github.com/alexander-b/clac

I was planning on adding a REPL-mode to it today for fun, and then someone linked me this post, saying "this could have been clac!", hehe.


I use the M-x calc in Emacs for this reason.


I find emacs calc very fitting the RPN tradition (reminiscent of HP pocket calculators), since it provides an algebraic solver; always a pleasurable thing to witness.


Obligatory XKCD: http://xkcd.com/645/


Nice! I wrote one called maths a while back. It's in Ruby but I use it pretty regularly and it does the trick:

https://github.com/commondream/maths


Emacs natives should know "C-x * *". Worth learning the bin/hex support with "d 2", "d 6".


Also checkout http://www.jasymchat.com, it is a mobile version of Jasymca, A Java based computer algebra system.


Use Tab instead: http://bitbucket.org/tkatchev/tab

Includes a calculator, but also a complete declarative data-processing language too.

E.g.:

    $ tab "[ log(@),@ : count(5) ]"  
    0	1
    0.693147	2
    1.09861	3
    1.38629	4
    1.60944	5


Qalculate has both a GUI and a command-line `qalc` util that does what `calc` seems to do and much more:

http://qalculate.sourceforge.net/


Nice and great job ! I should switch to this. I have been using python until now.

function calc { python -c "from math import *; print $1" }



Every small tool deserves special launching site and promoting if it's "written in go" or some other hyped language.


Most developers can't create something new and original or improve upon what's best out there so they reinvent things with very limited functions with something that people think is cool today (in this case, golang).


I thought you mean calc.exe


Why not use.. Scientific Calculator (PowerCalc) for Android?

https://play.google.com/store/apps/details?id=com.scaleasw.p...


My personal prejudice: I reject any calculator that does not compute the Gamma function (or factorial of non-integer arguments). Therefore, I reject this one.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: