functions.htmlTEXThbwr>L@@o Writing Functions Writing Functions

The items in the Functions menu correspond to text files contained in the 'PCalc Functions' folder. You can write your own and add them to the menu by placing text files with functions in them into the folder. Items in subfolders will appear as hierarchical menus.

You don't have to know anything about this to use the calculator but it's there under the surface if you are interested. Quite a few functions are already defined for you and they might be all you need. Open any of the existing files with your favourite text-editor and take a look if you want to know how they work.

If a function only makes sense in a certain mode, it is a good idea to prefix the rest of the definition with a 'dec', 'hex' or 'bin' so the calculator will automatically switch mode. For example 'set x 42' when in hex mode sets the display to the hex value 0x42, not to forty-two.

Please mail me any functions you write that you think would be useful to others and I will include them with the next version, credited to you.

Commands

Here is a list of the commands you can use in the function files, where 'x' is the name of any register and 'y' is the name of any register or an actual value.

To add comments to a file, put two slashes and a space at the start of a line and it will be ignored.

// Function to add UK VAT
// Written by James Thomson
dec
mul x 1.175

Command Action
set x y x = y
clr x x = 0
add x y x = x + y
sub x y x = x - y
mul x y x = x * y
div x y x = x / y
pwr x y x = x to the power of y
neg x x = -x
inv x x = 1/x
trn x truncate x to integer
rnd x round x to nearest integer
fac x x = factorial of x
exp x x = e to the power of x
log x x = log base 10 of x
ln x x = natural log of x
sin x x = sine x
cos x x = cosine x
tan x x = tangent x
asn x x = inverse sine x
acs x x = inverse cosine x
atn x x = inverse tangent x
+ value shortcut add that works on main register
- value shortcut subtract that works on main register
* value shortcut multiply that works on main register
/ value shortcut divide that works on main register
= x y sets x to 1 if x = y, to 0 otherwise
> x y sets x to 1 if x > y, to 0 otherwise
< x y sets x to 1 if x < y, to 0 otherwise
>= x y sets x to 1 if x >= y, to 0 otherwise
<= x y sets x to 1 if x <= y, to 0 otherwise
dec change mode to decimal
hex change mode to hexadecimal
bin change mode to binary
deg change angle measurement to degrees
rad change angle measurement to radians
and x y x = bitwise and of x and y
or x y x = bitwise or of x and y
xor x y x = bitwise xor of x and y
not x y x = bitwise not of x

Register Names

x : main register
m : memory
y : second memory
r1, r2, ...rF : sixteen registers for storing intermediate results

Constants

PI : value of pi 2 2~L2styl