HP
Section: User Commands (1)
Index
Return to Main Contents
NAME
hp - Reverse Polish Notation calculator
SYNOPSIS
hp
[
expression elements
]
DESCRIPTION
Hp
is a desk calculator program using the Reverse Polish Notation
familiar to all stack machine aficionados and users of
Hewlett-Packard calculators.
It accepts expressions composed of operands and operators from
either its argument list or standard input and evaluates them.
If the expressions to be evaluated are given on the command line,
hp
prints the resulting value automatically;
otherwise, the user must request printing with the
"p"
or
"P"
commands.
An acceptable expression consists of a sequence of
"constants"
and
"commands."
Constants are numeric constants written in the style of FORTRAN,
and are stored internally as double precision floating-point values.
Commands are single characters that request an arithmetic, stack
control, or control flow operation.
The following commands are currently implemented:
- p
-
print the value on the top of the stack.
- P
-
print all the values currently on the stack.
- d
-
delete the top value on the stack (throw it away).
- D
-
empty the stack completely (throw all stacked data away).
- +
-
add top two items on the stack, place sum on the stack.
- -
-
subtract top of stack from next to top, place difference on the stack.
- * or x or X
-
multiply top two items on the stack, place product on the stack.
Since
"*"
is usually expanded by the shell,
hp
allows
"x"
or
"X"
as synonyms for
"*".
(The idea is that
"x"
is hopefully reminiscent of the grade-school notation used for multiplication.)
- /
-
divide next to top of stack by top of stack, place quotient on the stack.
- %
-
divide next to top of stack by top of stack, place remainder on the stack.
- ^ or :
-
evaluate (next to top of stack) to the (top of stack) power, place
result on the stack.
The
":",
while not very mnemonic, is not special to the Bourne shell
(sh(1)),
and so can be used
on the command line.
- <
-
if next to top of stack is less than top of stack, place a 1 on the
stack; otherwise, place a 0 on the stack.
- =
-
if next to top of stack equals top of stack, place a 1 on the stack;
otherwise, place a 0 on the stack.
- >
-
if next to top of stack is greater than top of stack, place a 1 on the
stack; otherwise, place a 0 on the stack.
- &
-
if next to top of stack is nonzero and top of stack is nonzero, place
a 1 on the stack; otherwise, place a 0 on the stack.
- |
-
if next to top of stack is nonzero or top of stack is nonzero,
place a 1 on the stack; otherwise, place a 0 on the stack.
- !
-
if top of stack is nonzero, replace it with a 0; if it is zero,
replace it with a 1 (logical negation).
- q or Q
-
exit.
Hp
will also exit when it sees an end-of-file (usually control-D).
EXAMPLES
hp 32.75 4.5 '*'
hp
1 2 3 4 5 6 7P++++++pd
3.1416 2.7183^ 2.7183 3.1416^>p
SEE ALSO
eval(1),
lex(1),
yacc(1)
DIAGNOSTICS
- stack overflow
-
if an attempt is made to push too many items on the stack.
The stack size is currently limited to about 100.
- stack underflow
-
if an attempt is made to perform an operation
with insufficient operands on the stack.
- <char>: unrecognized command
-
if a character not corresponding to
any command appears in an expression.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- EXAMPLES
-
- SEE ALSO
-
- DIAGNOSTICS
-
This document was created by
man2html,
using the manual pages.
Time: 06:11:41 GMT, December 12, 2024