summaryrefslogtreecommitdiff
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
commit4e0ac23588e805fa4457878c5523fd7ed3367d40 (patch)
tree9a209bb3afa3dfb6edad8a99f8c7f57cfa1d83d5
parent6bc16a119834f4d496c527c19b4dcdb2430e26ab (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/branches/ruby_1_8@13907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--configure.in2
-rw-r--r--numeric.c16
3 files changed, 21 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 98622b5933..2b4fda24f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Nov 13 16:33:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (flodivmod): work around for inifinity.
+
+ * numeric.c (flo_divmod): work around for platforms have no round().
+ [ruby-dev:32247]
+
Tue Nov 13 13:58:51 2007 Tanaka Akira <akr@fsij.org>
* numeric.c (numeric.c): Integer#ord implemented. [ruby-dev:32206]
diff --git a/configure.in b/configure.in
index e61979ed06..4cd24635e6 100644
--- a/configure.in
+++ b/configure.in
@@ -545,7 +545,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync getcwd eaccess\
getgroups setgroups getpriority getrlimit setrlimit sysconf\
group_member dlopen sigprocmask\
sigaction _setjmp setsid telldir seekdir fchmod mktime timegm\
- cosh sinh tanh setuid setgid setenv unsetenv)
+ cosh sinh tanh round setuid setgid setenv unsetenv)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
[use_setreuid=$enableval])
diff --git a/numeric.c b/numeric.c
index 38a99f8283..e804da263c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -663,7 +663,10 @@ flodivmod(x, y, divp, 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;
@@ -736,11 +739,18 @@ flo_divmod(x, y)
}
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
if (FIXABLE(div)) {
+#ifdef HVAE_ROUND
val = round(div);
- a = LONG2FIX(val);
+#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);
+ a = rb_dbl2big(div);
}
b = rb_float_new(mod);
return rb_assoc_new(a, b);