diff --git a/Gemfile b/Gemfile index dbc00c9..0748532 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source 'https://rubygems.org' gemspec unless RUBY_ENGINE == 'jruby' group :development do + gem "bigdecimal" gem "bundler" gem "rake" gem "rake-compiler" diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 575e0e4..22946d4 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -6920,7 +6920,7 @@ cmp_gen(VALUE self, VALUE other) get_d1(self); if (k_numeric_p(other)) - return INT2FIX(f_cmp(m_ajd(dat), other)); + return rb_funcallv(m_ajd(dat), id_cmp, 1, &other); else if (k_date_p(other)) return INT2FIX(f_cmp(m_ajd(dat), f_ajd(other))); return rb_num_coerce_cmp(self, other, id_cmp); diff --git a/test/date/test_date_arith.rb b/test/date/test_date_arith.rb index c3633c9..ca9b553 100644 --- a/test/date/test_date_arith.rb +++ b/test/date/test_date_arith.rb @@ -97,6 +97,21 @@ def test__compare DateTime.new(2001,1,17,0,0,0,0,Date::GREGORIAN))) end + def test__compare_nan + nans = [Float::NAN] + begin + require "bigdecimal" + nans << BigDecimal("NaN") + rescue LoadError + end + d = Date.new(2000,1,1) + nans.each do |nan| + assert_nil(d <=> nan) + assert_equal(false, d == nan) + assert_raise(ArgumentError) { d < nan } + end + end + def test_prev d = Date.new(2000,1,1) assert_raise(NoMethodError) do