diff --git a/include/support.h b/include/support.h index ce0944af..19a2e76d 100644 --- a/include/support.h +++ b/include/support.h @@ -82,6 +82,13 @@ inline constexpr T1 ceil_sdivide(const T1 x, const T2 y) noexcept { // https://stackoverflow.com/a/33790603 } +inline int iround(double x) { + assert(std::isfinite(x)); + assert(x >= (std::numeric_limits::min)()); + assert(x <= (std::numeric_limits::max)()); + return static_cast(round(x)); +} + // Include a message in assert, similar to static_assert: #define assertm(exp, msg) assert(((void)msg, exp)) // Use (void) to silent unused warnings.