From aaab3b1de943c3317e115d623ffc7908b4c96578 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 10 Mar 2021 13:15:50 -0800 Subject: Fix integer/float remainder with infinity argument of opposite sign Previously, the result was incorrect: 4.remainder(-Float::INFINITY) Before: => NaN After: => 4 4.2.remainder(-Float::INFINITY) Before: => NaN After: => 4.2 Fixes [Bug #6120] --- test/ruby/test_numeric.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index c8751fbc57..066afc83a2 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -384,6 +384,18 @@ class TestNumeric < Test::Unit::TestCase end; end + def test_remainder_infinity + assert_equal(4, 4.remainder(Float::INFINITY)) + assert_equal(4, 4.remainder(-Float::INFINITY)) + assert_equal(-4, -4.remainder(Float::INFINITY)) + assert_equal(-4, -4.remainder(-Float::INFINITY)) + + assert_equal(4.2, 4.2.remainder(Float::INFINITY)) + assert_equal(4.2, 4.2.remainder(-Float::INFINITY)) + assert_equal(-4.2, -4.2.remainder(Float::INFINITY)) + assert_equal(-4.2, -4.2.remainder(-Float::INFINITY)) + end + def test_comparison_comparable bug12864 = '[ruby-core:77713] [Bug #12864]' -- cgit v1.2.3