My desktop calculator is
Submitted by Anonymous
| bc or dc |
![]() 26% | 113 votes |
| Repl/interpreter |
![]() 3% | 17 votes |
| My shell |
![]() 4% | 19 votes |
| A calculator application |
![]() 32% | 140 votes |
| Separate hardware |
![]() 11% | 50 votes |
| A pencil and paper |
![]() 3% | 15 votes |
| My brain |
![]() 17% | 74 votes |
| Total 433 votes |
perl -e '$calc = 5 * 4; print $calc, "\n";'
There is probably a better way
[ Parent ]
perl -e 'print 5*4,"\n";'
perl -e 'print 20/4,"\n";'
perl -e 'print 4**2,"\n";'
perl -e 'print sqrt 16,"\n";' perldoc perlop for details, yo.
[ Parent ]
echo $((1+1))
touch $(($(date +%S)%10)).txt
and because my bash claims that sqrt cannot be found, but I guess some sin, cos, exp bins would come handy sometimes :)
eh, shellists would have to miss ln, of course..
[ Parent ]
zsh[123]: perl -lne 'print eval $_' 5+3 8 123*7+5 866 $a=3 3 $b=4 4 $a + $b 7 ^D
The "-l" tells perl to add the newline after each print, the "-n" tells it to loop the expression passed with "-e" and thus you spare the "print" and "\n" everywhere.
Bash or the Z-Shell aren't bad either:
zsh[124]: echo $[4+3] $[5*6] 7 30
[ Parent ]
P.S. As this is perl, you can omit the "$_" of course, thus perl -lne 'print eval' is all one needs.
And the nice thing about perl is that it's quiet. I find the increasing tendency to waste screen real estate with copyright notes or disclaimers annoying. Compare e.g. 'tar xf a.tar' to 'unzip a.zip' to see what I mean.
[ Parent ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
I've done this sometimes, but I just run:
steve@skx2:~$ perl print 3*97; ^D
Typing the program interactively allows using variables more cleanly, and without worrying about quoting.
To be honest when I do fall back onto something programmatic I tend to switch to the *scratch* buffer of Emacs and enter something like:
(* 33 333443)
Then M-x eval-print-last-sexp, or Ctrl-j inserts the answer into the buffer.
Of course using this approach does rely upon you knowing how to use the reverse Polish notation...
Steve
--
[ Parent ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Of course. D'oh!
Steve
--
[ Parent ]
that's a bit more comfortable.
apt-get install libterm-readline-gnu-perl
#this will install and start it, use at your own risk!
s=/usr/share/doc/libterm-readline-gnu-perl/examples/perlsh.gz
d=/usr/local/bin/perlsh
zcat $s > $d
chmod +x $d
$d
Example session:
main[1]$ 1+1
2
main[2]$ for ($i=0; $i<100; $i++) {$x=cos($x);} ; $x
0.739085133215161
Benefits:
+ history support; edit previous expression with arrow keys
+ waste less time with typing and quoting
[ Parent ]
[ Parent ]
But yacas for anything more challenging.
yacas
In> D(x)Sin(x)*Cos(x)
Out> Cos(x)^2-Sin(x)^2
Oh yeah I remember that now it comes to mentioning it.
Although Yacas can be a bit temperamental ("cosh" is not equivalent to "Cosh"), it does pretty much everything you need for undergraduate maths degrees, although you do need to "know" your mathematics to understand when it did what you want, and when it messed up.
[ Parent ]
I'm a perl programmer through and through, and I don't know much about python at all ... but I've begun just typing python at the command line when I want to do some basic math.
Python's interactive shell is nicer than having to type perl -le 'print ... all the time, and basic math is about the same in any language.
[ Parent ]
for simple stuff
[/home/me]$ echo "sin(1+i)" | octave -q
ans = 1.29846 + 0.63496i
[/home/me]$
Or run it interactively when you want to do more interesting stuff- like some digital signal processing.
Also like other scripting languages (like perl and bash) you can write interactice scripts:
#!/usr/bin/octave -q
a=input("pick a number: ");
sqrt(rand(a))
Elivs
[ Parent ]
[ Parent ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
I have a slide rule... Although I've never really mastered it. I've seen some people do amazing things with them, but beyond looking at it every now and again and doing a few calculations for fun it just gets ignored sitting in the closet out of harms way.
I'm still hoping somebody will buy me a small abacus at some point in the future. I've dropped enough hints around birthday time; but no luck yet. Maybe next year!
Steve
--
[ Parent ]
when i'm within x i use galculator. initially i used gcalc (default gnome calculator) until i realized it didn't support order of operations (1 + 2 * 3 = 7, not 9).
when i'm on a console or ssh i use bc & dc (though i still struggle with remembering dc's commands).
[ Parent ]
* My editor: Emacs: (* 2 3) ==> 6
* An emacs based bot which I find handier: * 2 3 ==> 6
(well, I sometimes also use octave.. )
[ Parent ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
I often use emacs as I said above, but it does have issues with large numbers, or fractions:
(* 100000 10000) -73741824 (* 3.3 3) 9.899999999999999
Steve
--
[ Parent ]
Emacs' calc handles large integers. And clisp, etc. can handle arbitrarily large integers.
OTOH, octave is indeed more convenient in such cases...
[ Parent ]
[ Send Message | View SanctimoniousHypocrite's Scratchpad | View Weblogs ]
Anything that's rpn. Most often I use an HP-11c. If X is available, grpn is nice for casually checking something. At the higher end, there is Nonpareil, which its author describes as
a high-fidelity simulator for calculators. It currently supports many HP calculators models introduced between 1972 and 1982. Simulation fidelity is achieved through the use of the actual microcode of the calculators, thus in most cases the simulation behavior exactly matches that of the real calculator. In particular, numerical results will be identical, because the simulator is using the BCD arithmetic algorithms from the calculator.
[ Parent ]
Once my calculation is done (simply enter, e.g.: 3*5) I ^D to exit.
[ Parent ]
extension. Check below link.. https://addons.mozilla.org/extensions/moreinfo.php?application=fi refox&category=Miscellaneous&numpg=10&id=1194
With Cheers,
Hardik Dalwadi.
[ Parent ]
use the bash shell. The below example converts from
hex to decimal.
=======================================
~$ declare -i variable
~$ variable=16#8000
~$ echo $variable
32768
~$ unset variable
~$ echo $variable
~$
=======================================
To convert from decimal to hex you could use bc like this:
~$ echo 'obase=16;ibase=10;32768' | bc
~$ 8000
=======================================
Use the "scale" operator in bc for better resolution:
~$ echo "scale=6; 355 / 113" | bc
~$ 3.141592
easy as pi...
[ Parent ]

26%