summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--numeric.c30
-rw-r--r--version.h6
3 files changed, 32 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index a068e7f278..d4e7ff78b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Nov 14 01:34:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (round): fallback definition.
+
+ * numeric.c (flo_divmod, flo_round): use round() always.
+ [ruby-dev:32269]
+
Tue Nov 13 22:02:23 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: remove Thread.exclusive.
diff --git a/numeric.c b/numeric.c
index e804da263c..9d2c4508ac 100644
--- a/numeric.c
+++ b/numeric.c
@@ -63,6 +63,25 @@
#define DBL_EPSILON 2.2204460492503131e-16
#endif
+#ifndef HAVE_ROUND
+double
+round(x)
+ double x;
+{
+ double f;
+
+ if (x > 0.0) {
+ f = floor(x);
+ x = f + (x - f >= 0.5);
+ }
+ else if (x < 0.0) {
+ f = ceil(x);
+ x = f - (f - x >= 0.5);
+ }
+ return x;
+}
+#endif
+
static ID id_coerce, id_to_i, id_eq;
VALUE rb_cNumeric;
@@ -739,11 +758,7 @@ flo_divmod(x, 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)) {
@@ -1302,8 +1317,7 @@ flo_round(num)
double f = RFLOAT(num)->value;
long val;
- if (f > 0.0) f = floor(f+0.5);
- if (f < 0.0) f = ceil(f-0.5);
+ f = round(f);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
@@ -1541,7 +1555,7 @@ rb_num2long(val)
char *s;
sprintf(buf, "%-.10g", RFLOAT(val)->value);
- if (s = strchr(buf, ' ')) *s = '\0';
+ if ((s = strchr(buf, ' ')) != 0) *s = '\0';
rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
}
@@ -1692,7 +1706,7 @@ rb_num2ll(val)
char *s;
sprintf(buf, "%-.10g", RFLOAT(val)->value);
- if (s = strchr(buf, ' ')) *s = '\0';
+ if ((s = strchr(buf, ' ')) != 0) *s = '\0';
rb_raise(rb_eRangeError, "float %s out of range of long long", buf);
}
diff --git a/version.h b/version.h
index ca21de4377..7ee3cd225e 100644
--- a/version.h
+++ b/version.h
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-11-13"
+#define RUBY_RELEASE_DATE "2007-11-14"
#define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20071113
+#define RUBY_RELEASE_CODE 20071114
#define RUBY_PATCHLEVEL 5000
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 14
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];