summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/numeric.c b/numeric.c
index e9f72a1943..a6ab555991 100644
--- a/numeric.c
+++ b/numeric.c
@@ -794,14 +794,32 @@ static VALUE
rb_int_induced_from(klass, x)
VALUE klass, x;
{
- return rb_funcall(x, rb_intern("to_i"), 0);
+ switch (TYPE(x)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ return x;
+ case T_FLOAT:
+ return rb_funcall(x, rb_intern("to_i"), 0);
+ default:
+ rb_raise(rb_eTypeError, "failed to convert %s into Integer",
+ rb_class2name(CLASS_OF(x)));
+ }
}
static VALUE
rb_flo_induced_from(klass, x)
VALUE klass, x;
{
- return rb_funcall(x, rb_intern("to_f"), 0);
+ switch (TYPE(x)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ return rb_funcall(x, rb_intern("to_f"), 0);
+ case T_FLOAT:
+ return x;
+ default:
+ rb_raise(rb_eTypeError, "failed to convert %s into Float",
+ rb_class2name(CLASS_OF(x)));
+ }
}
static VALUE