Text ; idea: many times over a long period
What I want is that if by accident I type
dc 15 2 ^ p⏎
or
dc 15 2^p⏎
instead of
dc⏎
15 2^p⏎
, cd
makes that calculation anyway and
tells me the answer is 225.
Well, I knew the answer already, because in 1973 it was the opinion of our math teacher that we should know at least the squares up until 20 by heart. I took the challenge and I still know them today. No, not really, I’m in doubt about 18 (324?) and 19.
But it was just an example. It’s just that
it would be much easier if dc
took its
calculation instructions not only from stdin
but also as command line arguments.
What’s more, I want shells modified
(Bourne Shell sh
,
Born Again Shell bash
,
Korn Shell ksh
and also
tcsh
) in such a way that when I simply
numbers and operators to the command line and end
with a p
for print, the shell runs
dc
for me and shows me the result.
Of course it is not going to happen. And I am not going to program any of this weirdness myself.
dc
is the desk calculator, a very
old Unix program. It features arbitrary precision
(or in practice: very large, like up to 7000
decimals, just tested on FreeBSD 10.1, no problem!)
which normally, hardly anybody needs. But it can
do it.
Its instructions dc
takes in Reverse
Polish Notation (RPN). Number operands are pushed
up a stack, and operators pop the operands they
need off it and push the result up.
Hewlett Packard hand-held calculators in the 1980,
such as the HP41C that I had, worked like that.
Recently I read that even modern ones do, although
the entry mode is now software switchable between
algebraic (1+2=
) and RPN
(1 2+
).
In addition to and beside dc
I also
often use Windows’ calculator, either in
standard view or scientific view, as the case and
my actual needs may be. Switching between algebraic
and RPN entry doesn’t confuse me.
I’m getting older but I’m still flexible.
Copyright © 2014 R. Harmsen, all rights reserved.