From 4c2e2d8bdefa8cd43adf1e28358353c1ded53049 Mon Sep 17 00:00:00 2001 From: marcandre Date: Wed, 14 Mar 2012 06:10:01 +0000 Subject: * numeric.c: fix flodivmod for cornercases [Bug #6044] add ruby_float_mod * insns.def (opt_mod): use ruby_float_mod * internal.h: declare ruby_float_mod * test/ruby/test_float.rb: tests for above * test/ruby/envutil.rb: create helper assert_is_minus_zero git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/envutil.rb | 4 ++++ test/ruby/test_float.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) (limited to 'test') diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 80700d6dc5..3e0c1a3f00 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -212,6 +212,10 @@ module Test assert_equal([true, ""], [status.success?, err], message) assert_operator(after.fdiv(before), :<, limit, message) end + + def assert_is_minus_zero(f) + assert(1.0/f == -Float::INFINITY, "#{f} is not -0.0") + end end end end diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 1935cfdd52..f561d00158 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -195,6 +195,18 @@ class TestFloat < Test::Unit::TestCase assert_raise(TypeError) { 2.0.send(:%, nil) } end + def test_modulo3 + bug6048 = '[ruby-core:42726]' + assert_equal(4.2, 4.2.send(:%, Float::INFINITY)) + assert_equal(4.2, 4.2 % Float::INFINITY) + assert_is_minus_zero(-0.0 % 4.2) + assert_is_minus_zero(-0.0.send :%, 4.2) + assert_raise(ZeroDivisionError) { 4.2.send(:%, 0.0) } + assert_raise(ZeroDivisionError) { 4.2 % 0.0 } + assert_raise(ZeroDivisionError) { 42.send(:%, 0) } + assert_raise(ZeroDivisionError) { 42 % 0 } + end + def test_divmod2 assert_equal([1.0, 0.0], 2.0.divmod(2)) assert_equal([1.0, 0.0], 2.0.divmod((2**32).coerce(2).first)) -- cgit v1.2.3