Skip to content

Commit

Permalink
* numeric.c (flo_cmp): Infinity is greater than any bignum
Browse files Browse the repository at this point in the history
  number.  [ruby-dev:38672]

* bignum.c (rb_big_cmp): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Jun 17, 2009
1 parent 7785612 commit 7fc9c4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Thu Jun 18 01:35:51 2009 Yukihiro Matsumoto <[email protected]>

* numeric.c (flo_cmp): Infinity is greater than any bignum
number. [ruby-dev:38672]

* bignum.c (rb_big_cmp): ditto.

Thu Jun 18 01:29:16 2009 Nobuyoshi Nakada <[email protected]>

* file.c (file_expand_path): drive letter is ascii only.
Expand Down
10 changes: 9 additions & 1 deletion bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,15 @@ rb_big_cmp(VALUE x, VALUE y)
break;

case T_FLOAT:
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT_VALUE(y));
{
double a = RFLOAT_VALUE(y);

if (isinf(a)) {
if (a > 0.0) return INT2FIX(-1);
else return INT2FIX(1);
}
return rb_dbl_cmp(rb_big2dbl(x), a);
}

default:
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
Expand Down
4 changes: 4 additions & 0 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ flo_cmp(VALUE x, VALUE y)
break;

case T_BIGNUM:
if (isinf(a)) {
if (a > 0.0) return INT2FIX(1);
else return INT2FIX(-1);
}
b = rb_big2dbl(y);
break;

Expand Down
5 changes: 5 additions & 0 deletions test/ruby/test_float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def test_cmp

assert_equal(-1, 1.0 <=> 2**32)

assert_equal(1, inf <=> (Float::MAX.to_i*2))
assert_equal(-1, -inf <=> (-Float::MAX.to_i*2))
assert_equal(-1, (Float::MAX.to_i*2) <=> inf)
assert_equal(1, (-Float::MAX.to_i*2) <=> -inf)

assert_raise(ArgumentError) { 1.0 > nil }
assert_raise(ArgumentError) { 1.0 >= nil }
assert_raise(ArgumentError) { 1.0 < nil }
Expand Down

0 comments on commit 7fc9c4a

Please sign in to comment.