diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2009-04-09 04:24:04 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2009-04-09 04:24:04 +0000 |
commit | 1a5281d92824bef01f3c4af8a8f343f5148041dd (patch) | |
tree | fa97d57e51b463b1ca325d4a34a006e3fc8adc02 /numpy/core | |
parent | 1287312c87ec63d1c050d8786605260230e743dd (diff) | |
download | numpy-1a5281d92824bef01f3c4af8a8f343f5148041dd.tar.gz |
Refactor PyArray_OverflowMultiplyList to make it simpler.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 1f128ccd3..54bba9d08 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -140,20 +140,25 @@ PyArray_MultiplyList(register intp *l1, register int n) * Multiply a List of Non-negative numbers with over-flow detection. */ static intp -PyArray_OverflowMultiplyList(register intp *l1, register int n) +PyArray_OverflowMultiplyList(intp *l1, int n) { - intp s = 1; + intp prod = 1; + intp imax = NPY_MAX_INTP; + int i; - while (n--) { - if (*l1 == 0) { + for (i = 0; i < n; i++) { + intp dim = l1[i]; + + if (dim == 0) { return 0; } - if ((s > MAX_INTP / *l1) || (*l1 > MAX_INTP / s)) { + if (dim > imax) { return -1; } - s *= (*l1++); + imax /= dim; + prod *= dim; } - return s; + return prod; } /*NUMPY_API |