5 ms·
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 als
by pwg 11y ago
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
- creshal 11y agoWriting 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.
- vivekkannan 11y agoObviously, 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).
- nemoniac 11y agoFirst learning tip: .h files are not the place for definitions.
- vivekkannan 11y agoduly noted. will change it ASAP.
- Dewie3 11y agoThat 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.
- murbard2 11y agoGive the venerable dc a try. It can be quite succinct. http://en.wikipedia.org/wiki/Dc_%28computer_program%29 http://en.wikipedia.org/wiki/Dc_%28computer_program%29
- torrent-of-ions 11y agoThis one doesn't have abitrary precision?
- bstamour 11y agoYou can use bc interactively just fine, no needing to pipe anything. $ bc 3+4 7 ^D $