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 | |
parent | cb912bc64d7ad55f7180ca8039923489eb6bfa06 (diff) |
* 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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | numeric.c | 29 | ||||
-rw-r--r-- | version.h | 6 |
3 files changed, 25 insertions, 14 deletions
@@ -11,6 +11,10 @@ Thu Mar 13 14:14:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * trunk/string.c (hash): use inttypes.h instead of stdint.h. +Thu Mar 13 10:42:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * numeric.c (fix_divmod): should return integer division. [ruby-dev:34006] + Thu Mar 13 03:12:48 2008 Yukihiro Matsumoto <matz@ruby-lang.org> * lib/irb/cmd/help.rb: should be updated for new ri structure. @@ -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); } @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2008-03-13" +#define RUBY_RELEASE_DATE "2008-03-14" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20080313 +#define RUBY_RELEASE_CODE 20080314 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 13 +#define RUBY_RELEASE_DAY 14 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; |