math.c: C99-like atan2

* math.c (math_atan2): return values like as expected by C99 if
  both two arguments are infinity.  based on the patch by cremno
  phobia <cremno AT mail.ru> in [ruby-core:62310].  [Feature #9799]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-05-04 01:23:01 +00:00
parent 6e34259271
commit 7a6ebecf9e
5 changed files with 36 additions and 5 deletions

View file

@ -22,10 +22,15 @@ class TestMath < Test::Unit::TestCase
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) }
assert_raise(Math::DomainError) { Math.atan2(-Float::INFINITY, -Float::INFINITY) }
inf = Float::INFINITY
expected = 3.0 * Math::PI / 4.0
assert_nothing_raised { check(+expected, Math.atan2(+inf, -inf)) }
assert_nothing_raised { check(-expected, Math.atan2(-inf, -inf)) }
expected = Math::PI / 4.0
assert_nothing_raised { check(+expected, Math.atan2(+inf, +inf)) }
assert_nothing_raised { check(-expected, Math.atan2(-inf, +inf)) }
check(0, Math.atan2(0, 1))
check(Math::PI / 4, Math.atan2(1, 1))
check(Math::PI / 2, Math.atan2(1, 0))