Shortly:
calc.pl
is a download-and-use terminal calculator.
It is handy, easily extendable, tape-like. It comes with
most of usual and some financial and physical functions.
You will like it.
Yes, there is a lot of calculators
for linux on the web.
Once I was looking for something simple, fast to use,
something where you can see the history of operations
(tape calculator like gtapecalc),
with minimum use of mouse,
I didnot succeed. Most of the calculators are GUI - means that
functions you must use the mouse or learn some
shortcuts.
Non-GUIs look too complicated (like Easy
Stack Calculator) or
look too simple (like lcalc).
There are "linux-built-in" things like bc
(arbitrary
precision calculator language) or octave, but
their purpose is
a little bit different from what I wanted.
This simple, but powerfull
calc.pl PERL
calculator contains
features,
that comeout from everyday use. Lets name some:
Calculator is written in perl, based on perl's own formula
evaluation
and using 'stty cbreak' keyboard control. Program has NO module
dependences, it is a simple one file script. This implies the
requirements.
That means usual linux system that understands 'stty cbreak'
and perl interpreter (present on virtualy every linux distribution).
Tested on fedora, redhat 7.3, knoppix, dyne::bolic...
Shortly:
Linux with perl.
Download it, unzip it (gunzip calc.pl.gz), change the
execution
flag (chmod +x perl.pl), run it (./calc.pl). Preferably - copy it
to the $HOME/bin directory to be able to run it from everywhere.
(echo $PATH, if you want to see the directories that are searched
for executables).
Shortly:
No instalation.
Suppose you have a calc.pl prompt.
4+5
9.000000
*8
72.000000
/12
6.000000
**2
36.000000
sqrt
6.000000
/( 2**2 +3^3 - 3 -26)
3.000000
You can work in radians or degrees, here is an example:
deg
goniometric in degrees
30
30.000000
sin
0.500000
rad
goniometric in radians
asin
0.523599
/pi
0.166667
*180
30.000000
deg
goniometric in degrees
cos
0.866025
acos
30.000000
tan
0.577350
atan
30.000000
log(1E3)
3.000000
10**
1000.000000
ln(1000)
6.907755
e**
1000.000000
exp(6.907755)
999.999721
pi
3.141593
**2
9.869604
You could see before, how the constant "e" or how 10 is
exponentiated to the last result value, or how you exponentiate the
last result value.
Exactly. And this is also a weak point of it. Press twice
ENTER
to clear the memory ( pressing once - you just print a break-line).
pi
3.141593
-3
0.141593 ...!substaction..
pi
3.141593
space-3
-3.000000e+00
Variables - always lowercase. Watch the different
ways to input the value to variable(s):
a=3
3.000000
4
4.000000
=b
4.000000
sqrt(b**2+a**2)
5.000000
(a,b)=(6,7+1)
2.000000
sqrt(b^2+a**2)
10.000000
c=
10.000000
enter
---------------------------------
enter
================================= AC
c
10.000000
Yes.
e=2.71828182845904523536
pi=3.141592653589
hbar=6.581E-22 MeV s
ev=1.602E-19 Coulomb (electron charge)
hbarc=197 MeV fm
offs=32 (column where to display the result)
You can easily add your own predefined variables by editing
the fist
several lines of the program.
Well. There are two DEFAULT OPERATION modes. Again, there
is a danger - once you forget that you are in DO mode, you
get wrong results. Pay attention to the warnings on the right
side of the result. Remark the "..DO" warning, when default operation
mode is on
1st mode: write + and then enter (or - or *)
+
default operation
defined: + (-x is operation!, not a negative number)
1
1.000000 ..DO
1
2.000000 ..DO
1
3.000000 ..DO
+5
11.000000 ..DO
enter
default operation
cleared
---------------------------------
+++3.23
default operation
defined: +++3.23 (-x is operation!, not a negative number)
1
4.230000 ..DO
2
5.230000 ..DO
1
4.230000 ..DO
enter
default operation
cleared
---------------------------------
Some financial specific:
GETINTER(0.01, 24, 100, 0,0)
interest=1%
yearly #-months=24 bias=100$
each-month=0$ each-year=0$
102.010000
GETINTER(0.01, 24, 0, 10,30)
interest=1% yearly #-months=24 bias=0$ each-month=10$ each-year=30$
302.603514
SOLVEINTERM(102.01, 0.01, 100, 0, 0)
aim=102.01$
interest=1% yearly
bias=100$ each-month=0$ each-year=0$
23.5
+- -0.5 months to save for 102.01 $
23.500000
SOLVEINTERI(102.01, 24, 100, 0, 0)
aim=102.01$
#-months=24 bias=100$
each-month=0$ each-year=0$
estim.
interest to achieve 102.010000$ is 1.000 +- -0.000 %
0.00999737
Some physics specific:
Legendre polynomials (p0,p2,p4,
p1,p3),
Conversion between reduced electromagnetic transition probability
and a halflife of the level:
Bb2T12 Bw2T12 T122Bb
Conversion between reduced electromagnetic transition probabilities
in 3 different system units : efm <-> eb
<-> wu ... B2B
Conversion between time of flight and energy of neutron: tof2e e2tof
Use "help" command to learn how to use these functions.
See constants section for predefined physical constants.
Some others:
Yes, you can input the time (angle) and get it back.
Imagine, you wake up at 6 oclock and you go to sleep
at 10pm.
22:0-6:0
960.000000
:
16:00
960.000000
22:0:0-6:0:0
57600.000000
::
16:00:00
57600.000000
Other operations:
I didnot mention some stuff, that is implemented in perl
and
works also here in a natural way. Like modulo (50%40), less
or
greater (5>4 but who will use it?), bit shift operators
(8>>1),
binary or
(8|2) of binary and
(8&2) operators.
Arrows and backspace and delete.
Up and down arrows browse the history.
However, the keyboard doesnot have to always
correspond. For this case, there are also
classical keypresses
Ctrl-a, Ctrl-e (begin,end),
Ctrl-u,Ctrl-v (up,down),
Yes. If you end with three presses of enter, it writes the
history
to the $HOME/.calc.pl
Well, there is a field @functions=qw(...).
Add you function name there.
Then there is a part labeled with 'NO ARGUMENT - TRANSLATE
you can add your function following the examples. This is
for what happens if the function is issued without an argument.
And then simply write your subroutine in the manner as can be seen
in others. Something like sub E2TOF{ ... return $result;}
No. But
there is a nice piece of soft, mathomatic.
You download,
compile and you can call it from inside calc.pl
by issuing a command
"mat".
( may need some
libreadline.so.4 )