From acde7364f707cc831a79fd7a221635d4ec8648a4 Mon Sep 17 00:00:00 2001 From: tadf Date: Tue, 16 Sep 2008 22:04:19 +0000 Subject: [PATCH] * numeric.c: provides predicate real? instead of scalar?. * complex.c: follows the above change. * lib/cmath.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ complex.c | 11 ++++------- lib/cmath.rb | 34 +++++++++++++++++----------------- numeric.c | 8 ++++---- test/ruby/test_complex.rb | 10 ++++++---- test/ruby/test_numeric.rb | 4 ++-- test/ruby/test_rational.rb | 10 ++++++---- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58b7921c2797a0..3e074eaeb54b8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Sep 17 06:58:31 2008 Tadayoshi Funaba + + * numeric.c: provides predicate real? instead of scalar?. + + * complex.c: follows the above change. + + * lib/cmath.c: ditto. + Wed Sep 17 01:56:27 2008 Tanaka Akira * test/ruby/test_io_m17n.rb: use __FILE__ instead of /dev/null. diff --git a/complex.c b/complex.c index 0ed8a2c45c3108..fd7d1a9ee64441 100644 --- a/complex.c +++ b/complex.c @@ -24,7 +24,7 @@ VALUE rb_cComplex; static ID id_Unify, id_abs, id_abs2, id_arg, id_cmp, id_conjugate, id_convert, id_denominator, id_divmod, id_equal_p, id_exact_p, id_expt, id_floor, id_hash, id_idiv, id_inspect, id_negate, id_new, id_new_bang, - id_numerator, id_polar, id_quo, id_scalar_p, id_to_f, id_to_i, id_to_r, + id_numerator, id_polar, id_quo, id_real_p, id_to_f, id_to_i, id_to_r, id_to_s, id_truncate; #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -168,9 +168,7 @@ fun1(inspect) fun1(negate) fun1(numerator) fun1(polar) -fun1(scalar_p) - -#define f_real_p f_scalar_p +fun1(real_p) fun1(to_f) fun1(to_i) @@ -1383,7 +1381,7 @@ Init_Complex(void) id_numerator = rb_intern("numerator"); id_polar = rb_intern("polar"); id_quo = rb_intern("quo"); - id_scalar_p = rb_intern("scalar?"); + id_real_p = rb_intern("real?"); id_to_f = rb_intern("to_f"); id_to_i = rb_intern("to_i"); id_to_r = rb_intern("to_r"); @@ -1459,13 +1457,12 @@ Init_Complex(void) rb_define_method(rb_cComplex, "~", nucomp_conjugate, 0); /* gcc */ #endif -#if 0 rb_define_method(rb_cComplex, "real?", nucomp_false, 0); +#if 0 rb_define_method(rb_cComplex, "complex?", nucomp_true, 0); 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_false, 0); rb_define_method(rb_cComplex, "numerator", nucomp_numerator, 0); rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0); diff --git a/lib/cmath.rb b/lib/cmath.rb index 55995879e6f218..795558c59b5f17 100644 --- a/lib/cmath.rb +++ b/lib/cmath.rb @@ -25,7 +25,7 @@ module CMath alias atanh! atanh def exp(z) - if z.scalar? + if z.real? exp!(z) else Complex(exp!(z.real) * cos!(z.image), @@ -35,7 +35,7 @@ def exp(z) def log(*args) z, b = args - if z.scalar? and z >= 0 and (b.nil? or b >= 0) + if z.real? and z >= 0 and (b.nil? or b >= 0) log!(*args) else r, theta = z.polar @@ -48,7 +48,7 @@ def log(*args) end def log10(z) - if z.scalar? + if z.real? log10!(z) else log(z) / log!(10) @@ -56,7 +56,7 @@ def log10(z) end def sqrt(z) - if z.scalar? + if z.real? if z >= 0 sqrt!(z) else @@ -74,7 +74,7 @@ def sqrt(z) end def sin(z) - if z.scalar? + if z.real? sin!(z) else Complex(sin!(z.real) * cosh!(z.image), @@ -83,7 +83,7 @@ def sin(z) end def cos(z) - if z.scalar? + if z.real? cos!(z) else Complex(cos!(z.real) * cosh!(z.image), @@ -92,7 +92,7 @@ def cos(z) end def tan(z) - if z.scalar? + if z.real? tan!(z) else sin(z)/cos(z) @@ -100,7 +100,7 @@ def tan(z) end def sinh(z) - if z.scalar? + if z.real? sinh!(z) else Complex(sinh!(z.real) * cos!(z.image), @@ -109,7 +109,7 @@ def sinh(z) end def cosh(z) - if z.scalar? + if z.real? cosh!(z) else Complex(cosh!(z.real) * cos!(z.image), @@ -118,7 +118,7 @@ def cosh(z) end def tanh(z) - if z.scalar? + if z.real? tanh!(z) else sinh(z) / cosh(z) @@ -126,7 +126,7 @@ def tanh(z) end def asin(z) - if z.scalar? and z >= -1 and z <= 1 + if z.real? and z >= -1 and z <= 1 asin!(z) else -1.0.im * log(1.0.im * z + sqrt(1.0 - z * z)) @@ -134,7 +134,7 @@ def asin(z) end def acos(z) - if z.scalar? and z >= -1 and z <= 1 + if z.real? and z >= -1 and z <= 1 acos!(z) else -1.0.im * log(z + 1.0.im * sqrt(1.0 - z * z)) @@ -142,7 +142,7 @@ def acos(z) end def atan(z) - if z.scalar? + if z.real? atan!(z) else 1.0.im * log((1.0.im + z) / (1.0.im - z)) / 2.0 @@ -150,7 +150,7 @@ def atan(z) end def atan2(y,x) - if y.scalar? and x.scalar? + if y.real? and x.real? atan2!(y,x) else -1.0.im * log((x + 1.0.im * y) / sqrt(x * x + y * y)) @@ -158,7 +158,7 @@ def atan2(y,x) end def acosh(z) - if z.scalar? and z >= 1 + if z.real? and z >= 1 acosh!(z) else log(z + sqrt(z * z - 1.0)) @@ -166,7 +166,7 @@ def acosh(z) end def asinh(z) - if z.scalar? + if z.real? asinh!(z) else log(z + sqrt(1.0 + z * z)) @@ -174,7 +174,7 @@ def asinh(z) end def atanh(z) - if z.scalar? and z >= -1 and z <= 1 + if z.real? and z >= -1 and z <= 1 atanh!(z) else log((1.0 + z) / (1.0 - z)) / 2.0 diff --git a/numeric.c b/numeric.c index 45e17d2801ef55..6301adecd67343 100644 --- a/numeric.c +++ b/numeric.c @@ -385,14 +385,14 @@ num_remainder(VALUE x, VALUE y) /* * call-seq: - * num.scalar? -> true or false + * num.real? -> true or false * - * Returns true if num is an Scalar + * Returns true if num is a Real * (i.e. non Complex). */ static VALUE -num_scalar_p(VALUE num) +num_real_p(VALUE num) { return Qtrue; } @@ -3145,7 +3145,7 @@ Init_Numeric(void) rb_define_method(rb_cNumeric, "magnitude", num_abs, 0); rb_define_method(rb_cNumeric, "to_int", num_to_int, 0); - rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0); + rb_define_method(rb_cNumeric, "real?", num_real_p, 0); rb_define_method(rb_cNumeric, "integer?", num_int_p, 0); rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0); rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0); diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index af2311ca00c437..6a5eb0c4843c5b 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -243,7 +243,6 @@ def test_attr2 c = Complex(1) if defined?(Complex::Unify) - assert_equal(true, c.scalar?) =begin assert_equal(true, c.finite?) assert_equal(false, c.infinite?) @@ -251,13 +250,14 @@ def test_attr2 assert_equal(true, c.integer?) assert_equal(false, c.float?) assert_equal(true, c.rational?) +=end assert_equal(true, c.real?) +=begin assert_equal(false, c.complex?) assert_equal(true, c.exact?) assert_equal(false, c.inexact?) =end else - assert_equal(false, c.scalar?) =begin assert_equal(true, c.finite?) assert_equal(false, c.infinite?) @@ -265,7 +265,9 @@ def test_attr2 assert_equal(false, c.integer?) assert_equal(false, c.float?) assert_equal(false, c.rational?) +=end assert_equal(false, c.real?) +=begin assert_equal(true, c.complex?) assert_equal(true, c.exact?) assert_equal(false, c.inexact?) @@ -882,8 +884,8 @@ def test_prec end def test_supp - assert_equal(true, 1.scalar?) - assert_equal(true, 1.1.scalar?) + assert_equal(true, 1.real?) + assert_equal(true, 1.1.real?) assert_equal(1, 1.real) assert_equal(0, 1.image) diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 3db054fdae6c22..0dd7b2e99cb0d4 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -72,8 +72,8 @@ def %(x); :mod; end end end - def test_scalar_p - assert(Numeric.new.scalar?) + def test_real_p + assert(Numeric.new.real?) end def test_integer_p diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index de8c31dbc5140c..a3515759210f49 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -249,7 +249,6 @@ def test_attr2 c = Rational(1) if defined?(Rational::Unify) - assert_equal(true, c.scalar?) =begin assert_equal(true, c.finite?) assert_equal(false, c.infinite?) @@ -257,13 +256,14 @@ def test_attr2 assert_equal(true, c.integer?) assert_equal(false, c.float?) assert_equal(true, c.rational?) +=end assert_equal(true, c.real?) +=begin assert_equal(false, c.complex?) assert_equal(true, c.exact?) assert_equal(false, c.inexact?) =end else - assert_equal(true, c.scalar?) =begin assert_equal(true, c.finite?) assert_equal(false, c.infinite?) @@ -271,7 +271,9 @@ def test_attr2 assert_equal(false, c.integer?) assert_equal(false, c.float?) assert_equal(true, c.rational?) +=end assert_equal(true, c.real?) +=begin assert_equal(false, c.complex?) assert_equal(true, c.exact?) assert_equal(false, c.inexact?) @@ -1054,8 +1056,8 @@ def test_gcdlcm end def test_supp - assert_equal(true, 1.scalar?) - assert_equal(true, 1.1.scalar?) + assert_equal(true, 1.real?) + assert_equal(true, 1.1.real?) assert_equal(1, 1.numerator) assert_equal(9, 9.numerator)