Calculator Magic #1: Introduction |

Programming a Four-Function Calculator

Powers, roots, compound interest, trigonometry, logarithms — all these
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 barroom 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, it being ~~self-explanatory.~~

ABOUT THE LOGIC CHIP

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

**Arithmetic**: these models emulate the older electric and manual units. A number is entered, then an operator. For example,~~11 - 4~~. The entry is. For`11 + 4 -`~~17 ÷ 3~~, the entry is~~17 + 3 ÷~~. These units sometimes have a paper-printing capability; but they are designed for account clerks, not for scientists such as ourselves.

**Algebraic**: this is the type you want. Most modern calculators, including solar units, support this logic. Calculations are entered just as you would write or say them. For~~11 - 4~~, the entry is~~11 - 4 =~~. For~~17 ÷ 3~~, the entry is~~17 ÷ 3 =~~.

**Just as important**: There are two types of algebraic logic:
and **Casio-style**,**virtually 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's origin, 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 your unit has ~~Casio-style~~
logic; others will read *{8}* in the display.

*Note:* Some newer cheapo Casios don't behave like their predecessors,
choosing instead to emulate their inferior competition. This disappoints me;
but more importantly, you need to run the test no matter what.

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 application
for us programmers. Henceforth, this function will be designated as
or perhaps simply **Konstant** —**K**, so as to differentiate
from the algebraic meaning of 'constant'. In keeping with this protocol,
Casio units display a '**K**' when the Konstant mode is activated.

The following examples set a Konstant value of 2 in order to double a series of numbers:

Non-Casio:

- K-Multiplier:
`2 × 3 =`*{6}*;`4 =`*{8}*;`3.14 =`*{6.28}*

`2 ×`sets the Konstant. Following with`3 =`completes a calculation, and the display shows a*{6}*.

Now, in order to multiply`2 × 4`, the unit remembers the~~2 ×~~, so you need only enterYou may continue indefinitely:`4 =`*{8}*.`5.3 =`*{10.6}*;`.07 =`*{.14}*, etc.

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

- K-Multiplier:
`2 × × 3 =`*{6}*;`4 =`*{8}*;`3.14 =`*{6.28}*

Think of (`××`) as "multiplied by". - K-Divisor — enter the
**divisor first**:`5 ÷ ÷ 2 =`*{.4}*;`18 =`*{3.6}*;`98.6 =`*{17.2}*

Think of (`÷÷`) as "divided into".

Konstant mode also is available for the other three arithmetic operators, as follows.

Non-Casio:

- K-Divisor:
`2 ÷ 5 =`*{.4}*;`18 =`*{3.6}*;`98.6 =`*{17.2}*

In this case the divisor, or second term, becomes the constant value. - K-Addend:
`5 + 7 =`*{12}*;`84 =`*{91}*;`.55 =`*{7.55}*.

The second term is the constant. - K-Subtrahend:
`13 - 4 =`*{9}*;`32 =`*{28}*.

The second term is the contant.

Casio:

- K-Divisor — enter the
**divisor first**:`5 ÷ ÷ 2 =`*{.4}*;`18 =`*{3.6}*;`98.6 =`*{17.2}*

Think of (`÷÷`) as "divided into". - K-Addend:
`7 + + 5 =`*{12}*;`84 =`*{91}*;`.55 =`*{7.55}*.

Think of (`++`) as "added to". - K-Subtrahend:
`4 - - 13 =`*{9}*;`32 =`*{28}*.

Think of (`--`) as "subtracted from".

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. Note also that
the Casio setup is somewhat more intuitive, in that the Konstant value
always is entered first.

**Important**: In order to accommodate all types of calculators
in program code, the multiplication constant will be denoted as a generic
`×(×)`. Only Casio users will enter the second
`'×'`.

**Equally important:** Some Casios behave differently from
others in Konstant mode, regarding their treatment of the `M+`
and `M-` keys. After clearing anything in memory, 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.
*4 ^{2}* will be in memory, and

If the display shows a *16*, then you have a "passive"
model, which allows `M+` and `M-` to cancel Konstant
mode. Pressing `M+` placed *4 ^{2}* 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:

Note: "Active" units save one keystroke on each 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*:

- Casio:
*{8.7}*`÷ ÷ 1 =`*{.1149..}*You also can use:*{8.7}*`÷ ÷ = =`. - Other:
*{8.7}*`÷ =`*{.1149..}*Or else, if the unit has a**reciprocal**`[1/x]`key, just press it.

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

- Casio:
*{17}*`÷ ÷ 3 =`Normal division of one number into another. - Other:
*{17}*`÷ 3 ÷ =`Do an 'upside-down' division, then take the reciprocal.

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, because it is useful to be able
to clear the memory and ~~re-use~~ it during a calculation.
One works around that limitation with the following generic protocol:

`MR`recall the memory (one press of`MRC`)`MC`clear the memory (two presses of`MRC`)

*A final note*: many online arithmetic calculators —
even some on purportedly instructional ~~sites —~~ do not
feature a Konstant mode. That careless omission cripples the utility's
functionality, rendering all such sites unsuitable for our purposes. If you are
running Microsoft Windows, then you can use its excellent calculator utility.
I have no familiarity with the offerings of other PC operating systems.