-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
.Dd April 17, 2017 | ||
.Dt CLAC 1 | ||
. | ||
.Sh NAME | ||
. | ||
.Nm clac | ||
.Nd A command line, stack-based calculator with postfix notation | ||
|
||
.Sh SYNOPSIS | ||
. | ||
.Nm | ||
. | ||
.Sh DESCRIPTION | ||
. | ||
.Nm | ||
is a command line, stack-based calculator with postfix notation | ||
that displays the stack contents at all times. As you type, the | ||
stack changes are reflected immediately. | ||
.Pp | ||
In a stack-based postfix calculator, entering a number pushes it | ||
on a stack, and arithmetic operations pop their arguments from the | ||
stack and push the result. As all the operations take a fix number | ||
of arguments, there's no room for ambiguity: parenthesis and operator | ||
precedence are not needed. Postfix notation is also known as reverse | ||
Polish notation, or RPN. | ||
. | ||
.Ss Commands | ||
. | ||
When a command requires an argument, it pops a value from the stack. | ||
If the stack is empty, a zero is provided instead. In the descriptions | ||
below, the top of the stack (and thus the first value popped) is | ||
represented by the letter `a`, while the second value popped is | ||
represented by the letter `b`. For example, if the stack is composed | ||
of the number `1`, `2` and `3` (with `3` at the top of the stack), | ||
when we describe the sum then `a` will be `3` and `b` will be `2`. | ||
It is important to note that subtraction and division invert the | ||
order of the arguments before performing the operation: with `1`, | ||
`2` and `3` in the stack, when you type `-` it will pop the values | ||
`3` and `2` and push the result of `2 - 3`. This is in the tradition | ||
of other postfix calculators and programming languages. | ||
. | ||
A description of the available commands follows. | ||
. | ||
.Ss Arithmetic operations | ||
. | ||
.Bl -tag -width Fl | ||
.It Ic + | ||
Pop two values `a` and `b` and push the result of `a + b`. | ||
. | ||
.It Ic - | ||
Pop two values `a` and `b` and push the result of `b - a`. | ||
. | ||
.It Ic * | ||
Pop two values `a` and `b` and push the result of `a * b`. | ||
. | ||
.It Ic / | ||
Pop two values `a` and `b` and push the result of `b / a`. | ||
.El | ||
. | ||
.Ss Modulo operation | ||
. | ||
.Bl -tag -width Fl | ||
.It Ic % | ||
Pop two values `a` and `b` and push the remainder of the Euclidean | ||
division of `b` by `a`. | ||
.El | ||
. | ||
.Ss Exponentiation | ||
. | ||
.Bl -tag -width Fl | ||
.It Ic ^ | ||
Pop two values `a` and `b` and push the result of `b ^ a`. | ||
.El | ||
. | ||
.Ss Rounding | ||
. | ||
.Bl -tag -width Fl | ||
.It Ic ceil | ||
Pop the value `a` and push smallest integral value greater than or | ||
equal to `a`. | ||
.It Ic floor | ||
Pop the value `a` and push largest integral value less than or equal | ||
to `a`. | ||
.It Ic round | ||
Pop the value `a` and push integral value nearest to `a`. | ||
.El | ||
. | ||
.Ss Stack manipulation | ||
. | ||
.Bl -tag -width Fl | ||
.It Ic swap | ||
Pop two values `a` and `b` and push the values `a`, `b`. | ||
.It Ic dup | ||
Pop the value `a` and push the values `a`, `a`. | ||
.It Ic _ | ||
Push on the stack the result of the last operation. | ||
.El | ||
. | ||
.Sh AUTHOR | ||
.An Michel Martens Aq [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.