Skip to content

Commit

Permalink
merge revision(s) 23730:
Browse files Browse the repository at this point in the history
?\012
	* numeric.c (flo_cmp): Infinity is greater than any bignum
	  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
Signed-off-by: URABE, Shyouhei <shyouhei@ruby-lang.org>

git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@34000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shyouhei committed Dec 10, 2011
1 parent a8ae652 commit 2ed335b
Show file tree
Hide file tree
Showing 4 changed files with 47 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 @@
Mon Oct 17 04:19:39 2011 Yukihiro Matsumoto <matz@ruby-lang.org>

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

* bignum.c (rb_big_cmp): ditto.

Mon Oct 17 03:56:12 2011 Yusuke Endoh <mame@tsg.ne.jp>

* ext/openssl/ossl_x509store.c (ossl_x509store_initialize): initialize
Expand Down
10 changes: 9 additions & 1 deletion bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,15 @@ rb_big_cmp(x, y)
break;

case T_FLOAT:
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value);
{
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);
Expand Down
4 changes: 4 additions & 0 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,10 @@ flo_cmp(x, 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
27 changes: 27 additions & 0 deletions test/ruby/test_float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,31 @@ def test_to_i
assert_operator((-4611686018427387905.0).to_i, :<, 0)
assert_operator((-4611686018427387906.0).to_i, :<, 0)
end

def test_cmp
inf = 1.0 / 0.0
nan = inf / inf
assert_equal(0, 1.0 <=> 1.0)
assert_equal(1, 1.0 <=> 0.0)
assert_equal(-1, 1.0 <=> 2.0)
assert_nil(1.0 <=> nil)
assert_nil(1.0 <=> nan)
assert_nil(nan <=> 1.0)

assert_equal(0, 1.0 <=> 1)
assert_equal(1, 1.0 <=> 0)
assert_equal(-1, 1.0 <=> 2)

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 }
assert_raise(ArgumentError) { 1.0 <= nil }
end
end

0 comments on commit 2ed335b

Please sign in to comment.