diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-24 22:57:55 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-24 22:57:55 +0000 |
commit | 85e24491a6f2df6c764a743940651448e8d487b0 (patch) | |
tree | 6fd62bc314d98423e8c55aa97b262fbdd80f88b6 | |
parent | ee0d942ed9af59cefd7717ae456d76ebc5d2f6ee (diff) |
* 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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | numeric.c | 4 |
2 files changed, 7 insertions, 1 deletions
@@ -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: @@ -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; |