mp: fix mpnot and add mpasr
This commit is contained in:
parent
193daffafb
commit
cf2f2a8841
2 changed files with 23 additions and 1 deletions
|
@ -127,6 +127,9 @@ void mptrunc(mpint *b, int n, mpint *res)
|
|||
void mpxtend(mpint *b, int n, mpint *res)
|
||||
.PP
|
||||
.B
|
||||
void mpasr(mpint *b, int n, mpint *res)
|
||||
.PP
|
||||
.B
|
||||
void mpmul(mpint *b1, mpint *b2, mpint *prod)
|
||||
.PP
|
||||
.B
|
||||
|
@ -584,6 +587,12 @@ Logical operations (treating negative numbers using two's complement):
|
|||
.I mpnot
|
||||
.BR "res = ~b1" .
|
||||
.TP
|
||||
.I mpasr
|
||||
.BR "res = b>>shift"
|
||||
(\fImpasr\fR, unlike
|
||||
.IR mpright ,
|
||||
uses two's complement).
|
||||
.TP
|
||||
.I mptrunc
|
||||
truncates
|
||||
.I b
|
||||
|
|
|
@ -85,7 +85,8 @@ void
|
|||
mpnot(mpint *b, mpint *r)
|
||||
{
|
||||
mpadd(b, mpone, r);
|
||||
r->sign ^= -2;
|
||||
if(r->top != 0)
|
||||
r->sign ^= -2;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -193,3 +194,15 @@ mpxtend(mpint *b, int n, mpint *r)
|
|||
}
|
||||
mpnorm(r);
|
||||
}
|
||||
|
||||
void
|
||||
mpasr(mpint *b, int n, mpint *r)
|
||||
{
|
||||
if(b->sign > 0 || n <= 0){
|
||||
mpright(b, n, r);
|
||||
return;
|
||||
}
|
||||
mpadd(b, mpone, r);
|
||||
mpright(r, n, r);
|
||||
mpsub(r, mpone, r);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue