ruby-changes:16849
From: nobu <ko1@a...>
Date: Tue, 3 Aug 2010 20:30:37 +0900 (JST)
Subject: [ruby-changes:16849] Ruby:r28844 (trunk): * bignum.c (rb_big_eq): never equal to infinity.
nobu 2010-08-03 20:30:19 +0900 (Tue, 03 Aug 2010) New Revision: 28844 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28844 Log: * bignum.c (rb_big_eq): never equal to infinity. [ruby-core:31603] * rational.c (nurat_div): hack for integral float divisor. Modified files: trunk/ChangeLog trunk/bignum.c trunk/rational.c trunk/test/ruby/test_bignum.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 28843) +++ ChangeLog (revision 28844) @@ -1,3 +1,10 @@ +Tue Aug 3 20:30:16 2010 Nobuyoshi Nakada <nobu@r...> + + * bignum.c (rb_big_eq): never equal to infinity. + [ruby-core:31603] + + * rational.c (nurat_div): hack for integral float divisor. + Tue Aug 3 14:42:12 2010 NARUSE, Yui <naruse@r...> * ext/mkext.rb: remove purelib, fixes a bug in r28440, r28441. Index: bignum.c =================================================================== --- bignum.c (revision 28843) +++ bignum.c (revision 28844) @@ -1567,7 +1567,7 @@ volatile double a, b; a = RFLOAT_VALUE(y); - if (isnan(a)) return Qfalse; + if (isnan(a) || isinf(a)) return Qfalse; b = rb_big2dbl(x); return (a == b)?Qtrue:Qfalse; } Index: test/ruby/test_bignum.rb =================================================================== --- test/ruby/test_bignum.rb (revision 28843) +++ test/ruby/test_bignum.rb (revision 28844) @@ -193,6 +193,7 @@ assert(T31P != 1) assert(T31P == 2147483647.0) assert(T31P != "foo") + assert(2**77889 != (1.0/0.0), '[ruby-core:31603]') end def test_eql Index: rational.c =================================================================== --- rational.c (revision 28843) +++ rational.c (revision 28844) @@ -869,6 +869,23 @@ other, ONE, '/'); } case T_FLOAT: + { + double x = RFLOAT_VALUE(other), den; + get_dat1(self); + + if (isnan(x)) return DBL2NUM(NAN); + if (isinf(x)) { + if (RTEST(f_negative_p(dat->num)) == (x < 0)) { + return DBL2NUM(INFINITY); + } + else { + return DBL2NUM(-INFINITY); + } + } + if (modf(x, &den) == 0.0) { + return rb_rational_raw2(dat->num, f_mul(rb_dbl2big(den), dat->den)); + } + } return rb_funcall(f_to_f(self), '/', 1, other); case T_RATIONAL: if (f_zero_p(other)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/