summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-15 09:01:22 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-15 09:01:22 +0000
commit81af1bd9e8b8d84860cade1b5918b1c801b57845 (patch)
tree0d381a8b301c74872c5974b577a92fb7171a6e46 /rational.c
parent985fe77356ca24e78548ca5bce61f2328c49575b (diff)
downloadruby-81af1bd9e8b8d84860cade1b5918b1c801b57845.tar.gz
* ratioanl.c (float_rationalize): reduced.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/rational.c b/rational.c
index e4201ddd18..c8d5688c94 100644
--- a/rational.c
+++ b/rational.c
@@ -1935,17 +1935,25 @@ float_rationalize(int argc, VALUE *argv, VALUE self)
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
}