ruby-changes:50548
From: nobu <ko1@a...>
Date: Wed, 7 Mar 2018 21:04:49 +0900 (JST)
Subject: [ruby-changes:50548] nobu:r62689 (trunk): complex.c: check type
nobu 2018-03-07 21:04:43 +0900 (Wed, 07 Mar 2018) New Revision: 62689 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62689 Log: complex.c: check type * complex.c (m_cos, m_sin): determine the type by the internal type, not by a method. Modified files: trunk/complex.c trunk/test/ruby/test_complex.rb Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 62688) +++ test/ruby/test_complex.rb (revision 62689) @@ -970,4 +970,18 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L970 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 Index: complex.c =================================================================== --- complex.c (revision 62688) +++ complex.c (revision 62689) @@ -486,7 +486,7 @@ imp1(sinh) https://github.com/ruby/ruby/blob/trunk/complex.c#L486 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) https://github.com/ruby/ruby/blob/trunk/complex.c#L501 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/