summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-08 09:45:52 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-08 09:45:52 +0000
commit13230a3417e37edaf5cdfaedafde5b7e19a34e6e (patch)
tree0342b349f479ee241fbf0b04d31b7f1acdef0d64 /numeric.c
parent698a24674eb0707fdc8d934084932e845db955cd (diff)
* gc.c (rb_gc): check odd alignment stack on m68k machines.
* numeric.c (num_step): better error treatment of float values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 186a2db901..d8041a54a6 100644
--- a/numeric.c
+++ b/numeric.c
@@ -919,13 +919,16 @@ 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;
- n = n + 0.5;
+ 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));
}