summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-13 07:33:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-13 07:33:09 +0000
commitb7d363ead696a2f1143c547d71d0242b1402c9f6 (patch)
tree494cd08c763113f23a6b09ad55dbea0964e8d8a9 /numeric.c
parent9829e14432c2d30371305120c58c406a9df69a68 (diff)
* numeric.c (flodivmod): work around for inifinity.
* numeric.c (flo_divmod): work around for platforms have no round(). [ruby-dev:32247] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index d9466daa91..ddd30e46af 100644
--- a/numeric.c
+++ b/numeric.c
@@ -644,7 +644,10 @@ flodivmod(double x, double y, double *divp, double *modp)
mod = x - z * y;
}
#endif
- div = (x - mod) / y;
+ if (isinf(x) && !isinf(y) && !isnan(y))
+ div = x;
+ else
+ div = (x - mod) / y;
if (y*mod < 0) {
mod += y;
div -= 1.0;
@@ -715,9 +718,16 @@ flo_divmod(VALUE x, VALUE y)
}
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
if (FIXABLE(div)) {
+#ifdef HVAE_ROUND
val = round(div);
+#else
+ val = (div < 0) ? ceil(x - 0.5) : floor(x + 0.5);
+#endif
a = LONG2FIX(val);
}
+ else if (isnan(div) || isinf(div)) {
+ a = rb_float_new(div);
+ }
else {
a = rb_dbl2big(div);
}