[前][次][番号順一覧][スレッド一覧]

ruby-changes:56763

From: Nobuyoshi <ko1@a...>
Date: Fri, 2 Aug 2019 18:13:21 +0900 (JST)
Subject: [ruby-changes:56763] Nobuyoshi Nakada: 6640eeb6db (master): Deduplicate common code

https://git.ruby-lang.org/ruby.git/commit/?id=6640eeb6db

From 6640eeb6dbcf2c5d721ebd005001f3f43f03ab53 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 2 Aug 2019 18:11:05 +0900
Subject: Deduplicate common code


diff --git a/rational.c b/rational.c
index fdaf4d6..be5e38c 100644
--- a/rational.c
+++ b/rational.c
@@ -2247,27 +2247,19 @@ rb_flt_rationalize(VALUE flt) https://github.com/ruby/ruby/blob/trunk/rational.c#L2247
     if (INT_ZERO_P(f) || FIX2INT(n) >= 0)
         return rb_rational_new1(rb_int_lshift(f, n));
 
-#if FLT_RADIX == 2
-    {
-        VALUE two_times_f, den;
-
-        two_times_f = rb_int_mul(TWO, f);
-        den = rb_int_lshift(ONE, rb_int_minus(ONE, n));
-
-        a = rb_rational_new2(rb_int_minus(two_times_f, ONE), den);
-        b = rb_rational_new2(rb_int_plus(two_times_f, ONE), den);
-    }
-#else
     {
         VALUE radix_times_f, den;
 
         radix_times_f = rb_int_mul(INT2FIX(FLT_RADIX), f);
-        den = rb_int_pow(INT2FIX(FLT_RADIX), rb_int_minus(ONE, n));
+#if FLT_RADIX == 2 && 0
+        den = rb_int_lshift(ONE, INT2FIX(1-FIX2INT(n)));
+#else
+        den = rb_int_positive_pow(FLT_RADIX, 1-FIX2INT(n));
+#endif
 
         a = rb_rational_new2(rb_int_minus(radix_times_f, INT2FIX(FLT_RADIX - 1)), den);
         b = rb_rational_new2(rb_int_plus(radix_times_f, INT2FIX(FLT_RADIX - 1)), den);
     }
-#endif
 
     if (nurat_eqeq_p(a, b))
         return float_to_r(flt);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]