diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-22 14:13:40 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-22 14:13:40 +0000 |
commit | 10e0fc1b6c8fdc8d275653052e129a2d7569e58b (patch) | |
tree | 74cfa6f39d5ff2bef1e10c343c8fced90ff1d1dd /rational.c | |
parent | b866e34f75a3f4e70282d23fdce68fbc45bfc30e (diff) |
merge revision(s) 57688,57689: [Backport #13242]
rational.c: infinity in power
* rational.c (nurat_expt): return Infinity due to overflow.
[ruby-core:79686] [Bug #13242]:
rational.c: infinity in power
* rational.c (nurat_expt): return 0 due to overflow.
[ruby-core:79686] [Bug #13242]:
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/rational.c b/rational.c index 7f3a06af80..6b248e3483 100644 --- a/rational.c +++ b/rational.c @@ -1038,6 +1038,14 @@ nurat_expt(VALUE self, VALUE other) den = ONE; break; } + if (RB_FLOAT_TYPE_P(num)) { /* infinity due to overflow */ + if (RB_FLOAT_TYPE_P(den)) return DBL2NUM(NAN); + return num; + } + if (RB_FLOAT_TYPE_P(den)) { /* infinity due to overflow */ + num = ZERO; + den = ONE; + } return f_rational_new2(CLASS_OF(self), num, den); } } |