pc(1): add nsa() command
This commit is contained in:
parent
7bcbef11eb
commit
07284c41f6
2 changed files with 26 additions and 0 deletions
|
@ -93,6 +93,9 @@ The minimum number of bits required to represent \fIn\fR as an unsigned number.
|
||||||
.I sbits(n)
|
.I sbits(n)
|
||||||
The minimum number of bits required to represent \fIn\fR as an signed number.
|
The minimum number of bits required to represent \fIn\fR as an signed number.
|
||||||
.TP
|
.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)
|
.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.
|
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
|
.TP
|
||||||
|
|
|
@ -766,6 +766,28 @@ fnsbits(int, Num **a)
|
||||||
return a[0];
|
return a[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Num *
|
||||||
|
fnnsa(int, Num **a)
|
||||||
|
{
|
||||||
|
int n, i;
|
||||||
|
mpdigit d;
|
||||||
|
|
||||||
|
a[0] = nummod(a[0]);
|
||||||
|
if(a[0]->sign < 0){
|
||||||
|
numdecref(a[0]);
|
||||||
|
return error("invalid argument");
|
||||||
|
}
|
||||||
|
n = 0;
|
||||||
|
for(i = 0; i < a[0]->top; i++){
|
||||||
|
d = a[0]->p[i];
|
||||||
|
for(; d != 0; d &= d-1)
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
itomp(n, a[0]);
|
||||||
|
a[0]->b = 0;
|
||||||
|
return a[0];
|
||||||
|
}
|
||||||
|
|
||||||
Num *
|
Num *
|
||||||
fngcd(int, Num **a)
|
fngcd(int, Num **a)
|
||||||
{
|
{
|
||||||
|
@ -889,6 +911,7 @@ main(int argc, char **argv)
|
||||||
regfunc("xtend", fnxtend, 2);
|
regfunc("xtend", fnxtend, 2);
|
||||||
regfunc("ubits", fnubits, 1);
|
regfunc("ubits", fnubits, 1);
|
||||||
regfunc("sbits", fnsbits, 1);
|
regfunc("sbits", fnsbits, 1);
|
||||||
|
regfunc("nsa", fnnsa, 1);
|
||||||
regfunc("gcd", fngcd, 2);
|
regfunc("gcd", fngcd, 2);
|
||||||
regfunc("minv", fnminv, 2);
|
regfunc("minv", fnminv, 2);
|
||||||
regfunc("rand", fnrand, 1);
|
regfunc("rand", fnrand, 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue