From 161ece479598629f4ace4fa23bfea7bc1331a8a0 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 24 Jan 2019 05:30:42 +0000 Subject: numeric.c: Fix negative step with float components * numeric.c (ruby_float_step): fix negative step with float components. * test/ruby/test_numeric.c (test_step_bug15537): add tests. * test/ruby/test_range.c (test_step_bug15537): add tests. [Bug #15537] [ruby-core:91101] From: shuujii (Shuji KOBAYASHI) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 5cb1aad8a1..896d667cf8 100644 --- a/numeric.c +++ b/numeric.c @@ -2514,9 +2514,9 @@ int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endless) { if (RB_TYPE_P(from, T_FLOAT) || RB_TYPE_P(to, T_FLOAT) || RB_TYPE_P(step, T_FLOAT)) { - double beg = NUM2DBL(from); - double end = (allow_endless && NIL_P(to)) ? HUGE_VAL : NUM2DBL(to); double unit = NUM2DBL(step); + double beg = NUM2DBL(from); + double end = (allow_endless && NIL_P(to)) ? (unit < 0 ? -1 : 1)*HUGE_VAL : NUM2DBL(to); double n = ruby_float_step_size(beg, end, unit, excl); long i; -- cgit v1.2.3