Calculator

Author: Dale Anson
Version: 1.1.5

Introduction

This plugin provides an RPN calculator. It has these features:

Usage

If you haven't used an RPN calculator before, you're in for a pleasant surprise. It's actually a much faster and more accurate way of doing math on a calculator. Following is a brief introduction:

This calculator is more or less modeled after the HP-35 that I paid several hundred dollars for in the mid-1970's. Like the HP-35, this calculator uses a 4 register stack, allows 'rolling' of the stack in either direction, and swapping of the X and Y registers. The registers are named X, Y, Z, and T (T for Top). When you enter your first number, it will be in the X register. Math is done backwards, that is, you put in the numbers first, then do the operation. Let's go through the steps to add 4 and 5:

  1. Click the 4. It will appear in the X register.
  2. Click the 'Enter' button. This will copy the 4 to the Y register, and highlight the 4 in the X register.
  3. Click the 5. This will erase the 4 in the X register and replace it with the 5.
  4. Click the '+' button. Both the 4 and 5 will be erased and a 9 will be in the X register.

Let's go through a slightly more difficult example. Find the area of a circle with radius 12:

  1. Click 1 then 2 to make 12 appear in the X register.
  2. Click the 'Enter' button. This will copy the 12 to the Y register, and highlight the 12 in the X register.
  3. Click the 'x' (multiplication) button. Since 12 was in both the X and Y register, 12 squared will be placed into the X register.
  4. Click the 'Enter' button to move the 144 to the Y register.
  5. Click the π (pi) button.
  6. Click the 'x' (multiplication) button. The area of the circle is now in the X register.
One of the benefits of an RPN calculator versus an algebraic calculator is that you will use no more keystrokes, and will likely use quite a few less. For the above examples, to calculate 4 + 5, you'd use these keystrokes:
4
Enter
5
+

For an algebraic calculator, you'd use these:
4
+
5
=

So you'd use the same number of keystrokes either way. For the second example, you'd use:
12
Enter
*
Enter
π
*
for a total of 7 keystrokes (the 12 counts as two) and on an algebraic calculator:
12
x
12
*
π
=
for a total of 8.

Operational Modes

The calculator supports BigDecimal, Float, BigInteger, and Integer modes. BigDecimal and Float work with base 10 floating point and integer numbers, BigInteger and Integer modes work with base 16, 10, 8, and base 2 integer numbers. The default mode is Float with base 10 numbers.

Float mode is the standard mode and is the mode that is commonly found on most calculators.

Integer mode is common on calculators for programmers, and allows standard boolean and mod operations as well as the regular math operations. This mode also can convert numbers between the different bases.

BigDecimal and BigInteger modes allow arbitrarily large numbers to be used. Using these modes can take quite a bit of processing power and can make your computer appear to hang. These modes can let you calculate things like 999999 =
368063488259223267894700840060521865838338232037353204655959621437025609
300472231530103873614505175218691345257589896391130393189447969771645832
382192366076536631132001776175977932178658703660778465765811830827876982
014124022948671975678131724958064427949902810498973271030787716781467419
524180040734398996952930832508934116945966120176735120823151959779536852
290090377452502236990839453416790640456116471139751546750048602189291028
640970574762600185950226138244530187489211615864021135312077912018844630
780307462205252807737757672094320692373101032517459518497524015120165166
724189816766397247824175394802028228160027100623998873667435799073054618
906855460488351426611310634023489044291860510352301912426608488807462312
126590206830413782664554260411266378866626653755763627796569082931785645
600816236891168141774993267488171702172191072731069216881668294625679492
696148976999868715671440874206427212056717373099639711168901197440416590
226524192782842896415414611688187391232048327738965820265934093108172054
875188246591760877131657895633586576611857277011782497943522945011248430
439201297015119468730712364007639373910811953430309476832453230123996750
235710787086641070310288725389595138936784715274150426495416196669832679
980253436807864187160054589045664027158817958549374490512399055448819148
487049363674611664609890030088549591992466360050042566270348330911795487
647045949301286614658650071299695652245266080672989921799342509291635330
827874264789587306974472327718704306352445925996155619153783913237212716
010410294999877569745287353422903443387562746452522860420416689019732913
798073773281533570910205207767157128174184873357050830752777900041943256
738499067821488421053870869022738698816059810579221002560882999884763252
161747566893835178558961142349304466506402373556318707175710866983035313
122068321102457824112014969387225476259342872866363550383840720010832906
695360553556647545295849966279980830561242960013654529514995113584909050
813015198928283202189194615501403435553060147713139766323195743324848047
347575473228198492343231496580885057330510949058490527738662697480293583
612233134502078182014347192522391449087738579081585795613547198599661273
567662441490401862839817822686573112998663038868314974259766039340894024
308383451039874674061160538242392803580758232755749310843694194787991556
647907091849600704712003371103926967137408125713631396699343733288014254
084819379380555174777020843568689927348949484201042595271932630685747613
835385434424807024615161848223715989797178155169951121052285149157137697
718850449708843330475301440373094611119631361702936342263219382793996895
988331701890693689862459020775599439506870005130750427949747071390095256
759203426671803377068109744629909769176319526837824364926844730545524646
494321826241925107158040561607706364484910978348669388142016838792902926
158979355432483611517588605967745393958061959024834251565197963477521095
821435651996730128376734574843289089682710350244222290017891280419782767
803785277960834729869249991658417000499998999

or 123! (factorial of 123) =

121463043670253296757662432418812958554542170884833823153289181618292358
923621676688311569606126402021707358352212940477825910915704116514721860
29519906261646730733907419814952960000000000000000000000000000

which are not the kind of things you can usually do with a calculator. Most calculators will give you an 'overflow' error or 'infinity' or even '0' as the answer to these. Not all functions are available in these modes, and those functions that aren't available really don't make sense in these modes anyway (I can't think of any reason to calculate the sine of 123!).

For example, you can calculate the volume (V) and surface area (S) of the earth in cubic inches:
S = 4 Pi r2 = Pi d2
V = (4 Pi/3)r3 = (Pi/6)d3
diameter of Earth is 7,926.41 miles = 502217337.60 inches
Surface Area = 792379580822696720.58 square inches
Volume = 66324460574896460777635018.14 cubic inches
Using a regular calculator would give a volume like 6.632446057E25, which, while correct, does not give a lot of accuracy.

Constant Values

This calculator provides several hundred built-in constants for your use. The list of constants and their values are from 'Fundamental Physical Constants' from the National Institute of Standards and Technology:

             Fundamental Physical Constants --- Complete Listing


  From:  http://physics.nist.gov/constants

Source: Peter J. Mohr and Barry N. Taylor, CODATA Recommended Values of the 
        Fundamental Physical Constants: 2002,
        To be published.

You can access the constants via the 'Constants' menu, then follow the 'Constants...' menu item to see a list of all available constants. You can use them directly, add some to the 'Constants' menu for quicker access to those you use regularly, or make new constants that you might need.

Programmable (Recordable) Functions

While the calculator provides a number of built-in functions, you can record or create your own as you might need.

To record a function, click the "Function" menu, then "Record". The calculator will work as normal, with the addition that the X, Y, Z, and T beside the stack registers are now active. I tend to work best with an example, so here is how you would create a function to calculate the area of a circle given the radius. The formula is πr2.

  1. Click the "Function" menu, then "Record".
  2. Click a number, 0 through 9, it doesn't matter which one. This is the radius to be used in the formula.
  3. Click the "X" button beside the X register. This means that the number you entered in the X register won't be recorded, instead, any number in the X register will be used in your function.
  4. Click the "Enter" button. Now your number is in both the X and Y registers.
  5. Click the "x" (multiplication) button. This squares the radius.
  6. Click the "Enter" button.
  7. Click the "π" button.
  8. Click the "x" (multiplication) button. This completes the formula.
  9. Click the "Function" menu, then "Stop recording".
  10. Follow the prompts to save your function. The name for the function will appear in the function menu, and the description will be the tool tip for the function. Both the name and the description can contain html to make your menu item look nice. For this function, you might use "<html>&#960;r<sup>2</sup>" as the name for the function, which would then appear on the Function menu as πr2. Be sure to put the <html> at the start of the name or the html code will be displayed.

When recording your functions, nearly all of the calculator buttons can be used, including the Clear, All Clear, Roll Up, Roll Down, Swap X and Y, and Last X buttons. You can also use any function that you already have recorded. In this next example, you use the function created in the previous example to record a function to calculate the volume of a cylinder. The formula is πr2h. Since this formula takes two variables, r and h, we'll set up the recording a bit differently than before.

  1. Click a number, it doesn't matter which one. This will be the height of the cylinder. Click the "Enter" button to move it to the Y register.
  2. Click another number, this will be the radius of the cylinder.
  3. Click the "Function" menu, then "Record".
  4. Click the "X" button beside the X register. This means that the number you entered in the X register won't be recorded, instead, any number in the X register will be used in your function. This step really isn't necessary, since we put the radius in before we started recording.
  5. Click the "Function" menu, then click the "πr2" function that you recorded in the previous example.
  6. Click the "x" (multiplication) button.
  7. Click the "Function" menu, then "Stop recording".
  8. Follow the prompts to save your function. In the description, you might enter something like "Volume of a cylinder, X is radius, Y is height".

Once you've saved a function, you can delete it or edit it by choosing the "Edit Function..." menu item. The editor window lets you make changes to the name and description (you can even preview how your menu item will look if you use html mark up as in the above examples) and you can edit the function steps directly. Below are the function steps for the πr2 function recorded in the example above:

x
enter
*
enter
pi
*

The recorded function is pretty much just a step-by-step listing of the keys as you pressed them during the recording process. One added benefit of editing by hand is that you can add comments to your function to help explain what it is doing. Comment lines start with a #.

The table below shows the name of the built-in functions to use (these are what are recorded) and the corresponding calculator button (this is the key you clicked).

These functions take no parameters
Function Button Description
randomrandomGenerate a random number between 0 and 1
The integer value that is closest to x
These functions take one parameter
Function Button Description
expexe (the base of the natural logrithm) raised to the x power.
acosacosThe arc cosine of x
asinasinThe arc sine of x
atanatanThe arc tangent of x
loglnThe natural logrithm of x
coscosThe cosine of x
sinsinThe sine of x
tantanThe tangent of x
ceilceilThe smallest value that is not less than x and is an integer
floorfloorThe largest value that is not greater than x and is an integer
rintrintThe integer value that is closest to x
roundround
sqrtThe square root of x
toDegreesdegConverts the value in x from radians to degrees
toRadiansradConverts the value in x from degrees to radians
factorialx!The factorial of x

These functions take two parameters
Function Button Description
atan2atan2Converts rectangular coordinates (x, y) into polar coordinates (r, theta)
maxmaxThe larger of x and y
minminThe smaller of x and y
powyxy raised to the x power

These are the stack control commands
Function Button Description
clrCClear the x register
acACClear all the registers
ruR↑Roll the registers up
rdR↓Roll the registers down
xyX↔YSwap the x and y registers
lstxLstXRecall the last x value and put it in the x register

These are the operators
Function Button Description
++Add x and y
--Subtract x from y
*xMultiply x and y
/÷Divide y by x
\\y mod x
and&y and x
or|y or x
xor^y xor x
not~y not x
chs±Change the sign of the x register

These are the register labels
Function Button Description
xXFor recording, represents the x register
yYFor recording, represents the y register
zZFor recording, represents the z register
tTFor recording, represents the t register

π and e
Function Button Description
piπpi, the ratio of the circumference of a circle to its diameter
eulereEuler's e, the base of the natural logrithm.

Managing Functions

You can manage your functions by using the "Function" menu, then selecting the "Functions..." menu item. From here, you can see all available functions, add or remove functions from from the Functions menu, edit functions, and delete functions.