summaryrefslogtreecommitdiffstats
path: root/Modules/_decimal
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-08-22 16:54:37 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-08-22 16:54:37 (GMT)
commit2fd502f6a183fde7d8b4847d27e09884bf8006c7 (patch)
treef3b62140e4e4c7fab79474673610247642ae9da5 /Modules/_decimal
parentad54c6d82e9a4e3feb2a4a48a291dda99cf55507 (diff)
downloadcpython-2fd502f6a183fde7d8b4847d27e09884bf8006c7.zip
cpython-2fd502f6a183fde7d8b4847d27e09884bf8006c7.tar.gz
cpython-2fd502f6a183fde7d8b4847d27e09884bf8006c7.tar.bz2
1) Use _mpd_basedivmod() regardless of the length of the dividend. This is
required for a corner case in dec_hash() in the following commit and also usually faster. dec_hash() needs some extra precision above MPD_MAX_PREC, and _mpd_base_ndivmod() is not audited for that. 2) Use _mpd_basemul() if the length of the smaller operand is less than or equal to 256. While this is technically an optimization, it is required for *testing* corner cases in dec_hash() in reasonable time.
Diffstat (limited to 'Modules/_decimal')
-rw-r--r--Modules/_decimal/libmpdec/mpdecimal.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c
index d7ae41c..9bdb03d 100644
--- a/Modules/_decimal/libmpdec/mpdecimal.c
+++ b/Modules/_decimal/libmpdec/mpdecimal.c
@@ -3513,8 +3513,7 @@ _mpd_qdiv(int action, mpd_t *q, const mpd_t *a, const mpd_t *b,
if (b->len == 1) {
rem = _mpd_shortdiv(q->data, a->data, a->len, b->data[0]);
}
- else if (a->len < 2*MPD_NEWTONDIV_CUTOFF &&
- b->len < MPD_NEWTONDIV_CUTOFF) {
+ else if (b->len <= MPD_NEWTONDIV_CUTOFF) {
int ret = _mpd_basedivmod(q->data, NULL, a->data, b->data,
a->len, b->len);
if (ret < 0) {
@@ -3667,8 +3666,7 @@ _mpd_qdivmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b,
r->data[0] = _mpd_shortdiv(q->data, a->data, a->len, b->data[0]);
}
}
- else if (a->len < 2*MPD_NEWTONDIV_CUTOFF &&
- b->len < MPD_NEWTONDIV_CUTOFF) {
+ else if (b->len <= MPD_NEWTONDIV_CUTOFF) {
int ret;
ret = _mpd_basedivmod(q->data, r->data, a->data, b->data,
a->len, b->len);
@@ -5544,10 +5542,15 @@ _mpd_qmul(mpd_t *result, const mpd_t *a, const mpd_t *b,
}
- if (small->len == 1) {
+ if (small->len <= 256) {
rdata = mpd_calloc(rsize, sizeof *rdata);
if (rdata != NULL) {
- _mpd_shortmul(rdata, big->data, big->len, small->data[0]);
+ if (small->len == 1) {
+ _mpd_shortmul(rdata, big->data, big->len, small->data[0]);
+ }
+ else {
+ _mpd_basemul(rdata, small->data, big->data, small->len, big->len);
+ }
}
}
else if (rsize <= 1024) {