diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-13 16:37:54 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-13 16:37:54 +0000 |
commit | c7bea6f6e7a17150424d30439f5548e2176bd2b2 (patch) | |
tree | ed552b03955c01f09763b5e0907df2f2a774555d /numeric.c | |
parent | cb912bc64d7ad55f7180ca8039923489eb6bfa06 (diff) | |
download | ruby-c7bea6f6e7a17150424d30439f5548e2176bd2b2.tar.gz |
* numeric.c (fix_divmod): should return integer division. [ruby-dev:34006]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -708,6 +708,22 @@ flo_mod(VALUE x, VALUE y) return DOUBLE2NUM(mod); } +static VALUE +dbl2ival(double d) +{ + if (FIXABLE(d)) { + d = round(d); + return LONG2FIX((long)d); + } + else if (isnan(d) || isinf(d)) { + /* special case: cannot return integer value */ + return rb_float_new(d); + } + else { + return rb_dbl2big(d); + } +} + /* * call-seq: * flt.divmod(numeric) => array @@ -735,16 +751,7 @@ flo_divmod(VALUE x, VALUE y) return rb_num_coerce_bin(x, y, rb_intern("divmod")); } flodivmod(RFLOAT_VALUE(x), fy, &div, &mod); - if (FIXABLE(div)) { - val = round(div); - a = LONG2FIX(val); - } - else if (isnan(div) || isinf(div)) { - a = rb_float_new(div); - } - else { - a = rb_dbl2big(div); - } + a = dbl2ival(div); b = DOUBLE2NUM(mod); return rb_assoc_new(a, b); } @@ -2319,7 +2326,7 @@ fix_divmod(VALUE x, VALUE y) volatile VALUE a, b; flodivmod((double)FIX2LONG(x), RFLOAT_VALUE(y), &div, &mod); - a = DOUBLE2NUM(div); + a = dbl2ival(div); b = DOUBLE2NUM(mod); return rb_assoc_new(a, b); } |