Commit c51b7fd6 authored by Stefan Krah's avatar Stefan Krah

1) Simplify comment -- one has to read the complete proof (available in ACL2)

   in order to understand the algorithm anyway.

2) v->exp == -v->digits may be assumed.

3) Fix comment (v always shares data with a).
parent 5d0d2e2b
...@@ -6691,10 +6691,7 @@ recpr_schedule_prec(mpd_ssize_t klist[MPD_MAX_PREC_LOG2], ...@@ -6691,10 +6691,7 @@ recpr_schedule_prec(mpd_ssize_t klist[MPD_MAX_PREC_LOG2],
return i-1; return i-1;
} }
/* /* Initial approximation for the reciprocal. */
* Initial approximation for the reciprocal. Result has MPD_RDIGITS-2
* significant digits.
*/
static void static void
_mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status) _mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status)
{ {
...@@ -6702,6 +6699,8 @@ _mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status) ...@@ -6702,6 +6699,8 @@ _mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status)
mpd_uint_t dummy, word; mpd_uint_t dummy, word;
int n; int n;
assert(v->exp == -v->digits);
_mpd_get_msdigits(&dummy, &word, v, MPD_RDIGITS); _mpd_get_msdigits(&dummy, &word, v, MPD_RDIGITS);
n = mpd_word_digits(word); n = mpd_word_digits(word);
word *= mpd_pow10[MPD_RDIGITS-n]; word *= mpd_pow10[MPD_RDIGITS-n];
...@@ -6710,7 +6709,7 @@ _mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status) ...@@ -6710,7 +6709,7 @@ _mpd_qreciprocal_approx(mpd_t *z, const mpd_t *v, uint32_t *status)
(void)_mpd_shortdiv(z->data, p10data, 2, word); (void)_mpd_shortdiv(z->data, p10data, 2, word);
mpd_clear_flags(z); mpd_clear_flags(z);
z->exp = -(v->exp + v->digits) - (MPD_RDIGITS-2); z->exp = -(MPD_RDIGITS-2);
z->len = (z->data[1] == 0) ? 1 : 2; z->len = (z->data[1] == 0) ? 1 : 2;
mpd_setdigits(z); mpd_setdigits(z);
} }
...@@ -6723,7 +6722,7 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, ...@@ -6723,7 +6722,7 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
mpd_context_t varcontext, maxcontext; mpd_context_t varcontext, maxcontext;
mpd_t *z = result; /* current approximation */ mpd_t *z = result; /* current approximation */
mpd_t *v; /* a, normalized to a number between 0.1 and 1 */ mpd_t *v; /* a, normalized to a number between 0.1 and 1 */
MPD_NEW_SHARED(vtmp, a); /* by default v will share data with a */ MPD_NEW_SHARED(vtmp, a); /* v shares data with a */
MPD_NEW_STATIC(s,0,0,0,0); /* temporary variable */ MPD_NEW_STATIC(s,0,0,0,0); /* temporary variable */
MPD_NEW_STATIC(t,0,0,0,0); /* temporary variable */ MPD_NEW_STATIC(t,0,0,0,0); /* temporary variable */
MPD_NEW_CONST(two,0,0,1,1,1,2); /* const 2 */ MPD_NEW_CONST(two,0,0,1,1,1,2); /* const 2 */
...@@ -6732,9 +6731,9 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, ...@@ -6732,9 +6731,9 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
uint8_t sign = mpd_sign(a); uint8_t sign = mpd_sign(a);
int i; int i;
v = &vtmp;
assert(result != a); assert(result != a);
v = &vtmp;
mpd_clear_flags(v); mpd_clear_flags(v);
adj = v->digits + v->exp; adj = v->digits + v->exp;
v->exp = -v->digits; v->exp = -v->digits;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment