summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-09 02:31:23 (GMT)
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-09 02:31:23 (GMT)
commitc56edb9a59488f5efb6b6cbe02ac9db10bc0e6d3 (patch)
tree13bb3e499ace099af85fe5679e763f5fba3a16de /numeric.c
parent35fde4da0bef35b1f0e240549ed3307a3f0c0fca (diff)
revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]
This commit is auto-generated using following command: svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/numeric.c b/numeric.c
index c728e30..3d2b501 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1279,7 +1279,10 @@ flo_mod(VALUE x, VALUE y)
static VALUE
dbl2ival(double d)
{
- return rb_dbl2ival(d);
+ if (FIXABLE(d)) {
+ return LONG2FIX((long)d);
+ }
+ return rb_dbl2big(d);
}
/*
@@ -1964,6 +1967,7 @@ static VALUE
flo_floor(int argc, VALUE *argv, VALUE num)
{
double number, f;
+ long val;
int ndigits = 0;
if (rb_check_arity(argc, 0, 1)) {
@@ -1980,7 +1984,11 @@ flo_floor(int argc, VALUE *argv, VALUE num)
return DBL2NUM(f);
}
f = floor(number);
- return dbl2ival(f);
+ if (!FIXABLE(f)) {
+ return rb_dbl2big(f);
+ }
+ val = (long)f;
+ return LONG2FIX(val);
}
/*
@@ -2319,11 +2327,16 @@ static VALUE
flo_to_i(VALUE num)
{
double f = RFLOAT_VALUE(num);
+ long val;
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
- return dbl2ival(f);
+ if (!FIXABLE(f)) {
+ return rb_dbl2big(f);
+ }
+ val = (long)f;
+ return LONG2FIX(val);
}
/*
@@ -3008,15 +3021,12 @@ rb_num2fix(VALUE val)
{
long v;
- if (FIXNUM_P(val)) {
- return val;
- }
- else if (rb_long_is_fixable_p(v = rb_num2long(val))) {
- return LONG2FIX(v);
- }
- else {
+ if (FIXNUM_P(val)) return val;
+
+ v = rb_num2long(val);
+ if (!FIXABLE(v))
rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
- }
+ return LONG2FIX(v);
}
#if HAVE_LONG_LONG