Skip to content

Commit

Permalink
Document undefined behavior in div_rounding_up_safe (#17542)
Browse files Browse the repository at this point in the history
Adds more description to the `div_rounding_up_safe` utility identifying undefined behavior.
Closes #17539

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Paul Mattione (https://github.com/pmattione-nvidia)
  - Lawrence Mitchell (https://github.com/wence-)
  - Nghia Truong (https://github.com/ttnghia)

URL: #17542
  • Loading branch information
davidwendt authored Dec 9, 2024
1 parent ba3ed57 commit ed2892c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cpp/include/cudf/detail/utilities/integer_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2019 BlazingDB, Inc.
* Copyright 2019 Eyal Rozenberg <eyalroz@blazingdb.com>
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -134,16 +134,20 @@ constexpr I div_rounding_up_safe(std::integral_constant<bool, true>, I dividend,
} // namespace detail

/**
* Divides the left-hand-side by the right-hand-side, rounding up
* @brief Divides the left-hand-side by the right-hand-side, rounding up
* to an integral multiple of the right-hand-side, e.g. (9,5) -> 2 , (10,5) -> 2, (11,5) -> 3.
*
* @param dividend the number to divide
* @param divisor the number of by which to divide
* @return The least integer multiple of {@link divisor} which is greater than or equal to
* the non-integral division dividend/divisor.
* The result is undefined if `divisor == 0` or
* if `divisor == -1` and `dividend == min<I>()`.
*
* Will not overflow, and may _or may not_ be slower than the intuitive
* approach of using `(dividend + divisor - 1) / divisor`.
*
* @note will not overflow, and may _or may not_ be slower than the intuitive
* approach of using (dividend + divisor - 1) / divisor
* @tparam I Integer type for `dividend`, `divisor`, and the return type
* @param dividend The number to divide
* @param divisor The number by which to divide
* @return The least integer multiple of `divisor` which is greater than or equal to
* the non-integral division `dividend/divisor`
*/
template <typename I>
constexpr I div_rounding_up_safe(I dividend, I divisor) noexcept
Expand Down

0 comments on commit ed2892c

Please sign in to comment.