summaryrefslogtreecommitdiffstats
path: root/Modules/_decimal
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-04-18 17:27:32 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-04-18 17:27:32 (GMT)
commitc51b7fd65b8c7476180c965d48390431b2d558e6 (patch)
tree5fb4e132eddf655bdda222bfda9a2f96784fdcd4 /Modules/_decimal
parent5d0d2e2b04631e5ad9c7dad60e6be75c02f8e050 (diff)
downloadcpython-c51b7fd65b8c7476180c965d48390431b2d558e6.zip
cpython-c51b7fd65b8c7476180c965d48390431b2d558e6.tar.gz
cpython-c51b7fd65b8c7476180c965d48390431b2d558e6.tar.bz2
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).
Diffstat (limited to 'Modules/_decimal')
-rw-r--r--Modules/_decimal/libmpdec/mpdecimal.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c
index 6dd7002..89be535 100644
--- a/Modules/_decimal/libmpdec/mpdecimal.c
+++ b/Modules/_decimal/libmpdec/mpdecimal.c
@@ -6691,10 +6691,7 @@ recpr_schedule_prec(mpd_ssize_t klist[MPD_MAX_PREC_LOG2],
return i-1;
}
-/*
- * Initial approximation for the reciprocal. Result has MPD_RDIGITS-2
- * significant digits.
- */
+/* Initial approximation for the reciprocal. */
static void
_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;
int n;
+ assert(v->exp == -v->digits);
+
_mpd_get_msdigits(&dummy, &word, v, MPD_RDIGITS);
n = mpd_word_digits(word);
word *= mpd_pow10[MPD_RDIGITS-n];
@@ -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);
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;
mpd_setdigits(z);
}
@@ -6723,7 +6722,7 @@ _mpd_qreciprocal(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
mpd_context_t varcontext, maxcontext;
mpd_t *z = result; /* current approximation */
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(t,0,0,0,0); /* temporary variable */
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,
uint8_t sign = mpd_sign(a);
int i;
- v = &vtmp;
assert(result != a);
+ v = &vtmp;
mpd_clear_flags(v);
adj = v->digits + v->exp;
v->exp = -v->digits;