News: 061107 version released - goniometric bug fixed (above 90 deg), possibility to use decimal comma, few fancy features added (automatic terminal-tab name, saving history on Ctrl-C, better help)
Soon: fields => spreadsheet functions (statistics, operations...)
Why another calculator?
What are the requirements?
How to install?

So, how it operates?
Advanced functions, goniometric, logarithms?
Variables?
Constants?
Some number's crunching - DEFAULT OPERATIONS?
Special functions?
Fancy time (angle) interpretation or other operations?
Prompt editing?

Does it write to disk?
I want to add my own function. How?
Can it solve equations?

Download.

Q: Why another calculator?


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:



If you prefer to use a keyboard rather then a mouse and
if you use frequently the terminal, you need to input
formulae, repeat one operation - here
is something for you.


Q: What are the requirements?

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.


Q: How to install?

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.


Q: So, how it operates?

Suppose you have a calc.pl prompt.

4+5
         9.000000
*8
         72.000000
/12
         6.000000
**2
         36.000000
sqrt
         6.000000

Lets benefit from perl treatment of brackets and
two equivalent symbols for power - let's continue with:

/( 2**2 +3^3 - 3 -26)
         3.000000


Q: No surprises... some advanced functions, goniometric, logarithms?

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


And a logarithm of 10 and a natural one, e, pi.
Number in exponential form must have uppercase E like
1E+3=1000:


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.


Q: Ok, so it is a calculator, where you refer to the last number.


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

If you want to input a negative number, do it with the space before it.
Else you just did a substaction, and you are warned about it.

From experince - pay attention to the warnings.


Q: Ok, I am warned abou it. What else, does it have variables?

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


Q: Does it have some predefined variables - constants?

Yes.

e=2.71828182845904523536
pi=3.141592653589


hbar=6.581E-22 MeV s
ev=1.602E-19 Coulomb (electron charge)
hbarc=197 MeV fm

But also constants, that drive the display:

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.


Q: What about some crunching numbers - so called default operations?

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

The last operation means that you add not +5 but
the last_result+5. (3+5) + 3 =11. Operations are permited.
Just clear it with an empty enter.



2nd mode: +++num (or --- or *** or ///). Each number
you enter will be added (substracted, multiplied, divided)
to/by the number num.

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
---------------------------------

I repeat, always clear the DO after using, else you forget.


Q: Does it have some special functions?

Some financial specific:

 You want to find how much you will have after 24 months when the interest is 1%
and you put 100 bucks in the begining.


GETINTER(0.01, 24, 100, 0,0)
interest=1% yearly   #-months=24  bias=100$  each-month=0$  each-year=0$
                             102.010000

You can play with puting money each month and at the end of each year. 0$ in 
the begining, 10$ monthly, 30$ yearly. You  will have 302$ at the end.


GETINTER(0.01, 24, 0, 10,30)
interest=1% yearly   #-months=24  bias=0$  each-month=10$  each-year=30$
                             302.603514

 You want to find how long (how many months)  will it take to save 102.01 bucks
 when the interest is 1%. (You can again play with monthly savings and annual savings.) 


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

 You want to find what interest rate must be to save 102.01 bucks in 24 months.
 (You can again play with monthly savings and annual saings.) 


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:

Look just to the next section first.
The calc.pl contains just functions, I needed up to now. If you want some other, 
       

Q: Does it have some special conversions - say time?

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

You were up 16 hours or 960 minutes.

22:0:0-6:0:0
         57600.000000
::
         16:00:00
         57600.000000

More correctly, it was 57600 seconds.

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.

All strings (letters) are understood as variables. You cannot use
exec,system,unlink,open,close,delete,file,sub,char,ord,*_* as the
names of variables for the moment.

Q: What are the commands to edit the line?

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),

Ctrl-d (delete)

Q: Does it write to disk?

Yes. If you end with three presses of enter, it writes the history
to the $HOME/.calc.pl


Q: I want to add my own function. How?

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;}


Q: Can it solve equations?

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 )



Download.

If you have any suggestions (that meet my thinking direction),
or you found bugs  - contact me.
mirozbiro
at
seznam.cz


http://www.tucnak.webz.cz/calc.pl.gz
copyright 2005,2006 the program is released under GNU GPL.


WebZdarma.cz