3 pc \- programmer's calculator
11 is an arbitrary precision integer calculator with a special emphasis on supporting two's complement bit operations and working with different number bases.
14 reads input statements which are either expressions or control statements.
15 Multiple statements in one line can be separated by semicolons.
17 prints the value of all expressions that are not terminated by a semicolon.
20 can be run non-interactively by using the
22 switch. In this case no input prompt is printed.
24 Expressions can use the C-like operators
26 .B + - * ** \fR(exponentiation\fR)
28 .B / % \fR(Euclidean division, by default\fR)
32 .B "&& || \fR(returning the second argument, if appropriate)"
36 Variables can be defined using
40 always refers to the last printed result.
42 Numbers can use the prefixes
52 in numbers can be added for readability and is ignored.
54 .TF \fIcat(a0,n0,...,aN,nN)
57 Display \fIn\fR in binary.
60 Display \fIn\fR in octal.
63 Display \fIn\fR in decimal.
66 Display \fIn\fR in hexadecimal.
69 Display \fIn\fR in base \fIb\fR (currently must be one of 0, 2, 8, 10, 16; 0 uses the defined output base).
72 Absolute value of \fIn\fR.
75 \fIn\fR rounded to the nearest multiple of \fIm\fR.
76 Numbers exactly halfway between are rounded to the next even multiple.
79 \fIn\fR rounded down to the next multiple of \fIm\fR.
82 \fIn\fR rounded up to the next multiple of \fIm\fR.
85 \fIn\fR truncated to \fIm\fR bits.
88 \fIn\fR truncated to \fIm\fR bits, with the highest bit interpreted as a sign bit.
91 \fIn\fR truncated to \fIm\fR bits, with the order of bits reversed.
94 The minimum number of bits required to represent \fIn\fR as an unsigned number.
97 The minimum number of bits required to represent \fIn\fR as an signed number.
100 The number of bits set in \fIn\fR.
102 .I cat(a\d\s70\s0\u,n\d\s70\s0\u,...,a\d\s7N\s0\u,n\d\s7N\s0\u)
103 Truncate each of the \fIa\d\s7i\s0\u\fR arguments to \fIn\d\s7i\s0\u\fR bits and concatenate their binary representation.
106 The greatest common divisor of \fIn\fR and \fIm\fR.
109 The ceiling of the logarithm of \fIa\fR with respect to base \fIb\fR. \fIb\fR can be omitted, in which case it defaults to 2.
112 The inverse of \fIn\fR mod \fIm\fR.
115 A random number satisfying 0 ≤ \fIrand(n)\fR < \fIn\fR.
116 .SS Control statements
118 Control statements are always evaluated with default input base 10.
121 If \fIn\fR ≠ 0, insert
123 in all printed numbers, every
128 Set the default input base to \fIn\fR (default 10).
129 The input base can always be overriden by the base prefixes defined above.
132 Set the output base to \fIn\fR.
133 If \fIn\fR = 0 (default), print each number in the base it was input in.
136 Use Euclidean division (default).
137 \fIa\fR / \fIb\fR is rounded towards ±∞ (opposite sign as \fIb\fR).
138 \fIa\fR % \fIb\fR is always non-negative.
141 Use truncating division (same as C).
142 \fIa\fR / \fIb\fR is rounded towards zero.
143 \fIa\fR % \fIb\fR can be negative.
146 Enable numbering bits (disable with 0).
147 If the base is a power of two, print the number of the corresponding bit above each digit.
154 With the input base set to 16, terms such as
157 They are interpreted as numbers only if there is no function or variable of the same name.
158 To force interpretation as a number, use the \fL0x\fR prefix.
160 Arbitrary bases should be supported, but are not supported by the
165 first appeared in 9front (August, 2016).