aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-01 07:35:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-01 07:35:48 +0000
commit52b59fc9d90e8b06aa1e8df83c5ca63164769bcc (patch)
treeeff1ec9c0436e1ec426b046e770d0e1c065047bf /numeric.c
parent528ef3ca933b7cbbbd2e7dde8b1863bbed91947c (diff)
downloadruby-52b59fc9d90e8b06aa1e8df83c5ca63164769bcc.tar.gz
numeric.c: 0 % Float::NAN returns Float::NAN
* numeric.c (flodivmod): all results are NaN if divisor is NaN. [fix GH-692] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 3689165dd8..1e971f41ea 100644
--- a/numeric.c
+++ b/numeric.c
@@ -890,6 +890,12 @@ flodivmod(double x, double y, double *divp, double *modp)
{
double div, mod;
+ if (isnan(y)) {
+ /* y is NaN so all results are NaN */
+ if (modp) *modp = y;
+ if (divp) *divp = y;
+ return;
+ }
if (y == 0.0) rb_num_zerodiv();
if ((x == 0.0) || (isinf(y) && !isinf(x)))
mod = x;
@@ -903,7 +909,7 @@ flodivmod(double x, double y, double *divp, double *modp)
mod = x - z * y;
#endif
}
- if (isinf(x) && !isinf(y) && !isnan(y))
+ if (isinf(x) && !isinf(y))
div = x;
else
div = (x - mod) / y;