ruby-changes:7648
From: tadf <ko1@a...>
Date: Sat, 6 Sep 2008 07:55:50 +0900 (JST)
Subject: [ruby-changes:7648] Ruby:r19169 (trunk): * complex.c: uses f_real_p macro.
tadf 2008-09-06 07:55:35 +0900 (Sat, 06 Sep 2008) New Revision: 19169 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19169 Log: * complex.c: uses f_real_p macro. Modified files: trunk/ChangeLog trunk/complex.c trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: complex.c =================================================================== --- complex.c (revision 19168) +++ complex.c (revision 19169) @@ -170,6 +170,9 @@ fun1(numerator) fun1(polar) fun1(scalar_p) + +#define f_real_p f_scalar_p + fun1(to_f) fun1(to_i) fun1(to_r) @@ -326,7 +329,7 @@ case T_RATIONAL: break; default: - if (!k_numeric_p(num) || !f_scalar_p(num)) + if (!k_numeric_p(num) || !f_real_p(num)) rb_raise(rb_eArgError, "not a real"); } } @@ -343,16 +346,16 @@ if (f_zero_p(image) && f_unify_p(klass)) return real; #endif - else if (f_scalar_p(real) && f_scalar_p(image)) + else if (f_real_p(real) && f_real_p(image)) return nucomp_s_new_internal(klass, real, image); - else if (f_scalar_p(real)) { + else if (f_real_p(real)) { get_dat1(image); return nucomp_s_new_internal(klass, f_sub(real, dat->image), f_add(ZERO, dat->real)); } - else if (f_scalar_p(image)) { + else if (f_real_p(image)) { get_dat1(real); return nucomp_s_new_internal(klass, @@ -455,7 +458,7 @@ { get_dat1(x); - if (f_scalar_p(x)) + if (f_real_p(x)) return m_cos_bang(x); return f_complex_new2(rb_cComplex, f_mul(m_cos_bang(dat->real), @@ -469,7 +472,7 @@ { get_dat1(x); - if (f_scalar_p(x)) + if (f_real_p(x)) return m_sin_bang(x); return f_complex_new2(rb_cComplex, f_mul(m_sin_bang(dat->real), @@ -481,7 +484,7 @@ static VALUE m_sqrt(VALUE x) { - if (f_scalar_p(x)) { + if (f_real_p(x)) { if (!f_negative_p(x)) return m_sqrt_bang(x); return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x))); @@ -543,7 +546,7 @@ return f_complex_new2(CLASS_OF(self), real, image); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_complex_new2(CLASS_OF(self), @@ -565,7 +568,7 @@ return f_complex_new2(CLASS_OF(self), real, image); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_complex_new2(CLASS_OF(self), @@ -589,7 +592,7 @@ return f_complex_new2(CLASS_OF(self), real, image); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_complex_new2(CLASS_OF(self), @@ -619,7 +622,7 @@ } return f_div(f_mul(self, f_conjugate(other)), f_abs2(other)); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_complex_new2(CLASS_OF(self), @@ -695,7 +698,7 @@ } return f_expt(f_div(f_to_r(ONE), self), f_negate(other)); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { VALUE a, r, theta; a = f_polar(self); @@ -716,7 +719,7 @@ return f_boolcast(f_equal_p(adat->real, bdat->real) && f_equal_p(adat->image, bdat->image)); } - if (k_numeric_p(other) && f_scalar_p(other)) { + if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); return f_boolcast(f_equal_p(dat->real, other) && f_zero_p(dat->image)); @@ -727,7 +730,7 @@ static VALUE nucomp_coerce(VALUE self, VALUE other) { - if (k_numeric_p(other) && f_scalar_p(other)) + if (k_numeric_p(other) && f_real_p(other)) return rb_assoc_new(f_complex_new_bang1(CLASS_OF(self), other), self); rb_raise(rb_eTypeError, "%s can't be coerced into %s", @@ -777,13 +780,13 @@ return f_complex_new2(CLASS_OF(self), dat->real, f_negate(dat->image)); } -#if 0 static VALUE nucomp_real_p(VALUE self) { return Qfalse; } +#if 0 static VALUE nucomp_complex_p(VALUE self) { @@ -952,12 +955,6 @@ } static VALUE -nucomp_scalar_p(VALUE self) -{ - return Qfalse; -} - -static VALUE nucomp_to_i(VALUE self) { get_dat1(self); @@ -1443,6 +1440,7 @@ rb_define_method(rb_cComplex, "exact?", nucomp_exact_p, 0); rb_define_method(rb_cComplex, "inexact?", nucomp_inexact_p, 0); #endif + rb_define_method(rb_cComplex, "scalar?", nucomp_real_p, 0); rb_define_method(rb_cComplex, "numerator", nucomp_numerator, 0); rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0); @@ -1457,7 +1455,6 @@ /* --- */ - rb_define_method(rb_cComplex, "scalar?", nucomp_scalar_p, 0); rb_define_method(rb_cComplex, "to_i", nucomp_to_i, 0); rb_define_method(rb_cComplex, "to_f", nucomp_to_f, 0); rb_define_method(rb_cComplex, "to_r", nucomp_to_r, 0); Index: ChangeLog =================================================================== --- ChangeLog (revision 19168) +++ ChangeLog (revision 19169) @@ -1,3 +1,7 @@ +Sat Sep 6 07:54:36 2008 Tadayoshi Funaba <tadf@d...> + + * complex.c: uses f_real_p macro. + Sat Sep 6 07:27:00 2008 Tanaka Akira <akr@f...> * transcode.c (rb_econv_open): fail for ASCII incompatible with Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 19168) +++ test/ruby/test_complex.rb (revision 19169) @@ -105,6 +105,7 @@ end def test_new + assert_instance_of(Complex, Complex.__send__(:new, 2,0.0)) if defined?(Complex::Unify) assert_instance_of(Fixnum, Complex.__send__(:new, 2,0)) else @@ -172,6 +173,9 @@ assert_equal(Complex.__send__(:new, 1),Complex(1)) assert_equal(Complex.__send__(:new, 1),Complex('1')) assert_raise(ArgumentError){Complex(nil)} + assert_raise(ArgumentError){Complex(Object.new)} + assert_raise(ArgumentError){Complex()} + assert_raise(ArgumentError){Complex(1,2,3)} end def test_attr @@ -1033,6 +1037,12 @@ end + def test_ruby19 + assert_raise(NoMethodError){ Complex.new(1) } + assert_raise(NoMethodError){ Complex.new!(1) } + assert_raise(NoMethodError){ Complex.reduce(1) } + end + def test_fixed_bug if defined?(Rational) && !Rational.instance_variable_get('@RCS_ID') assert_equal(Complex(1), 1 ** Complex(1)) Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 19168) +++ test/ruby/test_rational.rb (revision 19169) @@ -209,6 +209,8 @@ assert_raise(ArgumentError){Rational(nil)} assert_raise(ArgumentError){Rational('')} assert_raise(ArgumentError){Rational(Object.new)} + assert_raise(ArgumentError){Rational()} + assert_raise(ArgumentError){Rational(1,2,3)} end def test_attr @@ -1067,6 +1069,11 @@ assert_equal(0.25, Rational(1,2).fdiv(2)) end + def test_ruby19 + assert_raise(NoMethodError){ Rational.new(1) } + assert_raise(NoMethodError){ Rational.new!(1) } + end + def test_fixed_bug if defined?(Rational::Unify) assert_instance_of(Fixnum, Rational(1,2) ** 0) # mathn's bug -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/