This site is now 100% read-only, and retired.

My desktop calculator is

Submitted by Anonymous

Tags: none.
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

 

 

 

Re: My desktop calculator is
Posted by gonad (219.89.xx.xx) on Sun 25 Sep 2005 at 00:07
I use

perl -e '$calc = 5 * 4; print $calc, "\n";'

There is probably a better way

[ Parent ]

Re: My desktop calculator is (Perl)
Posted by ybiC (70.171.xx.xx) on Sun 25 Sep 2005 at 14:08
Save yourself a few keystrokes by skipping the unecessary variable assignment:

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 ]

Re: My desktop calculator is (Perl)
Posted by matej (158.193.xx.xx) on Sun 25 Sep 2005 at 15:29
saving keystrokes? if you need save some cpu cycles as well (e.g. do some math in loops etc) you can do it in shell :)

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 ]

Re: My desktop calculator is (Perl)
Posted by Anonymous (80.136.xx.xx) on Mon 26 Sep 2005 at 20:58
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 ]

Re: My desktop calculator is (Perl)
Posted by Anonymous (80.136.xx.xx) on Mon 26 Sep 2005 at 21:12

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 ]

Re: My desktop calculator is
Posted by Steve (82.41.xx.xx) on Sun 25 Sep 2005 at 15:24
[ 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 ]

Re: My desktop calculator is
Posted by Anonymous (59.120.xx.xx) on Thu 29 Sep 2005 at 10:54
Of course you mean Polish notation , not reverse Polish notation , Steve...

- Math Nazi

[ Parent ]

Re: My desktop calculator is
Posted by Steve (82.41.xx.xx) on Thu 29 Sep 2005 at 11:24
[ View Weblogs ]

Of course. D'oh!

Steve
--

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (83.215.xx.xx) on Sun 25 Sep 2005 at 16:53
libterm-readline-gnu-perl documentation contains an example
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 ]

Re: My desktop calculator is
Posted by whizse (195.38.xx.xx) on Sun 25 Sep 2005 at 19:25
I use Qalculate! myself. Also available as a CLI program.

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (84.45.xx.xx) on Sun 25 Sep 2005 at 20:28
I use calculator applications, or a hardware calculator when it is to hand (solar powered and bought for my Maths degree nearly 20 years ago) for simple stuff.

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 ]

Python
Posted by forrest (208.42.xx.xx) on Sun 25 Sep 2005 at 21:04
[ View Weblogs ]

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 ]

Surely its octave/matlab
Posted by Anonymous (159.117.xx.xx) on Mon 26 Sep 2005 at 01:20
Surely others people out there are like me and need a bit more power. At home its octave, and at work where other pay the licening fee its matlab.

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 ]

You forgot an option
Posted by rhemasoundorg (66.23.xx.xx) on Mon 26 Sep 2005 at 19:08
For us true geeks... :-) you forgot to list slide rules, and log and trig tables...

[ Parent ]

Re: You forgot an option
Posted by Anonymous (86.129.xx.xx) on Mon 26 Sep 2005 at 19:14
abacus, anyone??

[ Parent ]

Re: You forgot an option
Posted by Steve (82.41.xx.xx) on Mon 26 Sep 2005 at 20:05
[ 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 ]

Re: You forgot an option
Posted by Anonymous (213.216.xx.xx) on Mon 26 Sep 2005 at 22:28
Nope. "Separate hardware" is right there.

[ Parent ]

Re: My desktop calculator is
Posted by undefined (192.91.xx.xx) on Mon 26 Sep 2005 at 22:05
i use to always use a hardware calculator, but switched to software calculators a few years ago.

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 ]

Re: My desktop calculator is
Posted by Anonymous (213.164.xx.xx) on Wed 28 Sep 2005 at 13:47
The default gnome calculator is gcalctool, it supports order of operations.

[ Parent ]

Re: My desktop calculator is
Posted by deego (24.197.xx.xx) on Tue 27 Sep 2005 at 13:48
Missing poll options :)

* My editor: Emacs: (* 2 3) ==> 6

* An emacs based bot which I find handier: * 2 3 ==> 6

(well, I sometimes also use octave.. )

[ Parent ]

Re: My desktop calculator is
Posted by Steve (82.41.xx.xx) on Wed 28 Sep 2005 at 13:11
[ 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 ]

Re: My desktop calculator is
Posted by deego (24.197.xx.xx) on Wed 28 Sep 2005 at 14:33
True,

Emacs' calc handles large integers. And clisp, etc. can handle arbitrarily large integers.

OTOH, octave is indeed more convenient in such cases...

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (213.216.xx.xx) on Fri 30 Sep 2005 at 15:56
Emacs obviously falls under REPL / (elisp) interpreter.

Do note that there is a (recommended) low limit for poll options so you can't list every atomic possibility!

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (62.2.xx.xx) on Tue 27 Sep 2005 at 15:55
i use google :-)

[ Parent ]

Re: My desktop calculator is
Posted by SanctimoniousHypocrite (12.221.xx.xx) on Tue 27 Sep 2005 at 19:28
[ 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 ]

Re: My desktop calculator is python
Posted by outreal (82.239.xx.xx) on Wed 28 Sep 2005 at 00:31
I just type python to enter interactive mode and that's it.
Once my calculation is done (simply enter, e.g.: 3*5) I ^D to exit.

[ Parent ]

Re: My desktop calculator is
Posted by hardik (61.95.xx.xx) on Wed 28 Sep 2005 at 06:28
Most of time, I am with my browser, So used firefox calculator
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 ]

Re: My desktop calculator is
Posted by Anonymous (128.139.xx.xx) on Wed 28 Sep 2005 at 14:14
python all the way.

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (68.85.xx.xx) on Wed 28 Sep 2005 at 20:09
Me, too.

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (70.246.xx.xx) on Thu 29 Sep 2005 at 06:07
As a quick way to convert any base to decimal, you can
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 ]

Re: My desktop calculator is
Posted by Anonymous (213.6.xx.xx) on Thu 29 Sep 2005 at 14:43
What about "ruby -m"?

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (213.216.xx.xx) on Fri 30 Sep 2005 at 15:57
ruby: invalid option -m (-h will show valid options)

irb is a REPL for ruby BTW.

[ Parent ]

Re: My desktop calculator is
Posted by Anonymous (216.148.xx.xx) on Fri 30 Sep 2005 at 17:03
Google

[ Parent ]