diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-29 00:45:41 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-29 00:45:41 +0000 |
commit | 36c4713e310d1904ab14d167a2d4e4ad63364f18 (patch) | |
tree | 03dd917a9fb6e1980ad4a9d6152be97159ef50c5 | |
parent | c655db52170dafdcf3b0a2237cc2b1ad90cf875a (diff) |
rational.c: may be float
* rational.c (f_muldiv): Integer#** can return Rational with Float
right now. [ruby-core:89212] [Bug #15175]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | numeric.c | 8 | ||||
-rw-r--r-- | rational.c | 10 | ||||
-rw-r--r-- | test/ruby/test_integer.rb | 3 |
3 files changed, 20 insertions, 1 deletions
@@ -4034,7 +4034,13 @@ fix_pow(VALUE x, VALUE y) } if (BIGNUM_NEGATIVE_P(y)) { if (a == 0) rb_num_zerodiv(); - return rb_rational_raw(INT2FIX(1), rb_int_pow(x, rb_big_uminus(y))); + y = rb_int_pow(x, rb_big_uminus(y)); + if (0 && RB_FLOAT_TYPE_P(y)) { + /* Maybe should return a Float */ + double d = pow((double)a, RFLOAT_VALUE(y)); + return DBL2NUM(d); + } + return rb_rational_raw(INT2FIX(1), y); } if (a == 0) return INT2FIX(0); x = rb_int2big(FIX2LONG(x)); diff --git a/rational.c b/rational.c index 69a0bf6ab6..3fcf82bce5 100644 --- a/rational.c +++ b/rational.c @@ -805,6 +805,16 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k) VALUE num, den; assert(RB_TYPE_P(self, T_RATIONAL)); + + /* Integer#** can return Rational with Float right now */ + if (RB_FLOAT_TYPE_P(anum) || RB_FLOAT_TYPE_P(aden) || + RB_FLOAT_TYPE_P(bnum) || RB_FLOAT_TYPE_P(bden)) { + double an = NUM2DBL(anum), ad = NUM2DBL(aden); + double bn = NUM2DBL(bnum), bd = NUM2DBL(bden); + double x = (an * bn) / (ad * bd); + return DBL2NUM(x); + } + assert(RB_INTEGER_TYPE_P(anum)); assert(RB_INTEGER_TYPE_P(aden)); assert(RB_INTEGER_TYPE_P(bnum)); diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 51737d3d1f..acba5aca1a 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -24,6 +24,9 @@ class TestInteger < Test::Unit::TestCase rescue nil end, "[ruby-dev:32084] [ruby-dev:34547]") + + x = EnvUtil.suppress_warning {2 ** -0x4000000000000000} + assert_in_delta(0.0, (x / 2), Float::EPSILON) end def test_lshift |