PC-CALCULATOR
Aimo Niemi, 1994-2008

INTRODUCTION
Pc-Calculator is a powerful scientific, programmable calculator with a full screen formula editor, nearly 50 Kb of working memory and 30 named registers to store constants and/or intermediate results. Trigonometric, logarithmic and user defined functions are supported.

The use of the calculator is easy. The working memory is like a piece of paper, which you can scroll back and forth and write your formulas just where you wish. You can also add explanatory comments and, if you want to execute a formula, you only need to move the cursor onto that line and press ENTER to see the result. It is then shown on the corresponding line in the answer window and, if you execute an other formula, you don't lose the previous one. All the results are shown and scrolling of the formulas scrolls the answers as well. This means that all possible errors are easily corrected, if needed, and fast recalculated.

FORMULA EDITOR
Most of the time, when you run Pc-Calculator, you are in the program's formula editor. It is like any other text editor with its own commands to scroll the text and move the cursor. The maximum file size the editor can handle is either 2000 lines or about 50000 bytes; the maximum length of a line is 2000 bytes. Available editing commands are:

Arrows: Move cursor to the direction of the arrow
Home: Move cursor to the beginning of the line
End: Move cursor to the end of the line
Del: Delete the character shown by the cursor
Back Space:Delete the character left to the cursor
Insert: Toggle between the insert and overwrite mode
Ctrl-right arrow:Move right to the next space
Ctrl-left arrow: Move left to the previous space
PgUp: Scroll the text one page back
PgDn: Scroll the text one page forward
Ctrl-z, Ctrl-s: Scroll the text one line forward
Ctrl-a, Ctrl-x: Scroll the text one line back
Ctrl-End : Go to the end of the text
Ctrl-Home: Go to the beginning of the text
Ctrl-PgUp: Scroll the text from the current position halfway to the beginning
Ctrl-PgDn: Scroll the text from the current position halfway to the end
Alt-c: Copy the line shown by the cursor
Alt-e: Toggle the function extensions on or off. If it is on then, for instance, sin x = sx = trigonometric sinus of x. If it is off, then sin x = s(i(n x)).
Alt-f: Find a string of text or numbers.
Ctrl-l: After find look for the next occurrence.
Ctrl-v: After find copy the find string to the current cursor position.
Alt-d: Delete the line shown by the cursor
Alt-i: Insert a new line above the cursor
Alt-n: Narrow the edit window. You may find this useful, if you want to run Pc-Calculator in a smaller window.
Alt-r: Show a list of the user defined short cuts and/or constants. A line is a short cut, if its first character is <. If there is a comment on the line, then the comment is also line's name.
F1: Show the help screen
F2: Change the colour scheme
F3: Select the line shown by the cursor. The line is then highlighted and can be moved with the arrow up or arrow down keys.
F5: £   (line reference prefix = pound sign)
F6: @  (temporary register sign)
F7: *   (the multiplication sign)
F8: ^   (rise to the power sign)
F10: Exit Basic Calculator
Ctrl-c: Exit Basic Calculator. Used, if F10 is not working.
TAB: Adds "a calculate total sign" to the beginning of the line and executes it. The value of the line is then added to register f.


FORMULA INTERPRETER
Each time the ENTER-key is pressed, the line shown by the cursor is executed and its value is put to the answer window and to the temporary register @. The line is then interpreted from left to right and standard arithmetic calculation rules are obeyed. If not otherwise shown with the parentheses, functions are calculated first, then powers (^), multiplications (*) or divisions (/) and last additions (+) or subtractions (-). The use of the multiplication sign is voluntary. So, for instance, xy=x*y and

c30^2(1+3) = c30*c30*4 = 3, (c=cos).
Except numbers and operators formulas can contain register names, named constants and references to other memory lines too. Capital letters A-Z, @ and small letters f,x,y and z are all available register names, which can be used to store constants and/or intermediate results. To put a value to a register an equal '=' or greater than '>' signs are used. For instance, line
A=100 B=456>x + 2A
puts 100 to register A, 456 to x and 656 to B.
Except registers, values can be stored to memory lines, too. If n is a line number, then the line function £ and the command
(expression)>£n
may be used to put a value to the beginning of the line n. Note that n may here be also a register or a result of some calculation as well. To put values to the temporary register @, there is still one possibility, a semicolon (;) which precedes its argument. Its main use is to transmit parameter values to the user defined functions. For instance, expression
z=u(x;y)
puts x to f and y to @, executes then line 2 and puts its value to the register z.


NAMED LINES
Named constants are actually named memory lines, where the constants are stored. Names are case sensitive and the syntax for a name is a colon (:) and a user defined name. In the name spaces and operators +-*/ and ^ are not allowed, small and capital letters, numbers and point (.) and underscore (_) are. See the examples below. There the names are Avogadro, Planck and Light_speed. The fourth line is an example, how a constant may be used in a formula.

 6.0225*10^23       :Avogadro number
 6.626068*10^-34  :Planck's constant m^2*kg/s
<299792.458         :Light_speed km/s

2q"Light - 100   =   995.06613

Names are used together with the quote function " and they can be shortened as far as the name remains unique. If two or more lines have the same name, then only the first one is valid. If you are using many constants, it is a good practice to put 'a less than' character (<) to the first column of the line. You can then use Alt-r command to see all the definitions, if you later want to check, what there is available.

QUOTE FUNCTION (")
Quote function is used to execute a named (or a quoted) line. Line's value is then put to the quote mark (") in the current formula. If the name is followed with a colon (:), then the editor shows the line, where the quoted name is. If the name is followed with the character #, then the line number of the quoted line is returned. If the name is followed with a semicolon, then the following expression, usually a number or a register, is put to the temporary register @ before the quoted line is executed. The syntax for the latter is:
"user_defined_name;(expression))
Note the closing parenthesis, if it is missing, the line number of the quoted line is returned. If you want to create your own functions, this is the way, how parameter values are transmitted to them.

LINE FUNCTION (£)
Function £ performs much the same way as the quote function above. Instead of the name £ uses a line number to show, which line is to be executed. Also the parameter transferring method is the same. So
£("user_defined_name#;(expression))
is equivalent to the quote function's syntax above. The main use of the line function, however, is to execute a block of lines. They can be executed either one by one or a loop may be created, which will execute them. These methods are discussed in a more detailed way in the chapter "Advanced programming technics".

USER DEFINED TWO PARAMETER FUNCTIONS
In the Pc Calculator memory lines 2-11 are reserved for the user defined two parameter functions. They can have any names you choose but the first four have also the default names u, w, j and d. So for instance, if line 2 has a name Line2, then the above example z=u(x;y) is equivalent to
z="Line2(x;y)
This expression, too, puts f=x and @=y, executes then line 2 and puts its value to the register z.
If not needed, one or both parameters may be omitted at wich the parentheses are also unnecessary. However, between the name and a parameter must be either a space or a quote to tell the program, where the name ends and where the parameter starts. For instance, following expressions are valid: z="Line2 x, z="Line2"x or z="Line2(x) but, however, the use of the last one is recommended.

Other key strokes and functions recognized by the formula interpreter are:

key meaningexamples
a trigonometric arc function as1=arcsin(1)=90
| absolute value |2=|(-2)=2
c cosine c60=c(--60)=0.5
e exp = e to power x e1=e(2-1)=2.718282
g convert sexagesimal to decimal g11 22 33.0 = 11.3758333
h convert hexadecimal to decimal hff = 255
o convert octal to decimal o101 = 65
b convert binary to decimal b101+b10.1 = 7.5
i integer i3.6 = 3, i(-4.1) = -5
l logarithm l100 = 2
n ln = natural logarithm ne1 = 1, n2 = 0.693147
p pi = 3.141592653589793 2pp = 19.7392088
q square root q2 = 1.414213562
k cube root k8 = 2
r reset registers f,x,y,z 0>f>x>y>z
r* reset all registers 0>x>X>A>B ...
rd random number 0 < rd < 1
s sinus s210 = -0.5
t tangent t45 = 1
^ rise to power xy^2 = xyy, 2^0.5 = q2,
sin x ^2 = (sin x)^2
\ mean value 1+2+3+4\ = 2.5
== logical operator "equal to" (x==x) = -1, (1==2) = 0
< logical operator "less than",
in the first colum = short cut prefix
(1 <2) = -1, (2 <1) = 0
£ line reference prefix £135, £x, £(5+2x)
# return the current line number £(#+1)£(#+2) meaning:
execute following two lines.
" named line reference prefix If a line has got a name, it can be executed by putting a quote (") before its name.
= set a value to a register x = 3.14, A = 2x+1
> store to 600>x>£x>£(22+x)
u store to f and insert line 2 ux = £(2+x>f0) meaning: put f=x and insert the value of the line 2.
w store to f and insert line 3 wx = £(3+x>f0)
j store to f and insert line 4 jx = £(4+x>f0)
d store to f and insert line 5 dx = £(5+x>f0)
; store to the register @. This is used in the function calls to give values to a parameter. 9;2-@ = 7  or  u(5;3) meaning:
put  f=5, @=3  and insert the value of the line 2.
? Print the result of the formula to the end of the line.
?g Print a desimal number in the sexagesimal form 11.3758333 ?g= 11 22 33.0
?h Print decimal in hexadesimal 255 ?h = FF
?o Print decimal in octal 255 ?o =377
?b Print decimal in binary 25.5 ?b =11001.1
' Comment follows
: Comment or a line name follows. In the beginning of the first line the working memory is not saved on the exit with F10.
TAB Executes a line and adds its value to the register f.


Note that usually the function definition precedes its argument. The only exceptions are: \ > ! ^ and ? Notice also that an audible warning signal is given, if the interpreter finds an error, like q(-1) or q(1, for instance.

LONG NUMBERS
If the accuracy of the program is not enough, the basic calculations with the long numbers can still be made. Write the numbers to the adjacent lines, put the operator before the lower number and press ctrl+enter. The result is then inserted to the next line. For instance, write
123456789123456789.000 000 000
/987654321 'and pres CTRL+ENTER here to get
=124 999 998.985 937 498

'or calculate with the whole numbers to get the remainder, if any
123456789123456789
/987654321
=124999998 :973765431
or
q2.000 000 000 000 000 000 000'  press CTRL+ENTER here
=1.414 213 562 373 095 048 8016
With the same technics functions q, k, s, c, t, as, ac, at, n, e, !, p(=pi ) and f (=factor) can be calculated, too. For instance:
f1234567890121           'press CTRL+ENTER here ..
f33366699733*37*1      'and here again ..
f174694763*191*37*1
f32309*5407*191*37*1
32309*5407*191*37*1   'No more factors


ADVANCED PROGRAMMING TECHNIQUES
Although the aim of the Pc-Calculator is not to compete with other high level programming languages, it is in the principle, however, capable to solve rather complicated problems too. Following short examples shows how program loops or program branching can be created:
1>f£244                   'Begin loop  (line 243)
@*f>f+£(244-(@<3);(@-1))  'Loop        (line 244)
0                         'End of loop (line 245)
£(243;9)                  'calculate 9!(=362880)
The example defines the factorial function n! (=1*2*...*(n-1)*n ), which takes its parameter n from the register @. The execution starts from the line 243, where a starting value 1 is stored to register f. On the line 244 term @*f calculates the factorial and intermediate results are stored to f. Then the line reference £(244-(@<3);(@-1)) follows, which is the main point of this example. If @>=3, then (@<3)=0 (not true) and the reference is made to the same line. No value is put to £, instead the execution of the line starts from the beginning again. Before that, however, term ";(@-1)" stores @-1 to register @, which in the loop gradually decreases and is finally <3. When this happens, (@<3)=-1 (true) and the reference goes to the line 245. Its value, zero, is put to £ on the line 244 and the result of that line to £ on the line 243, which ends the execution.

Although elegant, this method, however, is not practical in the use because it uses absolute line numbers, which may easily change, if or when the memory is edited. A better method is to use the function # and a symbolic memory addressing. Function # returns allways that line number, where it is situated and so the term £(#+1) on that line executes the line that follows. A second solution to the above example is given below. It can now be anywhere in the memory, it uses also register x and may be easier to understand.
f=1 x=@ @=£(#+1)       :factorial
f=xf x=x-1 @=£(#-x==1) 'loop
f                      'End
"factor;9)             'calculate 9!
Note that the factorial function is one of the Pc-Calculator's standard funtions. So there is no need to redefine it by the user. Note also, if you accidentally create a never ending loop, like y=£#, or if your loop is too slow, press F10 to get rid of it.

To execute a block of lines there is no specific means in the Pc-Calculator. Instead the line reference method can be used but then there must be a reference to every line you want to execute. For instance, to execute following four lines you can simply execute £(#+1)£(#+2)£(#+3)£(#+4) and so on. However, if the block is large, this may not be handy. A better method then is to create a loop, which executes the block. Below is an example how this can be made.
 @>A z=1 @=£(#+1):loop_name   'Loop begins, store parameters here
 z=z+1 @=£(#+z)+£(#-(z==12))  'execute following 12 lines
 )                            'beep when loop ends
 .....                        'program starts
Even a better way is to create a function, which makes the work. See the examples below and there the function execute_lines.

EXAMPLES
Following examples show some ways to create and use loops within the Pc-Calculator.

':EXAMPLES BEGIN                                 (line 1)
'Reserved to user function  u()                  (line 2)
'Reserved to other two parameter                 (line 3)
'....                                             .....
'user defined functions                          (line 10)
å=@ f=f+å @=£(#+1):execute_lines(start;length)   (line 11)
å=å-1 @=£(f-å) @=£(#-å<1)                        (line 12)
'Note above the use of the foreign character register å.
'It can be changed to any available register, if needed.
'Note also that register f is used here. So it may not be
'used in the lines, which the above loop executes. If that
'is not possible, change f to an other foreign character.
'ä, ö, ë and ü are still available.

'HYPERBOLIC FUNCTIONS
(e@-e(-@))/2           :sinh(@)
(e@+e(-@))/2           :cosh(@)
(e@-e(-@))/(e@+e(-@))  :tanh(@)
(e@+e(-@))/(e@-e(-@))  :coth(@)
n(@+q(@@+1))           :arsinh(@)
n((1+@)/(1-@))/2       :artanh(@)

'Examples
"sinh;1,4)^2 - "cosh;1.4)^2 ?d'= -1


'DATE OF THE EASTER SUNDAY  y=year, x=month, f=day
'User defined function "execute_lines(start;length)
'executes here the following 11 lines. Note that here
'the use of reg.f is allowed only on the last line.

y=@ @="execute_lines(#,11) :easter_sunday;year)
(y-100(i(y/100)>D))>A'
(A-4i(A/4))>B
(y-19i(y/19))>C
i(D/4)>E
i((D-15)/25)>F
i((D-F)/3)>G
((19C+D+15-E-G)>K-30i(K/30))>K
((18+2D-E+2B+4A-K)>L-7i(L/7))>L
(((K+L)>J+7(34<J))>J+22+7(J==34)(K==28)(10<C))>J
(3-(31<J)-(61<J))>x
(J+31(31<J)+30(61<J))>f

'Example
"easter;2009

 ' Random.number.Pi
 ' This example calculates the value of the pi using
 ' random numbers to simulate the well known match
 ' dropping method. See the picture.
 ' It also demonstrates the use of two nested loops.
 ' When the inner loop is completed an intermediate value
 ' of pi is calculated and after that the outer loop starts
 ' the process again. This makes it possible to follow the
 ' progress as the screen is automatically refreshed
 ' after every 1000 loops.

 f=360 z=0 T=1000 V=#+3 @=£(#+1) :rd.n.pi
 z=z+1 W=1000 y=2(A+B)/A x=y-p @=£(#+1) @=£(#-z==T)
 @=£V @=£(V+1<W)
 W=W-1 C=rd+s(rdf) A=A-(C<0)-(1<C) B=B+(C<1)(0<C)

'Example
"rd.n.pi 'Start the counting, press F1 to get rid of it.


A Worked Example of calculator's advanced properties is also available at
On a ray tracing method to calculate atmospheric refraction


  USING THE CLIPBOARD
Although Pc-Calculator is a non-Windows application, it still can use Windows' clipboard. Click the programs title bar with the right mouse button or press ALT+SPACEBAR to open programs control menu. From the menu select Edit and then Mark or Paste. With Mark you can drag the mouse pointer across the information you want to copy. However, you can not scroll the memory, you can only copy what is visible on the screen. With Paste the text in the clipboard is pasted to calculators working memory, one character in the time, as if you were typing it. This means that new lines are not inserted to the memory, instead they are inserted to the beginning of the old memory lines. The animation on the right shows the procedure.
(If the animation does not start, try to refresh the page)
Picture
Copyright
Pc-Calculator is released as freeware though on exit it asks you to make a donation to UNICEF. If you find this annoying, put ': to the beginning of its formula memory and become a honorable user by making your donation as asked.
Miscellaneous
  • The default working file of the Pc-Calculator is Pcalc.fml. If you like, you can edit it with your favorite text editor.
  • Except the default, you can give a different working file as a parameter when you start the program. You can also start by dropping the icon of a text file over the program's icon.
  • Onward version 3.33 it is possible to copy memory lines by writing a line reference £n to the beginning of a line and pressing CTRL+ENTER. Line n is then copied above that line.
  • In the long number mode the number of the decimals in the answer depends of the number of the decimals of the operands. If whole numbers are divided, then no decimals are calculated, instead the remainder of the division is given.
  • To make long numbers more readable spaces can be inserted to any place in the number. The decimal point again can be either dot or comma. If both or many points are used, then only the first one matters, the others are omitted.
  • The length of the program is about 110 Kb and the size of its screenshot image is about 100-400 Kb, if packed to JPG format. The writer of the program is proud being able to announce that.
  • If you like Pc-Calculator, you are wellcome to add a link to its homege to help Google to find it.
     Load Pc-Calculator
     Home
   Get Pc-Calculator at SourceForge.net. Fast, secure and Free Open Source software downloads   web hit counter