]> granicus.if.org Git - python/commit
x_mul(): This failed to normalize its result.
authorTim Peters <tim.peters@gmail.com>
Mon, 12 Aug 2002 06:17:58 +0000 (06:17 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 12 Aug 2002 06:17:58 +0000 (06:17 +0000)
commit44121a6bc9828c993932b87e442440dc4f260f3c
tree9d8be85c1b84bbf7104fb9e0df6cbf2f347725a5
parent877a2126786bd2a8e5086fbddb05a593c40cbc51
x_mul():  This failed to normalize its result.

k_mul():  This didn't allocate enough result space when one input had
more than twice as many bits as the other.  This was partly hidden by
that x_mul() didn't normalize its result.

The Karatsuba recurrence is pretty much hosed if the inputs aren't
roughly the same size.  If one has at least twice as many bits as the
other, we get a degenerate case where the "high half" of the smaller
input is 0.  Added a special case for that, for speed, but despite that
it helped, this can still be much slower than the "grade school" method.
It seems to take a really wild imbalance to trigger that; e.g., a
2**22-bit input times a 1000-bit input on my box runs about twice as slow
under k_mul than under x_mul.  This still needs to be addressed.

I'm also not sure that allocating a->ob_size + b->ob_size digits is
enough, given that this is computing k = (ah+al)*(bh+bl) instead of
k = (ah-al)*(bl-bh); i.e., it's certainly enough for the final result,
but it's vaguely possible that adding in the "artificially" large k may
overflow that temporarily.  If so, an assert will trigger in the debug
build, but we'll probably compute the right result anyway(!).
Objects/longobject.c