Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge revision(s) 23730:

?\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...
commit 2ed335bf0f6d9c529ef2c8de948aada36a5762b1 1 parent a8ae652
@shyouhei shyouhei authored
Showing with 47 additions and 1 deletion.
  1. +7 −0 ChangeLog
  2. +9 −1 bignum.c
  3. +4 −0 numeric.c
  4. +27 −0 test/ruby/test_float.rb
View
7 ChangeLog
@@ -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
View
10 bignum.c
@@ -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);
View
4 numeric.c
@@ -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;
View
27 test/ruby/test_float.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.