mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Consider Complex from Complex cases
The assertions that "an argument of a Complex constructor must not be a Complex" may not hold for some Numeric objects.
This commit is contained in:
parent
9212d96307
commit
b5cf356447
Notes:
git
2022-09-02 14:33:56 +09:00
2 changed files with 14 additions and 12 deletions
24
complex.c
24
complex.c
|
@ -495,7 +495,11 @@ nucomp_s_new(int argc, VALUE *argv, VALUE klass)
|
|||
inline static VALUE
|
||||
f_complex_new2(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
assert(!RB_TYPE_P(x, T_COMPLEX));
|
||||
if (RB_TYPE_P(x, T_COMPLEX)) {
|
||||
get_dat1(x);
|
||||
x = dat->real;
|
||||
y = f_add(dat->imag, y);
|
||||
}
|
||||
return nucomp_s_canonicalize_internal(klass, x, y);
|
||||
}
|
||||
|
||||
|
@ -609,8 +613,14 @@ m_sin(VALUE x)
|
|||
static VALUE
|
||||
f_complex_polar(VALUE klass, VALUE x, VALUE y)
|
||||
{
|
||||
assert(!RB_TYPE_P(x, T_COMPLEX));
|
||||
assert(!RB_TYPE_P(y, T_COMPLEX));
|
||||
if (RB_TYPE_P(x, T_COMPLEX)) {
|
||||
get_dat1(x);
|
||||
x = dat->real;
|
||||
}
|
||||
if (RB_TYPE_P(y, T_COMPLEX)) {
|
||||
get_dat1(y);
|
||||
y = dat->real;
|
||||
}
|
||||
if (f_zero_p(x) || f_zero_p(y)) {
|
||||
return nucomp_s_new_internal(klass, x, RFLOAT_0);
|
||||
}
|
||||
|
@ -703,14 +713,6 @@ nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
|
|||
nucomp_real_check(arg);
|
||||
break;
|
||||
}
|
||||
if (RB_TYPE_P(abs, T_COMPLEX)) {
|
||||
get_dat1(abs);
|
||||
abs = dat->real;
|
||||
}
|
||||
if (RB_TYPE_P(arg, T_COMPLEX)) {
|
||||
get_dat1(arg);
|
||||
arg = dat->real;
|
||||
}
|
||||
return f_complex_polar(klass, abs, arg);
|
||||
}
|
||||
|
||||
|
|
|
@ -567,7 +567,7 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_raise_with_message(TypeError, /C\u{1f5ff}/) { Complex(1).coerce(obj) }
|
||||
end
|
||||
|
||||
class ObjectX
|
||||
class ObjectX < Numeric
|
||||
def initialize(real = true, n = 1) @n = n; @real = real; end
|
||||
def +(x) Rational(@n) end
|
||||
alias - +
|
||||
|
|
Loading…
Reference in a new issue