Skip to content

Commit

Permalink
* numeric.c (fix_divmod): should return integer division. [ruby-dev:3…
Browse files Browse the repository at this point in the history
…4006]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Mar 13, 2008
1 parent cb912bc commit c7bea6f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 18 additions & 11 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions version.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#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
#define RUBY_VERSION_MINOR 9
#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[];
Expand Down

0 comments on commit c7bea6f

Please sign in to comment.