======================================================================
Help for DimCalc by David A Lyons 30-Aug-89
======================================================================
DimCalc is a postfix-notation calculator. Instead of working only
with numbers, DimCalc works with numbers AND THEIR UNITS.
Since DimCalc uses postfix notation, values are written first, and
then operations are performed on them.
Note that uppercase and lowercase letters are distinct in DimCalc. All
units and prefixes must be typed in lowercase. Names of variables and
names of definitions may use any mixture of case, but it _does_ make a
difference--for example, 2 variables called "G" and "g" are independent.
=========
Operators
=========
name takes leaves description
---- ----- ------ -----------
+ 2 1 addition (dimensions must be equal)
- 2 1 subtraction (dimensions must be equal)
* 2 1 multiplication
/ 2 1 division
pwr 2 1 exponentiation (exponent must be dimensionless)
sin 1 1 sine of angle (value must be an angle; leaves
cos 1 1 cosine dimensionless value)
tan 1 1 tangent
asin 1 1 arcsine (result in angle)
acos 1 1 arccosine (result is angle)
atan 1 1 arctangent (result is angle)
log 1 1 base 10 log
alog 1 1 base 10 antilog
ln 1 1 base e log
exp 1 1 base e antilog
sqr 1 1 square (x --> x^2)
sqrt 1 1 square root
dup 1 2 duplicates a value
drop 1 0 removes 1 value
swap 2 2 swaps 2 values
. 1 0 prints 1 value
= 0 1 used when printing with units specified
(use "=", units, ".")
====================
setting display mode
====================
Three modes for printing numbers are supported: fixed, scientific, and
engineering (fix, sci, eng). A display mode is one of these three, plus
a number from 0 to 11 specifying how many digits to put after the decimal
point.
Fixed mode is the simplest: an integer, followed by a decimal point and
a fixed number of digits, is printed. The number is rounded off to the
specified number of places after the decimal. If a number is too large or
too small to print in fixed-point notation, scientific format is used
automatically instead.
Scientific mode is one digit, a decimal point, and a specified number of
digits after the decimal, and an exponent of 10. Example: 6.670e-11
Engineering mode is the same as scientific mode, EXCEPT that the exponent of
10 is always a multiple of 3 (making it easy to read a result as "thousands,"
"millions," "thousandths," "millionths," etc., and there are 1, 2, or 3
digits before the decimal point.
To set the display mode, use 'fix' or 'sci' or 'eng' after putting the
number from 0 to 11 on the stack. Examples: 0 fix 4 sci 2 eng
The default (when you enter DimCalc) is fix 4.
==============
Other commands
==============
prefixes -- displays list of metric prefixes and their meanings
units -- displays list of known units
what -- displays dimensions of value entered
q / quit -- stop using DimCalc
stack -- prints all values on stack
clear -- removes all values from stack
help -- displays this file using Primos's "pg" command
version/ver -- reprints intro message
# -- retrieves last value printed with "."
==========================
entering numbers and units
==========================
per
exponents
examples: 12 feet
32.99e-17 megaacres
-9 megamicrons per kilocentury^2
100 kilowatt hours
9.81 meters per second per second
===========
definitions
===========
When the name of a definition is given on the input line, it is translated
into its value.
Example: if "hypot" is defined as "sqr swap sqr + sqrt", then "hypot" is an
operator that takes 2 values on the stack and leaves 1, equal to the square
root of the sum of the squares of the 2 values, and
3 yards 4 yards hypot = feet .
prints 15 feet.
define/def -- defines or redefines
defs/definitions -- lists all definitions
show -- lists one definition
undef/undefine -- removes a definition
If you have changed any definitions, DimCalc asks you if you want to keep
the changes when you quit.
=========
variables
=========
> name -- defines variable from stack
@ name or -- put variable's value on stack
< name (ex: 3 @myvar * calculates 3 times value of 'myvar')
vars -- list all variables
delvar -- delete a variable
If you have changed any variables, DimCalc asks you if you want to keep the
changes when you quit.
========
examples
========
Problem: "How many times around the earth (at the equator) could a person
go at 2 miles an hour walking for 15 years?"
Solution: We want to calculate 2 mph * 15 years (a distance) and then
divide by the circumference of the earth (2 pi times the Earth's
radius).
There are plenty of different solutions. First, the quickest one:
Type
2 mph 15 years * 2 3.14159265358 * 6.37E6 meters * / .
This will get the correct answer, but it may not be the best
approach.
For the second solution, let's consider that we may want to
keep some of the information around for later. We will do
this by storing some values in VARIABLES.
3.14159265358 >pi
6.37E11 meters >rEarth
Next we define a word that calculates the circumference of
a circle from its radius:
define circum @pi 2 * *
Now we're ready to solve the probblem:
2 mph 15 years * @rEarth circum / .
Problem: "If all my body's matter were converted into energy, how
long could this energy power a 100 watt light bulb?"
Solution: We will need the equation E=mc^2 for this. m is the mass,
E is the energy, and c is the velocity of light.
Begin by calculating the speed of light and keeping it for
later:
1 lightyear 1 year / >c
or 3E8 meters per sec >c
Next define 'energy' to take a mass and leave the result:
define energy @c sqr *
Now we can deal with the original problem easily:
(enter your body weight)
energy 100 watts / .
The result was printed in seconds, and it is an incredibly
large number! So let's print it in years instead. It's
STILL large:
# = years .
(Recall that '#' gets the last value printed with '.')
Problem: Calculate the average density of the Earth in pounds per
cubic foot.
Solution: We still have the variable rEarth defined from a previous
problem. We will need the mass of the Earth and the volume
of the Earth.
5.98E24 kilograms >mEarth
We want to calculate the volume of a sphere from its radius:
def spherevol 3 pwr 4 * 3 / @pi *
(Volume = 4/3 pi r^3)
Now:
@mEarth @rEarth spherevol / = pounds per foot^3 .
--------
If you want to play with gravity,
def kg kilogram
6.67E-11 meters^3 per kg sec^2 >G
def grav >$r * @G * @$r sqr / delvar $r
(Grav expects 2 masses and then a distance, and leaves a force.
It uses a temporary variable ($r) to hold the distance while it does the
first part of the calculation. There is nothing special about the '$'
in the variable name--it's just to avoid conflicts with other variables.
The equation used is F=G M m / r^2.)
==============
advanced stuff
==============
If "_start" is defined, it is executed when you enter DimCalc.
If "_prompt" is defined, it is executed before every "DimCalc>" prompt.
Typical values are "dup ." and "stack".
If the first character on the input line is "!", the rest of the line is
fed to the shell as a command.
========
messages
========
Here are all the error messages DimCalc prints:
*** stack is full
*** stack is empty
*** unknown unit: "..."
*** argument to SIN must be an angle
*** argument to COS must be an angle
*** argument to TAN must be an angle
*** operand for ASin must be -1..1
*** operand for ASin must be dimensionless
*** operand for ACos must be -1..1
*** operand for ACos must be dimensionless
*** operand for ATan must be dimensionless
*** operands for "+" must have same dimensions
*** operands for "-" must have same dimensions
*** can't divide by zero
*** operand for SQRT must not be negative
*** operand for Log must be positive
*** operand for Log must be dimensionless
*** operand for Ln must be positive
*** operand for Ln must be dimensionless
*** operand for Exp must be dimensionless
*** operand for Alog must be dimensionless
*** first operand for pwr must be positive
*** second operand for pwr must be dimensionless
*** operand for fix/sci/eng must be dimensionless
*** operand for fix/sci/eng must not be negative
*** operand for fix/sci/eng must not exceed 11
*** dimensions do not match; unable to print
*** something's fishy...second "=" found, but no "."
*** definition name required
*** "..." not defined
*** variable name required
*** too many variables
*** too many definitions
*** undefined variable: "..."
*** excessive expansion: aborted
There are no definitions.
No variables are defined.
Variables changed; save them? (y/n)
Definitions changed; save them? (y/n)
=======================
known bugs and problems
=======================
There should be a way to print the last (n) stack values.
There should be consistent behavior for how the stack is left in error
conditions. Either popped values should be replaced, or an invalid
result should be pushed. (Current behavior is inconsistent; some operators
push their operands back, but others push nothing.)
Arithmetic errors (overflow, etc.) can cause crash.
'pwr' should allow negative 1st operand if 2nd operand is an integer.
(end of help)