Permalink
Browse files

* numeric.c (int_round): Fix Integer#round [ruby-core:39096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent ee0d942 commit 85e24491a6f2df6c764a743940651448e8d487b0 @marcandre marcandre committed Aug 24, 2011
Showing with 7 additions and 1 deletion.
  1. +4 −0 ChangeLog
  2. +3 −1 numeric.c
View
@@ -1,3 +1,7 @@
+Thu Aug 25 07:57:33 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * numeric.c (int_round): Fix Integer#round [ruby-core:39096]
+
Thu Aug 25 07:00:00 2011 Koichi Sasada <ko1@atdot.net>
* vm_insnhelper.h, vm_insnhelper.c, vm.c, vm_method.c, insns.def:
View
@@ -3298,6 +3298,7 @@ int_round(int argc, VALUE* argv, VALUE num)
{
VALUE n, f, h, r;
int ndigits;
+ ID op;
if (argc == 0) return num;
rb_scan_args(argc, argv, "1", &n);
@@ -3324,7 +3325,8 @@ int_round(int argc, VALUE* argv, VALUE num)
h = rb_funcall(f, '/', 1, INT2FIX(2));
r = rb_funcall(num, '%', 1, f);
n = rb_funcall(num, '-', 1, r);
- if (!RTEST(rb_funcall(r, '<', 1, h))) {
+ op = RTEST(rb_funcall(num, '<', 1, INT2FIX(0))) ? rb_intern("<=") : '<';
+ if (!RTEST(rb_funcall(r, op, 1, h))) {
n = rb_funcall(n, '+', 1, f);
}
return n;

0 comments on commit 85e2449

Please sign in to comment.