summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index d07af84425c..527d65d2a33 100644
--- a/numeric.c
+++ b/numeric.c
@@ -588,6 +588,18 @@ num2int(val)
switch (TYPE(val)) {
case T_FIXNUM:
+ if (sizeof(int) < sizeof(INT)) {
+#ifndef INT_MAX
+/* assuming 32bit(2's compliment) int */
+# define INT_MAX 2147483647
+# define INT_MIN (- INT_MAX - 1)
+#endif
+ INT i = FIX2INT(val);
+ if (INT_MIN < i && i < INT_MAX) {
+ return i;
+ }
+ ArgError("Fixnum too big to convert into `int'");
+ }
return FIX2INT(val);
case T_FLOAT: