Version of Saturday 31 October 2015.
Dave Barber's other pages.
This is a simple postfix calculator for complex numbers. Implemented in JavaScript, it stores numbers in a stack, with the eight most recent entries visible in the display. Because of the stack configuration, there is no need to store information about pending operations. Further, parentheses and the equal button are omitted; instead are enter (or push in stack parlance) and pop buttons. This postfix syntax is also called reverse Polish notation, often abbreviated RPN.
See also the quaternion version of this calculator.
Input.
Either (but not both) of the input boxes can be left empty, defaulting to zero.
rect real or polar radius | rect imag or polar angle | implicit | |||||
implicit |
The digit buttons have the obvious equivalents on the keyboard, as do the minus sign and decimal point. Also, the e key substitutes for the ent exp (enter exponent) button. If you use the mouse or the arrow keys to move the cursor within an input box, the web-page buttons may not recognize the change, and the next input character may appear at a surprising location.
Lacking keyboard equivalents are the buttons to clear one input box, and to backspace one character.
The minimum format for a number is simply a string of digits, such as 2436. It can start with a minus sign, as −34. That is optionally followed by a point and more digits, for instance 12.54. Further, an exponent may be suffixed, and it begins with the letter e, has an optional plus sign or minus sign, and then some digits. For example, 12.54e−77 means 12.54 times 10 to the −77 power. Here are some typical numbers:
23 | 432e16 | 1722e-4 | 543.21 | 386.32e9 | 232e-18 |
-43 | -29.683 | -897e-4 | -114.381 | -14.98e11 | -246785e+26 |
Once you have put your desired numbers into the input boxes and clicked enter rect or enter polar, your number will be displayed in register a in both rectangular and polar formats. The previous contents (if any) of register a will move to b, what was in b will go to c, et cetera. Both input boxes will be cleared.
register letter | real part | imaginary part | radius | angle |
a | ||||
---|---|---|---|---|
b | ||||
et cetera | ||||
real ← rect → imag | radius ← polar → angle |
If either component of your input number was illegally formatted, register a will show what the calculator could salvage from it, with a result of NaN indicating complete failure.
Two special buttons, pi enter and e enter, move pi ≈ 3.141593 and e ≈ 2.718282 directly to register a.
In polar format:
As a result of many enters or other operations, there may be more than eight numbers stored in the calculator, with the stack count box in the lower left telling how many. Although only eight can be shown, many more can be stored.
Many operations listed below perform the implicit enter. With these, if you have started entering a number into the input boxes, but have not yet clicked the enter rect or enter polar button, the number will be moved into register a before the operation is commenced, as though an enter button had been used. The checkboxes next to the enter buttons determine whether the input will be interpreted as rectangular or polar. Any numbers that were already in the stack will be moved down to make room, as with the explicit clicking of an enter button.
These controls pertain to the stack:
delete the entire stack, but not the input boxes, nor statistical data | ||
delete the contents of a, and move other stack contents up to fill the gap | ||
copy a to b, and move other stack contents down to make room | ||
swap a and b | swap other registers similarly | |
swap b and c | ||
stack count | total quantity of numbers in the stack; at most eight are visible |
The dup button performs the implicit enter, placing two copies of the input number into the stack. Other controls:
digits to display 0 3 6 9 12 all | choose how many digits will be shown in the results of calculations;
full precision (equivalent to about 15 decimal digits) is maintained internally |
exp notation | when checked, always display results in exponential form |
The mathematical operations below perform the implicit enter. Some replace the contents of stack register a with a new value; the others consume registers a and b and leave the result in a, afterward moving the contents of c to b, d to c, et cetera. The calculator provides the same precision, usually about 15 decimal digits, as the underlying JavaScript operations. Furnished are two varieties of each two-argument non-commutative operation.
one input, one output | conjugate | |||||
two inputs, one output | divide | divide | two inputs, one output | |||
multiply | reciprocal | one input, one output | ||||
subtract | subtract | two inputs, one output | ||||
add | negate | one input, one output |
The next functions are in general multiple-valued, so a principal value is returned.
restrictions | |||
two inputs, one output | ath root of b | when b = 0, a must be positive real | |
b to ath power | |||
bth root of a | when a = 0, b must be positive real | ||
a to bth power |
The next operations are all one-input-one-output, replacing the contents of register a with something new. The implicit enter is performed. Angles are reckoned in radians, not degrees. The definitions are from those given in chapter four of Abramowitz and Stegun.
circular | sine | principal value of inverse sine | circular | ||
cosine | principal value of inverse cosine | ||||
tangent | principal value of inverse tangent | ||||
hyperbolic | sine | principal value of inverse sine | hyperbolic | ||
cosine | principal value of inverse cosine | ||||
tangent | principal value of inverse tangent | ||||
exponential | principal value of natural logarithm | ||||
principal value of cube root | principal value of square root |
For trigonometry, the button legends read inv… instead of the more frequently seen arc… because:
Some of the functions above are not defined for certain inputs (see branch cuts).
not defined … | … when both conditions are true | |
abs (x) > 1 | y = 0 | |
abs (x) > 1 | y = 0 | |
x = 0 | abs (y) > 1 | |
x = 0 | abs (y) > 1 | |
x < 1 | y = 0 | |
abs (x) > 1 | y = 0 | |
x = 0 | y = 0 |
The next operations replace the complex number in register a with a real number. Some information is lost.
step 1 | step 2 | |
leave the real part unchanged | move zero to the imaginary part then calculate the new radius and angle | |
move the imaginary part to the real part | ||
move the radius to the real part | ||
move the angle to the real part |
Because the description of the statistical controls (pictured below) is lengthy, it is on a separate page.
stats | univar | ||||||||
---|---|---|---|---|---|---|---|---|---|
weight n n−1 | bivar | ||||||||
data count |
Comments.
Following the tradition of RPN calculators, most notably those of Hewlett-Packard, the enter buttons are wider than the others. However, stack manipulation on this calculator does differ from some versions of HP's RPN. For instance, there is no t register whose contents are replicated when the pop (HP calls it drop) button is pushed.
The postfix-with-stack design means that an enhanced version of this calculator could introduce operations with any number of inputs and any number of outputs — such flexibility is fully exploited in languages like Adobe PostScript. With an infix-and-parentheses syntax by contrast, it is awkward for an operation to have more than two inputs or one output.
Keyboards of pocket calculators are, by practical reasons of size, limited to about fifty buttons. As a result, many functions are accessed by way of shift buttons (often called f, g, 2nd, or inv). On the other hand a web page, when viewed on a full-size computer screen, has plenty of room, so no shift buttons are used here. If this calculator were optimized for small-screen handheld devices, shift buttons might become necessary, and fewer than eight registers would likely be displayed.
All JavaScript code is housed in this one file, although some of the documentation is elsewhere. Users may copy, modify, and republish as desired.