rational.c: optimize Rational#/
* rational.c (f_muldiv, nurat_div): optimize Rational#/. Author: Tadashi Saito <tad.a.digger@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
06d701a1f0
commit
bc4310718b
10
rational.c
10
rational.c
@ -812,9 +812,9 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
|
|||||||
if (k == '/') {
|
if (k == '/') {
|
||||||
VALUE t;
|
VALUE t;
|
||||||
|
|
||||||
if (f_negative_p(bnum)) {
|
if (INT_NEGATIVE_P(bnum)) {
|
||||||
anum = f_negate(anum);
|
anum = rb_int_uminus(anum);
|
||||||
bnum = f_negate(bnum);
|
bnum = rb_int_uminus(bnum);
|
||||||
}
|
}
|
||||||
t = bnum;
|
t = bnum;
|
||||||
bnum = bden;
|
bnum = bden;
|
||||||
@ -911,8 +911,8 @@ nurat_div(VALUE self, VALUE other)
|
|||||||
other, ONE, '/');
|
other, ONE, '/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (RB_TYPE_P(other, T_FLOAT))
|
else if (RB_FLOAT_TYPE_P(other))
|
||||||
return rb_funcall(f_to_f(self), '/', 1, other);
|
return DBL2NUM(nurat_to_double(self) / RFLOAT_VALUE(other));
|
||||||
else if (RB_TYPE_P(other, T_RATIONAL)) {
|
else if (RB_TYPE_P(other, T_RATIONAL)) {
|
||||||
if (f_zero_p(other))
|
if (f_zero_p(other))
|
||||||
rb_raise_zerodiv();
|
rb_raise_zerodiv();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user