summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-22 12:43:42 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-22 12:43:42 +0000
commit6cec674877a48c64201254e80b76dfdab126b750 (patch)
treeea74e2de89d913f463186486c0b8272929c7de43
parent6d55a704454c197b725fa91acb061841aa6805df (diff)
merge revision(s) 21298:
* numeric.c (ruby_float_step): extracted from num_step(). * range.c (range_step): uses ruby_float_step() for float range. [ruby-dev:37691] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@22528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--numeric.c44
-rw-r--r--range.c5
-rw-r--r--version.h2
4 files changed, 41 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index ca8428f1a2..f11b311694 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Feb 22 21:43:34 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (ruby_float_step): extracted from num_step().
+
+ * range.c (range_step): uses ruby_float_step() for float range.
+ [ruby-dev:37691]
+
Sun Feb 22 00:49:36 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): does not use both of makefile.rb and
diff --git a/numeric.c b/numeric.c
index 4f181035ae..de00de20d9 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1427,6 +1427,33 @@ num_truncate(num)
}
+int ruby_float_step _((VALUE from, VALUE to, VALUE step, int excl));
+
+int
+ruby_float_step(from, to, step, excl)
+ VALUE from, to, step;
+ int excl;
+{
+ if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
+ const double epsilon = DBL_EPSILON;
+ double beg = NUM2DBL(from);
+ double end = NUM2DBL(to);
+ double unit = NUM2DBL(step);
+ double n = (end - beg)/unit;
+ double err = (fabs(beg) + fabs(end) + fabs(end-beg)) / fabs(unit) * epsilon;
+ long i;
+
+ if (err>0.5) err=0.5;
+ n = floor(n + err);
+ if (!excl) n++;
+ for (i=0; i<n; i++) {
+ rb_yield(rb_float_new(i*unit+beg));
+ }
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
/*
* call-seq:
* num.step(limit, step ) {|i| block } => num
@@ -1501,22 +1528,7 @@ num_step(argc, argv, from)
}
}
}
- else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
- const double epsilon = DBL_EPSILON;
- double beg = NUM2DBL(from);
- double end = NUM2DBL(to);
- double unit = NUM2DBL(step);
- double n = (end - beg)/unit;
- double err = (fabs(beg) + fabs(end) + fabs(end-beg)) / fabs(unit) * epsilon;
- long i;
-
- if (err>0.5) err=0.5;
- n = floor(n + err) + 1;
- for (i=0; i<n; i++) {
- rb_yield(rb_float_new(i*unit+beg));
- }
- }
- else {
+ else if (!ruby_float_step(from, to, step, Qfalse)) {
VALUE i = from;
ID cmp;
diff --git a/range.c b/range.c
index 7526324da7..864ca9fb28 100644
--- a/range.c
+++ b/range.c
@@ -273,6 +273,8 @@ step_i(i, arg)
return Qnil;
}
+extern int ruby_float_step _((VALUE from, VALUE to, VALUE step, int excl));
+
/*
* call-seq:
* rng.step(n=1) {| obj | block } => rng
@@ -343,6 +345,9 @@ range_step(argc, argv, range)
}
}
+ else if (ruby_float_step(b, e, step, EXCL(range))) {
+ /* done */
+ }
else if (rb_obj_is_kind_of(b, rb_cNumeric) ||
!NIL_P(rb_check_to_integer(b, "to_int")) ||
!NIL_P(rb_check_to_integer(e, "to_int"))) {
diff --git a/version.h b/version.h
index c0835b6712..9c67e7aa48 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-02-22"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20090222
-#define RUBY_PATCHLEVEL 136
+#define RUBY_PATCHLEVEL 137
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8