ruby-changes:4317
From: ko1@a...
Date: Wed, 19 Mar 2008 22:29:24 +0900 (JST)
Subject: [ruby-changes:4317] tadf - Ruby:r15807 (trunk): added rb_gcd.
tadf 2008-03-19 22:29:04 +0900 (Wed, 19 Mar 2008)
New Revision: 15807
Modified files:
trunk/ChangeLog
trunk/complex.c
trunk/rational.c
Log:
added rb_gcd.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/complex.c?r1=15807&r2=15806&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15807&r2=15806&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/rational.c?r1=15807&r2=15806&diff_format=u
Index: complex.c
===================================================================
--- complex.c (revision 15806)
+++ complex.c (revision 15807)
@@ -813,88 +813,15 @@
return f_boolcast(!nucomp_exact_p(self));
}
-inline static long
-i_gcd(long x, long y)
-{
- long b;
+extern VALUE rb_gcd(VALUE x, VALUE y);
- if (x < 0)
- x = -x;
- if (y < 0)
- y = -y;
-
- if (x == 0)
- return y;
- if (y == 0)
- return x;
-
- b = 0;
- while ((x & 1) == 0 && (y & 1) == 0) {
- b += 1;
- x >>= 1;
- y >>= 1;
- }
-
- while ((x & 1) == 0)
- x >>= 1;
-
- while ((y & 1) == 0)
- y >>= 1;
-
- while (x != y) {
- if (y > x) {
- long t;
- t = x;
- x = y;
- y = t;
- }
- x -= y;
- while ((x & 1) == 0)
- x >>= 1;
- }
-
- return x << b;
-}
-
-inline static VALUE
-f_gcd(VALUE x, VALUE y)
-{
- VALUE z;
-
- if (FIXNUM_P(x) && FIXNUM_P(y))
- return LONG2NUM(i_gcd(FIX2LONG(x), FIX2LONG(y)));
-
- if (f_negative_p(x))
- x = f_negate(x);
- if (f_negative_p(y))
- y = f_negate(y);
-
- if (f_zero_p(x))
- return y;
- if (f_zero_p(y))
- return x;
-
- for (;;) {
- if (FIXNUM_P(x)) {
- if (FIX2INT(x) == 0)
- return y;
- if (FIXNUM_P(y))
- return LONG2NUM(i_gcd(FIX2LONG(x), FIX2LONG(y)));
- }
- z = x;
- x = f_mod(y, x);
- y = z;
- }
- /* NOTREACHED */
-}
-
static VALUE
f_lcm(VALUE x, VALUE y)
{
if (f_zero_p(x) || f_zero_p(y))
return ZERO;
else
- return f_abs(f_mul(f_div(x, f_gcd(x, y)), y));
+ return f_abs(f_mul(f_div(x, rb_gcd(x, y)), y));
}
static VALUE
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15806)
+++ ChangeLog (revision 15807)
@@ -1,3 +1,15 @@
+Wed Mar 19 22:27:41 2008 Tadayoshi Funaba <tadf@d...>
+
+ * rational.c: added rb_gcd.
+
+ * complex.c: use rb_gcd.
+
+Wed Mar 19 18:37:00 2008 Tadayoshi Funaba <tadf@d...>
+
+ * complex.c: revert.
+
+ * rational.c: revert.
+
Wed Mar 19 17:31:20 2008 Yukihiro Matsumoto <matz@r...>
* eval_intern.h (TH_EXEC_TAG): need not to FLUSH_REGISTER_WINDOWS.
Index: rational.c
===================================================================
--- rational.c (revision 15806)
+++ rational.c (revision 15807)
@@ -133,6 +133,12 @@
/* NOTREACHED */
}
+VALUE
+rb_gcd(VALUE x, VALUE y)
+{
+ return f_gcd(x, y);
+}
+
#define get_dat1(x) \
struct RRational *dat;\
dat = ((struct RRational *)(x))
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/