Calculator Magic #1:
Introduction


Programming a Four-Function Calculator

Powers, roots, compound interest, trigonometry, logarithms — all things are possible even on the simplest of units, if you know how.  One could simply purchase a scientific calculator from Hewlett-Packard or Texas Instruments; or else you could enjoy mastering the power of the $4 solar unit that you received in your Christmas stocking or as an advertising promotion.  The results will be perfectly useful, and you can amaze your friends and win bar-room bets in the process.

This discussion covers only features that apply to my related pages on specialized calculator application.  Extensive use is made of the Memory and Constant features, but usage of the Percent function isn't covered at all.


ABOUT THE LOGIC CHIP

Important: There are two basic types of of calculator logic:

Just as important:  There are two types of algebraic logic: Casio, and all others.  Many retailers such as Radio Shack market units with their own logos, but which are manufactured by other companies.  If you are not sure of your brand, then perform the following test:

Enter  2 × 3 =.  The display will show a {6}.  Now, without clearing, enter 4 =.  If the display shows a {4}, then you have a Casio-made unit; others will read {8} in the display.

Note: Some newer cheapo Casio units don't behave like their predecessors, choosing instead to emulate their inferior competition.  This disappoints me greatly, but more importantly, you need to run the test even on Casio calculators.


USING THE CONSTANT (K)

Every pocket calculator has a built-in constant feature, meaning that you can establish a fixed multiplier or divisor to save steps in repetitive calculations.  Although I am a strong detractor of substituting 'K' for 'C' in general (names such as "Kalico Kitchen" and "Krispy Kreme" turn my stomach), but it has a valuable usage for us programmers.  Henceforth, this function will be designated as Konstant — or perhaps simply K, so as to differentiate from the algebraic meaning of 'constant'.  In keeping with this protocol, Casio units display a 'K' when Konstant mode is initialized.

The following example sets a Konstant value of 2 in order to double a series of numbers:

Non-Casio:

Casio models: the Konstant is initialized by a double entry of the arithmetic operator:

The Casio protocol may seem somewhat tedious, but it has certain advantages. For example, Konstants for addition (++) and subtraction (−−) can be set up in the same manner; other brands cannot do this at all:

When using Konstant mode, it can be useful to think of the mnemonic aids — or even mouth them — during a calculation; it may help you to keep track of what you are doing.

Important:  In order to accommodate all types of calculators in program code, the multiplication constant will be denoted as a generic  ×(×).  Non-Casio users do not enter the second  (×).

Equally important:  Some Casios behave differently than others in Konstant mode, regarding their treatment of the  M+  and  M−  keys.  Run this test:

Enter  4 ×× M+ =

If the display shows a  64, then you have an "active" model, which allows the usage of  M+  and  M−  without disrupting the Konstant series.  42  will be in memory, and  43  is the active number.  In other words, pressing  M+  includes the function of an equal sign, squaring the number as it is copied to memory.

If the display show a  16, then you have a "passive" model, which allows  M+  and  M−  to cancel Konstant mode.  Pressing  M+  placed  42  into memory all right, but the equal sign did nothing.  Passive Casios and other brands need to use an extra equal sign in the code sequence:  4 ×(×) = M+ =

Note: "Active" units save one keystroke per loop of this type, and this savings is not optional.  Remember that the memory key serves double duty; entering the extra equal sign would add an unwanted increment to the exponent in this particular calculation.


TAKING A RECIPROCAL

Reciprocals also are handled differently by the two types of logic.  If the display shows  {8.7}  and you wish to take its reciprocal, 1/8.7:

Dividing the {display} into another number is slightly different.  Example: divide  {17}  into  3:


ABOUT MEMORY

Your calculator might have only a 3-key memory setup; that is, it will have a dual-function  MRC  button. One keypress recalls the memory, and a second keypress clears it.  A 4-key setup is preferable, as it can be useful to be able to clear the memory and re-use it during a calculation.  We'll just have to work around that limitation with the following generic protocol:

A final note: many online arithmetic calculators — even some on purported instructional sites — do not feature a Konstant mode.  These are careless omissions by the programmers, as the utilities are thereby crippled.  Those units are unsuitable for our purposes.  If you are running Microsoft Windows, then you can use the good calculator utility supplied with the operating system.  I have no familiarity with the offerings of other PC operating systems.

programming a four-function calculator
mathematical recreations
powers and roots
trigonometry
logarithms
compound interest
square root