-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaddc.1
108 lines (108 loc) · 2.29 KB
/
baddc.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.Dd 25 May, 2022
.Dt BADDC 1
.Os "ben's space"
.Sh NAME
.Nm baddc
.Nd integer-precision desk calculator
.Sh SYNOPSIS
.Nm
.Op Ar file
.Sh DESCRIPTION
.Nm
is a simple desk calculator for integer arithmetic.
It operates on a stack and uses reverse-polish notation, like
.Xr dc 1 .
.Pp
.Nm
reads lines from
.Ar file
or from the standard input if no operands are given,
and interprets them as follows:
.Bl -bullet
.It
If a hexanumerical number is found, it is pushed onto the stack
according to the current input base.
The number may be composed of the characters 0-9 and A-F
.Pq but not a-f .
.It
If the number is prefixed by
.Sq _ ,
the negative of the number is pushed.
.It
Whitespace is ignored.
.It
If one of the supported operations is found, it is performed.
.It
.Nm
quits on EOF.
.It
If a stack overflow or underflow occurs,
.Nm
prints a warning.
.El
.Pp
The input and output bases default to base 10.
.Pp
The supported operations are:
.Bl -tag -width Ds
.It p
Print the top value of the stack without popping it off.
.It f
Print the contents of the stack, from top to bottom.
.It d
Duplicate the top of the stack.
.It c
Clear the entire stack.
.It +
Pop the top two values on the stack, and push their sum.
.It -
Subtract the first value from the second, and push the result.
.It *
Multiply the top two values, and push the result.
.It /
Divide the second value by the first, and push the result.
.It i
Use the top value of the stack as the new input base.
.It I
Push the current input base.
.It o
Use the top value of the stack as the new output base.
.It O
Push the current output base.
.It %
Push the second value modulus the second
.Pq the remainder after division .
.It ^
Push the second value raised to the first value.
.It v
Push the square root of the first value.
.It r
Drop the top value of the stack.
.It q
Quit
.Nm
immediately.
.El
.Sh EXIT STATUS
The
.Nm
utility exits 0 on success, and 1 if the named
.Ar file
cannot be opened for reading.
.Sh SEE ALSO
.Xr bc 1 ,
.Xr dc 1
.Sh BUGS
Since
.Nm
uses integers internally, all the operations perform integer
.Pq floor
rounding which may be lossy.
.Pp
The only supported values of input base are 1-16.
.Pp
The only supported values of output base are 8, 10, 16.
.Pp
Signed numbers are only printed correctly with an output base of 10.
.Sh AUTHORS
.An phoebos Aq Mt [email protected]