summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ext/bigdecimal/bigdecimal.c10
-rw-r--r--test/bigdecimal/test_bigdecimal.rb17
3 files changed, 25 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 417d7d9ad1..149cfacfbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Nov 14 09:16:54 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons
+ [ruby-core:26646]
+
+ * test/bigdecimal/test_bigdecimal.rb (class): Fix and improve tests.
+
Sat Nov 14 04:07:06 2009 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/variable.rb (TkVariable::coerce): fix bug on a
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index f4c22b5060..38772f68f6 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -724,23 +724,21 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
switch(op)
{
- case '*': f = rb_intern("<=>");break;
- case '=': f = rb_intern("=="); break;
- case '!': f = rb_intern("!="); break;
+ case '*': return rb_num_coerce_cmp(self,r,rb_intern("<=>"));
+ case '=': return RTEST(rb_num_coerce_cmp(self,r,rb_intern("=="))) ? Qtrue : Qfalse;
case 'G': f = rb_intern(">="); break;
case 'L': f = rb_intern("<="); break;
case '>': case '<': f = (ID)op; break;
}
- return rb_num_coerce_cmp(self,r,f);
+ return rb_num_coerce_relop(self,r,f);
}
SAVE(b);
e = VpComp(a, b);
- if(e==999) return Qnil;
+ if(e==999) return (op == '*') ? Qnil : Qfalse;
switch(op)
{
case '*': return INT2FIX(e); /* any op */
case '=': if(e==0) return Qtrue ; return Qfalse;
- case '!': if(e!=0) return Qtrue ; return Qfalse;
case 'G': if(e>=0) return Qtrue ; return Qfalse;
case '>': if(e> 0) return Qtrue ; return Qfalse;
case 'L': if(e<=0) return Qtrue ; return Qfalse;
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 2490c8469c..4d2a28514e 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -61,7 +61,6 @@ class TestBigDecimal < Test::Unit::TestCase
x = BigDecimal.new("0.1")
100.times do
x *= x
- break if x == false
end
end
end
@@ -71,7 +70,6 @@ class TestBigDecimal < Test::Unit::TestCase
x = BigDecimal.new("10")
100.times do
x *= x
- break if x == false
end
end
end
@@ -219,7 +217,20 @@ class TestBigDecimal < Test::Unit::TestCase
assert_operator(1, :<, inf)
end
- def test_cmp_corece
+ def test_cmp_nan
+ n1 = BigDecimal.new("1")
+ BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
+ assert_equal(nil, BigDecimal.new("NaN") <=> n1)
+ assert_equal(false, BigDecimal.new("NaN") > n1)
+ end
+
+ def test_cmp_failing_coercion
+ n1 = BigDecimal.new("1")
+ assert_equal(nil, n1 <=> nil)
+ assert_raise(ArgumentError){n1 > nil}
+ end
+
+ def test_cmp_coerce
n1 = BigDecimal.new("1")
n2 = BigDecimal.new("2")
o1 = Object.new; def o1.coerce(x); [x, BigDecimal.new("1")]; end