ruby-changes:17115
From: mrkn <ko1@a...>
Date: Fri, 27 Aug 2010 12:53:51 +0900 (JST)
Subject: [ruby-changes:17115] Ruby:r29115 (trunk): * math.c (math_atan2): change the behavior when x and y are zero.
mrkn 2010-08-27 12:51:56 +0900 (Fri, 27 Aug 2010) New Revision: 29115 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29115 Log: * math.c (math_atan2): change the behavior when x and y are zero. * test/ruby/test_math.rb (test_atan2): add tests for the above changes. Modified files: trunk/ChangeLog trunk/math.c trunk/test/ruby/test_math.rb Index: math.c =================================================================== --- math.c (revision 29114) +++ math.c (revision 29115) @@ -55,7 +55,13 @@ Need_Float2(y, x); dx = RFLOAT_VALUE(x); dy = RFLOAT_VALUE(y); - if (dx == 0.0 && dy == 0.0) domain_error("atan2"); + if (dx == 0.0 && dy == 0.0) { + if (!signbit(dx)) + return DBL2NUM(dy); + if (!signbit(dy)) + return DBL2NUM(M_PI); + return DBL2NUM(-M_PI); + } if (isinf(dx) && isinf(dy)) domain_error("atan2"); return DBL2NUM(atan2(dy, dx)); } Index: ChangeLog =================================================================== --- ChangeLog (revision 29114) +++ ChangeLog (revision 29115) @@ -1,3 +1,10 @@ +Fri Aug 27 12:47:44 2010 Kenta Murata <mrkn@m...> + + * math.c (math_atan2): change the behavior when x and y are zero. + + * test/ruby/test_math.rb (test_atan2): add tests for the above + changes. + Fri Aug 27 12:26:23 2010 NAKAMURA Usaku <usa@r...> * object.c (rb_obj_class): remove mention of obsolete method. Index: test/ruby/test_math.rb =================================================================== --- test/ruby/test_math.rb (revision 29114) +++ test/ruby/test_math.rb (revision 29115) @@ -17,7 +17,10 @@ end def test_atan2 - assert_raise(Math::DomainError) { Math.atan2(0, 0) } + check(+0.0, Math.atan2(+0.0, +0.0)) + check(-0.0, Math.atan2(-0.0, +0.0)) + check(+Math::PI, Math.atan2(+0.0, -0.0)) + check(-Math::PI, Math.atan2(-0.0, -0.0)) assert_raise(Math::DomainError) { Math.atan2(Float::INFINITY, Float::INFINITY) } assert_raise(Math::DomainError) { Math.atan2(Float::INFINITY, -Float::INFINITY) } assert_raise(Math::DomainError) { Math.atan2(-Float::INFINITY, Float::INFINITY) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/