summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-27 00:42:11 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-27 00:42:11 +0000
commitc94855855ed2abbfc9abd3d74ad2984d1b8ff14e (patch)
tree111fd30fd67a4d049baba70a3a36b470a7de8366 /object.c
parentcc08515cf8ed0cdb5c38bbb4ef84a110e8868cd6 (diff)
downloadruby-c94855855ed2abbfc9abd3d74ad2984d1b8ff14e.tar.gz
object.c: fixable float to fixnum
* object.c (rb_convert_to_integer): convert a fixable float to a fixnum directly without the convesion method, as well as bignum case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/object.c b/object.c
index 228b67e8f8..05bef4df28 100644
--- a/object.c
+++ b/object.c
@@ -2684,30 +2684,23 @@ rb_convert_to_integer(VALUE val, int base)
{
VALUE tmp;
- switch (TYPE(val)) {
- case T_FLOAT:
+ if (RB_FLOAT_TYPE_P(val)) {
+ double f;
if (base != 0) goto arg_error;
- if (RFLOAT_VALUE(val) <= (double)FIXNUM_MAX
- && RFLOAT_VALUE(val) >= (double)FIXNUM_MIN) {
- break;
- }
- return rb_dbl2big(RFLOAT_VALUE(val));
-
- case T_FIXNUM:
- case T_BIGNUM:
+ f = RFLOAT_VALUE(val);
+ if (FIXABLE(f)) return LONG2FIX((long)f);
+ return rb_dbl2big(f);
+ }
+ else if (RB_INTEGER_TYPE_P(val)) {
if (base != 0) goto arg_error;
return val;
-
- case T_STRING:
+ }
+ else if (RB_TYPE_P(val, T_STRING)) {
return rb_str_to_inum(val, base, TRUE);
-
- case T_NIL:
+ }
+ else if (NIL_P(val)) {
if (base != 0) goto arg_error;
rb_raise(rb_eTypeError, "can't convert nil into Integer");
- break;
-
- default:
- break;
}
if (base != 0) {
tmp = rb_check_string_type(val);