summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/complex.c b/complex.c
index 1644746360..58704110ce 100644
--- a/complex.c
+++ b/complex.c
@@ -85,22 +85,6 @@ f_add(VALUE x, VALUE y)
}
inline static VALUE
-f_cmp(VALUE x, VALUE y)
-{
- VALUE r;
- if (FIXNUM_P(x) && FIXNUM_P(y)) {
- long c = FIX2LONG(x) - FIX2LONG(y);
- if (c > 0)
- c = 1;
- else if (c < 0)
- c = -1;
- r = INT2FIX(c);
- } else
- r = rb_funcall(x, id_cmp, 1, y);
- return r;
-}
-
-inline static VALUE
f_div(VALUE x, VALUE y)
{
VALUE r;
@@ -200,6 +184,22 @@ fun1(to_r)
fun1(to_s)
fun1(truncate)
+inline static VALUE
+f_cmp(VALUE x, VALUE y)
+{
+ VALUE r;
+ if (FIXNUM_P(x) && FIXNUM_P(y)) {
+ long c = FIX2LONG(x) - FIX2LONG(y);
+ if (c > 0)
+ c = 1;
+ else if (c < 0)
+ c = -1;
+ r = INT2FIX(c);
+ } else
+ r = rb_funcall(x, id_cmp, 1, y);
+ return r;
+}
+
fun2(coerce)
fun2(divmod)
@@ -1016,13 +1016,22 @@ nucomp_inexact_p(VALUE self)
return f_boolcast(!nucomp_exact_p(self));
}
-extern VALUE rb_lcm(VALUE x, VALUE y);
+extern VALUE rb_gcd(VALUE x, VALUE y);
+
+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, rb_gcd(x, y)), y));
+}
static VALUE
nucomp_denominator(VALUE self)
{
get_dat1(self);
- return rb_lcm(f_denominator(dat->real), f_denominator(dat->image));
+ return f_lcm(f_denominator(dat->real), f_denominator(dat->image));
}
static VALUE