1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2009-06-17 17:05:31 +00:00
parent 7785612a38
commit 7fc9c4a4a0
4 changed files with 25 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Thu Jun 18 01:35:51 2009 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.
Thu Jun 18 01:29:16 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (file_expand_path): drive letter is ascii only.

View file

@ -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("<=>"));

View file

@ -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;

View file

@ -215,6 +215,11 @@ class TestFloat < Test::Unit::TestCase
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 }