From d66f5dc07ea6934df1c41d4904f7d985a54049a1 Mon Sep 17 00:00:00 2001 From: feixyz10 Date: Wed, 28 Apr 2021 19:58:56 +0800 Subject: [PATCH] fix bug in common::Range --- common/math/math_utils.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/math/math_utils.cc b/common/math/math_utils.cc index f7a5d70..bf313ea 100644 --- a/common/math/math_utils.cc +++ b/common/math/math_utils.cc @@ -19,11 +19,15 @@ double Rad2Degree(double rad) { const std::vector Range(int begin, int end, int step) { ACHECK(step != 0) << "Step must be non-zero"; - int num = (end - begin) / step; + int sign = step < 0 ? -1 : 1; + int num = (end - begin - sign) / step + 1; if (num <= 0) return {}; - end = begin + step * num; std::vector seq(num); - for (int i = begin; i != end; i += step) seq[i] = i; + int b = begin; + for (int i = 0; i != num; ++i) { + seq[i] = b; + b += step; + } return seq; }