diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /libmp/port/mpvecsub.c | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'libmp/port/mpvecsub.c')
| -rw-r--r-- | libmp/port/mpvecsub.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libmp/port/mpvecsub.c b/libmp/port/mpvecsub.c new file mode 100644 index 00000000..db93b65b --- /dev/null +++ b/libmp/port/mpvecsub.c @@ -0,0 +1,34 @@ +#include "os.h" +#include <mp.h> +#include "dat.h" + +// prereq: a >= b, alen >= blen, diff has at least alen digits +void +mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff) +{ + int i, borrow; + mpdigit x, y; + + borrow = 0; + for(i = 0; i < blen; i++){ + x = *a++; + y = *b++; + y += borrow; + if(y < borrow) + borrow = 1; + else + borrow = 0; + if(x < y) + borrow++; + *diff++ = x - y; + } + for(; i < alen; i++){ + x = *a++; + y = x - borrow; + if(y > x) + borrow = 1; + else + borrow = 0; + *diff++ = y; + } +} |
