summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-09 09:30:25 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-09 09:30:25 +0000
commite32da15f48189cfba02a9be2e6572161d91b3122 (patch)
tree47c660015f96f23220975c71fd69e71f8a69b6ef /numeric.c
parent8673eacafa039f056927e0f91ce195afae9b9019 (diff)
1.1b9_09 pre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/numeric.c b/numeric.c
index ea90e03588..053ad10151 100644
--- a/numeric.c
+++ b/numeric.c
@@ -612,21 +612,16 @@ fail_to_integer(val)
rb_class2name(CLASS_OF(val)));
}
-int
+INT
num2int(val)
VALUE val;
{
- if (NIL_P(val)) return 0;
+ if (NIL_P(val)) {
+ TypeError("no implicit conversion from nil");
+ }
switch (TYPE(val)) {
case T_FIXNUM:
- if (sizeof(int) < sizeof(INT)) {
- INT i = FIX2INT(val);
- if (INT_MIN < i && i < INT_MAX) {
- return i;
- }
- TypeError("Fixnum too big to convert into `int'");
- }
return FIX2INT(val);
case T_FLOAT:
@@ -645,10 +640,6 @@ num2int(val)
TypeError("no implicit conversion from string");
return Qnil; /* not reached */
- case T_NIL:
- TypeError("no implicit conversion from nil");
- return Qnil; /* not reached */
-
default:
val = rb_rescue(to_integer, val, fail_to_integer, val);
if (!obj_is_kind_of(val, cInteger)) {
@@ -664,19 +655,12 @@ num2fix(val)
{
INT v;
- if (NIL_P(val)) return INT2FIX(0);
- switch (TYPE(val)) {
- case T_FIXNUM:
- return val;
+ if (FIXNUM_P(val)) return val;
- case T_FLOAT:
- case T_BIGNUM:
- default:
- v = num2int(val);
- if (!FIXABLE(v))
- Fail("integer %d out of range of Fixnum", v);
- return INT2FIX(v);
- }
+ v = num2int(val);
+ if (!FIXABLE(v))
+ Fail("integer %d out of range of fixnum", v);
+ return INT2FIX(v);
}
static VALUE