diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:41:50 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:41:50 +0000 |
commit | 4fa0cdea7838a12afac492ee58af7f30660c6a8f (patch) | |
tree | 30895168554835060498505a41c9f5e72c4cddea /numeric.c | |
parent | ca55fe4f0d1477f9b2b14793468c370ebbb96ea7 (diff) |
* numeric.c (num_step): better iteration condition for float
values; suggested by Masahiro TANAKA <masa@ir.isas.ac.jp>.
* range.c (range_step): step (for Range#step method) <= 0 makes no
sence, thus ArgError will be raised.
* range.c (range_each): Range#each method is special case for
Range#step(1)
* file.c (rb_find_file): load must be done from an abolute path if
$SAFE >= 4.
* enum.c (enum_partition): new method. [new]
* re.c (rb_reg_s_quote): quote whitespaces for /x cases.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 18 |
1 files changed, 7 insertions, 11 deletions
@@ -788,6 +788,7 @@ num_step(argc, argv, from) while (i <= end) { rb_yield(INT2FIX(i)); i += diff; + printf("<<%g>>\n", i - end); } } else { @@ -798,21 +799,16 @@ num_step(argc, argv, from) } } else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) { + const double epsilon = 2.2204460492503131E-16; double beg = NUM2DBL(from); double end = NUM2DBL(to); double unit = NUM2DBL(step); - double n = beg; - long i = 0; + double n = (end - beg)/unit; + long i; - if (unit > 0) { - for (i=0; n<=end; i++, n=beg+unit*i) { - rb_yield(rb_float_new(n)); - } - } - else { - for (i=0; n>=end; i++, n=beg+unit*i) { - rb_yield(rb_float_new(n)); - } + n = floor(n + n*epsilon) + 1; + for (i=0; i<n; i++) { + rb_yield(rb_float_new(i*unit+beg)); } } else { |