mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (num_step): try to reduce residual on Float operations.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a117cec653
commit
936ad409ad
2 changed files with 34 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Apr 24 14:06:35 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* numeric.c (num_step): try to reduce residual on Float operations.
|
||||
|
||||
Wed Apr 24 06:48:31 2002 Koji Arai <jca02266@nifty.ne.jp>
|
||||
|
||||
* io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
|
||||
|
|
25
numeric.c
25
numeric.c
|
@ -769,8 +769,6 @@ num_step(argc, argv, from)
|
|||
VALUE from;
|
||||
{
|
||||
VALUE to, step;
|
||||
VALUE i = from;
|
||||
ID cmp;
|
||||
|
||||
if (rb_scan_args(argc, argv, "11", &to, &step) == 1) {
|
||||
step = INT2FIX(1);
|
||||
|
@ -798,8 +796,28 @@ num_step(argc, argv, from)
|
|||
i += diff;
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
|
||||
double beg = NUM2DBL(from);
|
||||
double end = NUM2DBL(to);
|
||||
double unit = NUM2DBL(step);
|
||||
double n = beg;
|
||||
long i = 0;
|
||||
|
||||
if (unit > 0) {
|
||||
for (i=0; n<=end; i++, n=unit*i+beg) {
|
||||
rb_yield(rb_float_new(n));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; n>=end; i++, n=unit*i+beg) {
|
||||
rb_yield(rb_float_new(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
VALUE i = from;
|
||||
ID cmp;
|
||||
|
||||
if (RTEST(rb_funcall(step, '>', 1, INT2FIX(0)))) {
|
||||
cmp = '>';
|
||||
|
@ -812,6 +830,7 @@ num_step(argc, argv, from)
|
|||
rb_yield(i);
|
||||
i = rb_funcall(i, '+', 1, step);
|
||||
}
|
||||
}
|
||||
return from;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue