summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Jespersen <laumann.thomas@gmail.com>2014-11-25 18:29:18 +0100
committerThomas Jespersen <laumann.thomas@gmail.com>2014-11-25 18:29:18 +0100
commita65243782d6f768b5a933063798cda61ce9f6939 (patch)
treedbb56b0124e8bc772a8ecc1be90b52441be79c00 /src
parent51ecf12487dd87ab5bc2a284a697a85c36143045 (diff)
Unfinished division, but growing closer
Diffstat (limited to 'src')
-rw-r--r--src/blk256.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/blk256.c b/src/blk256.c
index da50fc2..9eadfc3 100644
--- a/src/blk256.c
+++ b/src/blk256.c
@@ -205,6 +205,10 @@ void blk256_sub(blk256_t *rop, blk256_t *op1, blk256_t *op2)
if (neg)
blk256_set_sign_bit(&r);
}
+
+ /**
+ * Arranged such that abs(opx) >= abs(opy)
+ */
uint64_t *opx = r.x;
uint64_t *opy = sop->x;
@@ -227,7 +231,7 @@ void blk256_sub(blk256_t *rop, blk256_t *op1, blk256_t *op2)
if (opx[3] < opy[3])
blk256_clear_high_bit(&r);
else
- r.mx |= (blk256_high_bit(&r) - blk256_high_bit(sop)) & 1;
+ r.mx |= ((blk256_high_bit(&r) - blk256_high_bit(sop))) & 1;
opx[3] -= opy[3];
/* Copy result into rop */
@@ -376,9 +380,11 @@ void blk256_div_blk128(blk256_t *q, blk128_t *r, blk256_t *x, blk128_t *d)
double div = blk128_as_double(d);
double z, xd;
- while (blk256_cmp_blk128(&rr, d) > -1) {
+ while (blk256_cmp_blk128(&rr, d) > -1
+ || blk256_sign_bit(&rr)) {
xd = blk256_as_double(&rr);
z = xd / div;
+ printf("r=%lg, d=%lg, z = %lg\n", xd, div, z);
double_as_blk256(&t, z);
@@ -390,15 +396,10 @@ void blk256_div_blk128(blk256_t *q, blk128_t *r, blk256_t *x, blk128_t *d)
*/
blk256_mul_blk128(&m, &t, d);
- if (blk256_cmp(&m, &rr) > 0) {
- blk256_sub(&qq, &qq, &t);
- blk256_sub(&m, &m, &rr);
- blk256_cp(&rr, &m);
- } else {
- blk256_add(&qq, &qq, &t); /* Add to divisor found so far */
- blk256_sub(&rr, &rr, &m);
- }
+ blk256_add(&qq, &qq, &t); /* Add to divisor found so far */
+ blk256_sub(&rr, &rr, &m);
}
+ printf("\n");
/**
* Set quotient