From 8c20f66c485649560ed6082233dbe03cdcdaf7a3 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 30 Mar 2008 14:50:55 +0000 Subject: * proc.c (proc_dup): should copy is_lambda attribute as well. [ruby-talk:296244] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'complex.c') diff --git a/complex.c b/complex.c index 164474636..58704110c 100644 --- a/complex.c +++ b/complex.c @@ -84,22 +84,6 @@ f_add(VALUE x, VALUE y) return r; } -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) { @@ -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 -- cgit