3 ms·
Or: echo "$1" | bc -l No need to rev up python.
by ubasu 13y ago
Or:
echo "$1" | bc -l
No need to rev up python.
- gnosis 13y agoA little syntactic sugar (in zsh): function calc { print $1 | bc -l } Then: calc "(1+2)*3" 9 zsh actually comes with its own little calculator: zcalc "(1+2)*3" 1> 9 2> Among other things, it features "full command line editing, including the history of previous calculations".
- eieio 13y agoI thought the same thing until I got to the part where the author used from math import * Which gives you significantly more options. I love this idea, I have always found math in the command line to be clunky.
- ubasu 13y agoThat is true, but I have found if I am doing calculations that need something like the full math library of python, it's not a one-off calculation, and I am typically on octave anyway. In any case, since I have emacs open all time, I usually do M-x calc for one-off calculations.
- merlincorey 13y agoI just evaluate random lisp in my buffers, sometimes evaluating it to output directly there. Ah emacs!
- omaranto 13y agoI do that too, with textadept & Lua instead of Emacs & elisp.
- _ZeD_ 13y agominor nitpick, you don't need "echo" $ bc -l <<< 3+2 5 $