Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How is this different from the existing command-line calculator 'bc'?

    echo "3+4" | bc 
    7
Other than not needing equations to be piped to it?

Note also that bc allows defining functions (among other features), and is also arbitrary precision (factorial of 200 below):

    $ echo "define f (x) { if (x <= 1) return (1); return (f(x-1) * x); }; f(200)"| bc
    78865786736479050355236321393218506229513597768717326329474253324435\
    94499634033429203042840119846239041772121389196388302576427902426371\
    05061926624952829931113462857270763317237396988943922445621451664240\
    25403329186413122742829485327752424240757390324032125740557956866022\
    60319041703240623517008587961789222227896237038973747200000000000000\
    00000000000000000000000000000000000


Writing your own calculator is a nice programming exercise (touches a lot of different problems and is still a small, manageable task), especially for languages you're not familiar with. Of course there's better ones for "production" use.


Obviously, bc is much more capable than calc. However, calc was not created to replace or even compete with bc or any other awesome command-line calculators. calc is my way of learning a bunch of stuffs (shunting yard).


First learning tip:

.h files are not the place for definitions.


duly noted. will change it ASAP.


You can use bc interactively just fine, no needing to pipe anything.

    $ bc
    3+4
    7
    ^D
    $


This one doesn't have abitrary precision?


That function syntax is a nice example of C-isms bleeding through. If I want to write some arithmetic, I want something more declarative and succinct than C.


Give the venerable dc a try. It can be quite succinct.

http://en.wikipedia.org/wiki/Dc_%28computer_program%29




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: