* complex.c (nucomp_div): [ruby-dev:34357]
* complex.c (nucomp_abs): use hypot. * complex.c (nucomp_quo): do not force convertion. * test/ruby/test_complex.rb: omitted some meaningless tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fee4ed204f
commit
6d02a4857d
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Tue Apr 15 07:21:21 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* complex.c (nucomp_div): [ruby-dev:34357]
|
||||||
|
|
||||||
|
* complex.c (nucomp_abs): use hypot.
|
||||||
|
|
||||||
|
* complex.c (nucomp_quo): do not force convertion.
|
||||||
|
|
||||||
|
* test/ruby/test_complex.rb: omitted some meaningless tests.
|
||||||
|
|
||||||
Mon Apr 14 23:25:50 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
Mon Apr 14 23:25:50 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* test/ruby/test_objectspace.rb: add a test for
|
* test/ruby/test_objectspace.rb: add a test for
|
||||||
|
23
complex.c
23
complex.c
@ -478,6 +478,7 @@ extern VALUE math_atan2(VALUE obj, VALUE x, VALUE y);
|
|||||||
extern VALUE math_cos(VALUE obj, VALUE x);
|
extern VALUE math_cos(VALUE obj, VALUE x);
|
||||||
extern VALUE math_cosh(VALUE obj, VALUE x);
|
extern VALUE math_cosh(VALUE obj, VALUE x);
|
||||||
extern VALUE math_exp(VALUE obj, VALUE x);
|
extern VALUE math_exp(VALUE obj, VALUE x);
|
||||||
|
extern VALUE math_hypot(VALUE obj, VALUE x, VALUE y);
|
||||||
extern VALUE math_log(int argc, VALUE *argv);
|
extern VALUE math_log(int argc, VALUE *argv);
|
||||||
extern VALUE math_sin(VALUE obj, VALUE x);
|
extern VALUE math_sin(VALUE obj, VALUE x);
|
||||||
extern VALUE math_sinh(VALUE obj, VALUE x);
|
extern VALUE math_sinh(VALUE obj, VALUE x);
|
||||||
@ -487,6 +488,7 @@ extern VALUE math_sqrt(VALUE obj, VALUE x);
|
|||||||
#define m_cos_bang(x) math_cos(Qnil,x)
|
#define m_cos_bang(x) math_cos(Qnil,x)
|
||||||
#define m_cosh_bang(x) math_cosh(Qnil,x)
|
#define m_cosh_bang(x) math_cosh(Qnil,x)
|
||||||
#define m_exp_bang(x) math_exp(Qnil,x)
|
#define m_exp_bang(x) math_exp(Qnil,x)
|
||||||
|
#define m_hypot(x,y) math_hypot(Qnil,x,y)
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
m_log_bang(VALUE x)
|
m_log_bang(VALUE x)
|
||||||
@ -681,7 +683,21 @@ nucomp_div(VALUE self, VALUE other)
|
|||||||
f_div(dat->image, other));
|
f_div(dat->image, other));
|
||||||
}
|
}
|
||||||
case T_COMPLEX:
|
case T_COMPLEX:
|
||||||
|
{
|
||||||
|
get_dat2(self, other);
|
||||||
|
|
||||||
|
if (TYPE(adat->real) == T_FLOAT ||
|
||||||
|
TYPE(adat->image) == T_FLOAT ||
|
||||||
|
TYPE(bdat->real) == T_FLOAT ||
|
||||||
|
TYPE(bdat->image) == T_FLOAT) {
|
||||||
|
VALUE magn = m_hypot(bdat->real, bdat->image);
|
||||||
|
VALUE tmp = f_complex_new_bang2(CLASS_OF(self),
|
||||||
|
f_div(bdat->real, magn),
|
||||||
|
f_div(bdat->image, magn));
|
||||||
|
return f_div(f_mul(self, f_conjugate(tmp)), magn);
|
||||||
|
}
|
||||||
return f_div(f_mul(self, f_conjugate(other)), f_abs2(other));
|
return f_div(f_mul(self, f_conjugate(other)), f_abs2(other));
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return rb_num_coerce_bin(self, other, '/');
|
return rb_num_coerce_bin(self, other, '/');
|
||||||
}
|
}
|
||||||
@ -693,8 +709,8 @@ nucomp_quo(VALUE self, VALUE other)
|
|||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
|
|
||||||
return f_div(f_complex_new2(CLASS_OF(self),
|
return f_div(f_complex_new2(CLASS_OF(self),
|
||||||
f_to_r(dat->real),
|
f_quo(dat->real, ONE),
|
||||||
f_to_r(dat->image)), other);
|
f_quo(dat->image, ONE)), other);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -824,8 +840,7 @@ static VALUE
|
|||||||
nucomp_abs(VALUE self)
|
nucomp_abs(VALUE self)
|
||||||
{
|
{
|
||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
return m_sqrt(f_add(f_mul(dat->real, dat->real),
|
return m_hypot(dat->real, dat->image);
|
||||||
f_mul(dat->image, dat->image)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
2
math.c
2
math.c
@ -465,7 +465,7 @@ math_ldexp(VALUE obj, VALUE x, VALUE n)
|
|||||||
* Math.hypot(3, 4) #=> 5.0
|
* Math.hypot(3, 4) #=> 5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
math_hypot(VALUE obj, VALUE x, VALUE y)
|
math_hypot(VALUE obj, VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
Need_Float2(x, y);
|
Need_Float2(x, y);
|
||||||
|
@ -1055,6 +1055,7 @@ class Complex_Test < Test::Unit::TestCase
|
|||||||
Complex.const_set(:Unify, unify_val) if f
|
Complex.const_set(:Unify, unify_val) if f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
def test_abs
|
def test_abs
|
||||||
b = 2**100
|
b = 2**100
|
||||||
def b.*(x); self; end rescue nil
|
def b.*(x); self; end rescue nil
|
||||||
@ -1075,6 +1076,7 @@ class Complex_Test < Test::Unit::TestCase
|
|||||||
nan = inf/inf
|
nan = inf/inf
|
||||||
assert_raise(Errno::EDOM, Errno::ERANGE) { Complex(1, nan).abs }
|
assert_raise(Errno::EDOM, Errno::ERANGE) { Complex(1, nan).abs }
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
def test_coerce
|
def test_coerce
|
||||||
c = Complex(6, 3)
|
c = Complex(6, 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user