]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/man/1/pc
merge
[plan9front.git] / sys / man / 1 / pc
index d7bbeee14c8bd8307baf8d7077c3390e2942c53a..287938541de01120b32fba9d3a41380df9047539 100644 (file)
@@ -8,7 +8,7 @@ pc \- programmer's calculator
 ]
 .SH DESCRIPTION
 .I Pc
-is an arbitrary precision calculator with a special emphasis on supporting two's complement bit operations and working with different number bases.
+is an arbitrary precision integer calculator with a special emphasis on supporting two's complement bit operations and working with different number bases.
 .PP
 .I Pc
 reads input statements which are either expressions or control statements.
@@ -33,6 +33,9 @@ Expressions can use the C-like operators
 .TP
 .B < >= < <= == !=
 .PP
+The \fB$\fR operator performs sign extension. \fIn\fB$\fIx\fR truncates \fIx\fR to \fIn\fR bits and sign extends.
+If \fIn\fR is omitted, it is inferred from the highest set bit (the result is always ≤ 0 in this case).
+.PP
 Variables can be defined using
 .BR = .
 The builtin variable
@@ -51,7 +54,7 @@ Numbers can use the prefixes
 .B _
 in numbers can be added for readability and is ignored.
 .SS Builtin functions
-.TF xtend(n,m)
+.TF \fIcat(a0,n0,...,aN,nN)
 .TP
 .I bin(n)
 Display \fIn\fR in binary.
@@ -65,6 +68,9 @@ Display \fIn\fR in decimal.
 .I hex(n)
 Display \fIn\fR in hexadecimal.
 .TP
+.I pb(n, b)
+Display \fIn\fR in base \fIb\fR (currently must be one of 0, 2, 8, 10, 16; 0 uses the defined output base).
+.TP
 .I abs(n)
 Absolute value of \fIn\fR.
 .TP
@@ -84,15 +90,27 @@ Numbers exactly halfway between are rounded to the next even multiple.
 .I xtend(n,m)
 \fIn\fR truncated to \fIm\fR bits, with the highest bit interpreted as a sign bit.
 .TP
+.I rev(n,m)
+\fIn\fR truncated to \fIm\fR bits, with the order of bits reversed.
+.TP
 .I ubits(n)
 The minimum number of bits required to represent \fIn\fR as an unsigned number.
 .TP
 .I sbits(n)
 The minimum number of bits required to represent \fIn\fR as an signed number.
 .TP
+.I nsa(n)
+The number of bits set in \fIn\fR.
+.TP
+.I cat(a\d\s70\s0\u,n\d\s70\s0\u,...,a\d\s7N\s0\u,n\d\s7N\s0\u)
+Truncate each of the \fIa\d\s7i\s0\u\fR arguments to \fIn\d\s7i\s0\u\fR bits and concatenate their binary representation.
+.TP
 .I gcd(n,m)
 The greatest common divisor of \fIn\fR and \fIm\fR.
 .TP
+.I clog(a,b)
+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.
+.TP
 .I minv(n,m)
 The inverse of \fIn\fR mod \fIm\fR.
 .TP
@@ -126,6 +144,10 @@ Use Euclidean division (default).
 Use truncating division (same as C).
 \fIa\fR / \fIb\fR is rounded towards zero.
 \fIa\fR % \fIb\fR can be negative.
+.TP
+\fL\'\fR 1
+Enable numbering bits (disable with 0).
+If the base is a power of two, print the number of the corresponding bit above each digit.
 .SH SOURCE
 .B /sys/src/cmd/pc.y
 .SH "SEE ALSO"