ruby-changes:26356
From: tadf <ko1@a...>
Date: Sat, 15 Dec 2012 18:01:31 +0900 (JST)
Subject: [ruby-changes:26356] tadf:r38407 (trunk): * ratioanl.c (float_rationalize): reduced.
tadf 2012-12-15 18:01:22 +0900 (Sat, 15 Dec 2012) New Revision: 38407 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38407 Log: * ratioanl.c (float_rationalize): reduced. Modified files: trunk/ChangeLog trunk/rational.c Index: ChangeLog =================================================================== --- ChangeLog (revision 38406) +++ ChangeLog (revision 38407) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Dec 15 18:00:00 2012 Tadayoshi Funaba <tadf@d...> + + * ratioanl.c (float_rationalize): reduced. + Sat Dec 15 14:18:44 2012 KOSAKI Motohiro <kosaki.motohiro@g...> * io.c (finish_writeconv): uses rb_write_internal2 if Index: rational.c =================================================================== --- rational.c (revision 38406) +++ rational.c (revision 38407) @@ -1935,17 +1935,25 @@ float_rationalize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/rational.c#L1935 return rb_rational_new1(f_lshift(f, n)); #if FLT_RADIX == 2 - a = rb_rational_new2(f_sub(f_mul(TWO, f), ONE), - f_lshift(ONE, f_sub(ONE, n))); - b = rb_rational_new2(f_add(f_mul(TWO, f), ONE), - f_lshift(ONE, f_sub(ONE, n))); + { + VALUE two_times_f, den; + + two_times_f = f_mul(TWO, f); + den = f_lshift(ONE, f_sub(ONE, n)); + + a = rb_rational_new2(f_sub(two_times_f, ONE), den); + b = rb_rational_new2(f_add(two_times_f, ONE), den); + } #else - a = rb_rational_new2(f_sub(f_mul(INT2FIX(FLT_RADIX), f), - INT2FIX(FLT_RADIX - 1)), - f_expt(INT2FIX(FLT_RADIX), f_sub(ONE, n))); - b = rb_rational_new2(f_add(f_mul(INT2FIX(FLT_RADIX), f), - INT2FIX(FLT_RADIX - 1)), - f_expt(INT2FIX(FLT_RADIX), f_sub(ONE, n))); + { + VALUE radix_times_f, den; + + radix_times_f = f_mul(INT2FIX(FLT_RADIX), f); + den = f_expt(INT2FIX(FLT_RADIX), f_sub(ONE, n)); + + a = rb_rational_new2(f_sub(radix_times_f, INT2FIX(FLT_RADIX - 1)), den); + b = rb_rational_new2(f_add(radix_times_f, INT2FIX(FLT_RADIX - 1)), den); + } #endif } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/