2024-02-01 18:36:38 +00:00
|
|
|
.\" Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
2024-02-03 03:12:12 +00:00
|
|
|
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
2024-02-01 18:36:38 +00:00
|
|
|
.\"
|
|
|
|
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
|
|
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.TH rpn 1
|
|
|
|
.SH NAME
|
2024-02-03 03:12:12 +00:00
|
|
|
rpn \(en reverse polish notation evaluation
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH SYNOPSIS
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-02-03 03:12:12 +00:00
|
|
|
rpn
|
2024-06-03 00:47:14 +00:00
|
|
|
.RB [ numbers... ]
|
|
|
|
.RB [ operators... ]
|
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH DESCRIPTION
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
Evaluate reverse polish notation.
|
2024-02-03 03:12:12 +00:00
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
The program evaluates reverse polish notation expressions either read from the
|
|
|
|
standard input or parsed from provided arguments. See the STANDARD INPUT
|
|
|
|
section.
|
|
|
|
|
|
|
|
Upon evaluation, the program will print the resulting number on the stack to the
|
2024-02-08 02:11:53 +00:00
|
|
|
standard output. Any further specified numbers will be placed at the end of the
|
|
|
|
stack.
|
2024-02-04 00:20:31 +00:00
|
|
|
|
2024-06-04 22:11:33 +00:00
|
|
|
For information on for reverse polish notation syntax, see
|
|
|
|
.BR rpn (7).
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH STANDARD INPUT
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-06-03 00:47:14 +00:00
|
|
|
If arguments are passed, they are interpreted as an expression to be
|
|
|
|
evaluated. Otherwise, it reads whitespace-delimited numbers and operations from
|
|
|
|
the standard input.
|
|
|
|
.\"
|
2024-02-04 00:20:31 +00:00
|
|
|
.SH DIAGNOSTICS
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-03-27 01:22:30 +00:00
|
|
|
In the event of an error, a debug message will be printed and the program will
|
2024-06-03 00:47:14 +00:00
|
|
|
exit with the appropriate
|
2024-06-04 22:11:33 +00:00
|
|
|
.BR sysexits.h (3)
|
2024-06-06 05:07:15 +00:00
|
|
|
error code; however, in the event of a syntax error, the program will print an
|
|
|
|
error message and continue accepting input.
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-03 03:12:12 +00:00
|
|
|
.SH CAVEATS
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-02-03 03:12:12 +00:00
|
|
|
Due to precision constraints and the way floats are represented in accordance
|
2024-06-03 00:47:14 +00:00
|
|
|
with the IEEE Standard for Floating Point Arithmetic (\fIIEEE 754\fP),
|
|
|
|
floating-point arithmetic has rounding errors. This is somewhat curbed by using
|
|
|
|
the machine epsilon as provided by the Rust standard library to which to round
|
2024-02-08 02:11:53 +00:00
|
|
|
numbers. Because of this, variation is expected in the number of decimal places
|
2024-03-27 01:22:30 +00:00
|
|
|
the program can handle based on the platform and hardware of any given machine.
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH RATIONALE
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-06-03 00:47:14 +00:00
|
|
|
An infix notation calculation utility,
|
|
|
|
.BR bc (1p),
|
|
|
|
is included in the POSIX standard, but does not accept expressions as arguments;
|
|
|
|
in scripts, any predefined, non-interactive input must be piped into the
|
|
|
|
program. A
|
|
|
|
.BR dc (1)
|
|
|
|
pre-dates the standardized
|
|
|
|
.BR bc (1p),
|
|
|
|
the latter originally being a preprocessor for the former, and was included in
|
|
|
|
UNIX v2 onward. While it implements reverse polish notation, it still suffers
|
|
|
|
from being unable to accept an expression as an argument.
|
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH AUTHOR
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-06-03 00:47:14 +00:00
|
|
|
Written by Emma Tebibyte
|
|
|
|
.MT emma@tebibyte.media
|
|
|
|
.ME .
|
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH COPYRIGHT
|
2024-06-04 05:07:19 +00:00
|
|
|
|
2024-02-01 18:36:38 +00:00
|
|
|
Copyright (c) 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later
|
|
|
|
<https://gnu.org/licenses/agpl.html>.
|
2024-06-03 00:47:14 +00:00
|
|
|
.\"
|
2024-02-01 18:36:38 +00:00
|
|
|
.SH SEE ALSO
|
2024-06-03 00:47:14 +00:00
|
|
|
.BR bc (1p),
|
|
|
|
.BR dc (1),
|
2024-06-04 22:11:33 +00:00
|
|
|
.BR rpn (7),
|
2024-06-03 00:47:14 +00:00
|
|
|
.I IEEE 754
|