summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-16 22:04:19 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-16 22:04:19 +0000
commitacde7364f707cc831a79fd7a221635d4ec8648a4 (patch)
tree79f122b6a5a5182b2d715363c9045f36582e9d42
parentd9d3781de0cfac4d0fa5e2dd9c920f7c66a77a3f (diff)
* 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
-rw-r--r--ChangeLog8
-rw-r--r--complex.c11
-rw-r--r--lib/cmath.rb34
-rw-r--r--numeric.c8
-rw-r--r--test/ruby/test_complex.rb10
-rw-r--r--test/ruby/test_numeric.rb4
-rw-r--r--test/ruby/test_rational.rb10
7 files changed, 47 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 58b7921c27..3e074eaeb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Sep 17 06:58:31 2008 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * 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 <akr@fsij.org>
* test/ruby/test_io_m17n.rb: use __FILE__ instead of /dev/null.
diff --git a/complex.c b/complex.c
index 0ed8a2c45c..fd7d1a9ee6 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 55995879e6..795558c59b 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 @@ module CMath
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 @@ module CMath
end
def log10(z)
- if z.scalar?
+ if z.real?
log10!(z)
else
log(z) / log!(10)
@@ -56,7 +56,7 @@ module CMath
end
def sqrt(z)
- if z.scalar?
+ if z.real?
if z >= 0
sqrt!(z)
else
@@ -74,7 +74,7 @@ module CMath
end
def sin(z)
- if z.scalar?
+ if z.real?
sin!(z)
else
Complex(sin!(z.real) * cosh!(z.image),
@@ -83,7 +83,7 @@ module CMath
end
def cos(z)
- if z.scalar?
+ if z.real?
cos!(z)
else
Complex(cos!(z.real) * cosh!(z.image),
@@ -92,7 +92,7 @@ module CMath
end
def tan(z)
- if z.scalar?
+ if z.real?
tan!(z)
else
sin(z)/cos(z)
@@ -100,7 +100,7 @@ module CMath
end
def sinh(z)
- if z.scalar?
+ if z.real?
sinh!(z)
else
Complex(sinh!(z.real) * cos!(z.image),
@@ -109,7 +109,7 @@ module CMath
end
def cosh(z)
- if z.scalar?
+ if z.real?
cosh!(z)
else
Complex(cosh!(z.real) * cos!(z.image),
@@ -118,7 +118,7 @@ module CMath
end
def tanh(z)
- if z.scalar?
+ if z.real?
tanh!(z)
else
sinh(z) / cosh(z)
@@ -126,7 +126,7 @@ module CMath
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 @@ module CMath
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 @@ module CMath
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 @@ module CMath
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 @@ module CMath
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 @@ module CMath
end
def asinh(z)
- if z.scalar?
+ if z.real?
asinh!(z)
else
log(z + sqrt(1.0 + z * z))
@@ -174,7 +174,7 @@ module CMath
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 45e17d2801..6301adecd6 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 <code>true</code> if <i>num</i> is an <code>Scalar</code>
+ * Returns <code>true</code> if <i>num</i> is a <code>Real</code>
* (i.e. non <code>Complex</code>).
*/
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 af2311ca00..6a5eb0c484 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -243,7 +243,6 @@ class Complex_Test < Test::Unit::TestCase
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 @@ class Complex_Test < Test::Unit::TestCase
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 @@ class Complex_Test < Test::Unit::TestCase
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 @@ class Complex_Test < Test::Unit::TestCase
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 3db054fdae..0dd7b2e99c 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -72,8 +72,8 @@ class TestNumeric < Test::Unit::TestCase
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 de8c31dbc5..a351575921 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -249,7 +249,6 @@ class Rational_Test < Test::Unit::TestCase
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 @@ class Rational_Test < Test::Unit::TestCase
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 @@ class Rational_Test < Test::Unit::TestCase
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 @@ class Rational_Test < Test::Unit::TestCase
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)