diff options
author | aiju <devnull@localhost> | 2016-08-28 10:49:41 +0200 |
---|---|---|
committer | aiju <devnull@localhost> | 2016-08-28 10:49:41 +0200 |
commit | cf2f2a884137b589f502ffc7af9de5ca78634356 (patch) | |
tree | 09ae722e5907b20b1ffa559fc45bbdd14125ac71 | |
parent | 193daffafb2ca564a47e52489cb082d77fa78872 (diff) |
mp: fix mpnot and add mpasr
-rw-r--r-- | sys/man/2/mp | 9 | ||||
-rw-r--r-- | sys/src/libmp/port/mplogic.c | 15 |
2 files changed, 23 insertions, 1 deletions
diff --git a/sys/man/2/mp b/sys/man/2/mp index 5223c8a10..678f0eb7f 100644 --- a/sys/man/2/mp +++ b/sys/man/2/mp @@ -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 diff --git a/sys/src/libmp/port/mplogic.c b/sys/src/libmp/port/mplogic.c index 3dd9be2ab..16de7571b 100644 --- a/sys/src/libmp/port/mplogic.c +++ b/sys/src/libmp/port/mplogic.c @@ -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); +} |