1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2008-03-13 16:37:54 +00:00
parent cb912bc64d
commit c7bea6f6e7
3 changed files with 25 additions and 14 deletions

View file

@ -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.

View file

@ -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);
}

View file

@ -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[];