jorisvandenbossche commented on code in PR #14696:
URL: https://github.com/apache/arrow/pull/14696#discussion_r1036764141


##########
cpp/src/arrow/compute/kernels/scalar_nested.cc:
##########
@@ -96,6 +97,28 @@ std::string ToString(const std::optional<T>& o) {
   return o.has_value() ? ToChars(*o) : "(nullopt)";
 }
 
+int64_t MaxSliceLength(const int64_t start, const int64_t stop, const int64_t 
step) {
+  const auto startf = static_cast<float>(start);
+  const auto stopf = static_cast<float>(stop);
+  const auto stepf = static_cast<float>(step);
+
+  // length not considering step, is less than step then
+  // the length will be 1; the index of start.
+  if (stopf - startf <= stepf) {
+    return 1;
+  }
+
+  // Get the raw length with any remainder after dividing by step
+  auto length = (stopf - startf) / stepf;
+
+  // Any remainder from the step into length then it is not evenly split by 
step
+  // and will need one extra in length.
+  if (length > std::floor(length)) {
+    ++length;
+  }

Review Comment:
   I am wondering, isn't this now the same as rounding up? (std::ceil)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to