Skip to content

Commit

Permalink
Merge pull request #1216 from semmons99/bigdecimal-comparing-NaN
Browse files Browse the repository at this point in the history
update BigDecimalCmp to return false when comparing to NaN
  • Loading branch information
brixen committed Oct 10, 2011
2 parents ce2dad4 + a2d369f commit 0e6227e
Show file tree
Hide file tree
Showing 22 changed files with 7 additions and 25 deletions.
7 changes: 7 additions & 0 deletions lib/ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
S_INT e;
Real *a, *b;
GUARD_OBJ(a,GetVpValue(self,1));
if(VpIsNaN(a)) return Qfalse;
b = GetVpValue(r,0);
if(!b) {
ID f = 0;
Expand All @@ -748,6 +749,7 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
return rb_num_coerce_cmp(self,r,f);
}
SAVE(b);
if(VpIsNaN(b)) return Qfalse;
e = VpComp(a, b);
if(e==999) return Qnil;
switch(op)
Expand Down Expand Up @@ -786,6 +788,11 @@ BigDecimal_nonzero(VALUE self)
static VALUE
BigDecimal_comp(VALUE self, VALUE r)
{
Real *a, *b;
GUARD_OBJ(a,GetVpValue(self,1));
GUARD_OBJ(b,GetVpValue(self,0));
if(VpIsNaN(a) || VpIsNaN(b)) return Qnil;

return BigDecimalCmp(self, r, '*');
}

Expand Down
1 change: 0 additions & 1 deletion spec/tags/18/ruby/library/bigdecimal/case_compare_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#=== NaN is never equal to any number
fails:BigDecimal#=== returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/18/ruby/library/bigdecimal/eql_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#eql? NaN is never equal to any number
fails:BigDecimal#eql? returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/18/ruby/library/bigdecimal/equal_value_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#== NaN is never equal to any number
fails:BigDecimal#== returns false when compared objects that can not be coerced into BigDecimal
2 changes: 0 additions & 2 deletions spec/tags/18/ruby/library/bigdecimal/gt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:BigDecimal#> properly handles NaN values
fails:BigDecimal#> properly handles NaN values
fails:BigDecimal#> raises an ArgumentError if the argument can't be coerced into a BigDecimal
2 changes: 0 additions & 2 deletions spec/tags/18/ruby/library/bigdecimal/gte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:BigDecimal#>= properly handles NaN values
fails:BigDecimal#>= properly handles NaN values
fails:BigDecimal#>= returns nil if the argument is nil
2 changes: 0 additions & 2 deletions spec/tags/18/ruby/library/bigdecimal/lt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:BigDecimal#< properly handles NaN values
fails:BigDecimal#< properly handles NaN values
fails:BigDecimal#< raises an ArgumentError if the argument can't be coerced into a BigDecimal
2 changes: 0 additions & 2 deletions spec/tags/18/ruby/library/bigdecimal/lte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:BigDecimal#<= properly handles NaN values
fails:BigDecimal#<= properly handles NaN values
fails:BigDecimal#<= raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/case_compare_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#=== NaN is never equal to any number
fails:BigDecimal#=== returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/eql_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#eql? NaN is never equal to any number
fails:BigDecimal#eql? returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/equal_value_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#== NaN is never equal to any number
fails:BigDecimal#== returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/gt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#> properly handles NaN values
fails:BigDecimal#> raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/gte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#>= properly handles NaN values
fails:BigDecimal#>= returns nil if the argument is nil
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/lt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#< properly handles NaN values
fails:BigDecimal#< raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/bigdecimal/lte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#<= properly handles NaN values
fails:BigDecimal#<= raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/case_compare_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#=== NaN is never equal to any number
fails:BigDecimal#=== returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/eql_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#eql? NaN is never equal to any number
fails:BigDecimal#eql? returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/equal_value_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#== NaN is never equal to any number
fails:BigDecimal#== returns false when compared objects that can not be coerced into BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/gt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#> properly handles NaN values
fails:BigDecimal#> raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/gte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#>= properly handles NaN values
fails:BigDecimal#>= returns nil if the argument is nil
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/lt_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#< properly handles NaN values
fails:BigDecimal#< raises an ArgumentError if the argument can't be coerced into a BigDecimal
1 change: 0 additions & 1 deletion spec/tags/20/ruby/library/bigdecimal/lte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:BigDecimal#<= properly handles NaN values
fails:BigDecimal#<= raises an ArgumentError if the argument can't be coerced into a BigDecimal

0 comments on commit 0e6227e

Please sign in to comment.