1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
tadf 2008-09-16 22:04:19 +00:00
parent d9d3781de0
commit acde7364f7
7 changed files with 47 additions and 38 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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)

View file

@ -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

View file

@ -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)