summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-06 22:05:52 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-06 22:05:52 +0000
commit941025c31bb14adcd3314682742eb48357e8f11a (patch)
treeb1df206bbdda1bc98e2cd1a72e00a412a8f1cb56
parent09a2dd632b9a3f4233466d054388359684667cdc (diff)
* lib/bigdecimal.rb: fix comparison operators [ruby-core:26646]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/bigdecimal/bigdecimal.c12
-rw-r--r--test/bigdecimal/test_bigdecimal.rb2
3 files changed, 13 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 110500663a..a14ce74421 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Dec 7 07:05:05 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/bigdecimal.rb: fix comparison operators [ruby-core:26646]
+
Mon Dec 7 07:01:19 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* object.c (rb_Float): Allow results of to_f to be NaN
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 185a0799fc..78ea21a0f3 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -750,15 +750,21 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
Real *a, *b;
GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
- if(!b) return rb_num_coerce_cmp(self,r);
+ if(!b) {
+ switch(op)
+ {
+ case '*': return rb_num_coerce_cmp(self,r); /* any op */
+ case '=': return RTEST(rb_num_coerce_cmp(self,r)) ? Qtrue : Qfalse;
+ default: return rb_num_coerce_relop(self,r);
+ }
+ }
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 a8b8c076be..19beec1c74 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