Created
August 1, 2011 23:53
-
-
Save shirok/1119272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/number.c | |
+++ b/src/number.c | |
@@ -37,6 +37,7 @@ | |
#include "gauche/scmconst.h" | |
#include "gauche/bits.h" | |
#include "gauche/builtin-syms.h" | |
+#include "gauche/arith.h" | |
#include <limits.h> | |
#include <float.h> | |
@@ -1810,9 +1811,9 @@ static ScmObj scm_mul(ScmObj arg0, ScmObj arg1, int vmp) | |
if (SCM_INTP(arg1)) { | |
long v0 = SCM_INT_VALUE(arg0); | |
long v1 = SCM_INT_VALUE(arg1); | |
- long k = v0 * v1; | |
- /* TODO: need a better way to check overflow */ | |
- if ((v1 != 0 && k/v1 != v0) || !SCM_SMALL_INT_FITS(k)) { | |
+ long k; int ov; | |
+ SMULOV(k, ov, v0, v1); | |
+ if (ov || !SCM_SMALL_INT_FITS(k)) { | |
ScmObj big = Scm_MakeBignumFromSI(v0); | |
return Scm_BignumMulSI(SCM_BIGNUM(big), v1); | |
} else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment