mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
complex.c: check type
* complex.c (m_cos, m_sin): determine the type by the internal type, not by a method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b31ba1056e
commit
c31f6285c7
2 changed files with 16 additions and 2 deletions
|
@ -486,7 +486,7 @@ imp1(sinh)
|
|||
static VALUE
|
||||
m_cos(VALUE x)
|
||||
{
|
||||
if (f_real_p(x))
|
||||
if (!RB_TYPE_P(x, T_COMPLEX))
|
||||
return m_cos_bang(x);
|
||||
{
|
||||
get_dat1(x);
|
||||
|
@ -501,7 +501,7 @@ m_cos(VALUE x)
|
|||
static VALUE
|
||||
m_sin(VALUE x)
|
||||
{
|
||||
if (f_real_p(x))
|
||||
if (!RB_TYPE_P(x, T_COMPLEX))
|
||||
return m_sin_bang(x);
|
||||
{
|
||||
get_dat1(x);
|
||||
|
|
|
@ -970,4 +970,18 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_equal(obj, c.real)
|
||||
assert_equal(-1, c.imag)
|
||||
end
|
||||
|
||||
def test_canonicalize_polar
|
||||
obj = Class.new(Numeric) do
|
||||
def initialize
|
||||
@x = 2
|
||||
end
|
||||
def real?
|
||||
(@x -= 1) > 0
|
||||
end
|
||||
end.new
|
||||
assert_raise(TypeError) do
|
||||
Complex.polar(1, obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue