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

rational.c: optimize Rational#to_i

* rational.c (nurat_truncate): optimize Rational#to_i.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2016-11-12 06:58:35 +00:00
parent 9bb3022475
commit 05ff2fe4f3

View file

@ -1243,9 +1243,9 @@ static VALUE
nurat_truncate(VALUE self)
{
get_dat1(self);
if (f_negative_p(dat->num))
return f_negate(f_idiv(f_negate(dat->num), dat->den));
return f_idiv(dat->num, dat->den);
if (INT_NEGATIVE_P(dat->num))
return rb_int_uminus(rb_int_idiv(rb_int_uminus(dat->num), dat->den));
return rb_int_idiv(dat->num, dat->den);
}
static VALUE