From c890c7b05b7f493710a1e4859d59edc74c5f7f2f Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Fri, 10 Apr 2020 23:41:23 +0200 Subject: [PATCH] Implement iround helper function --- include/support.h | 7 +++++++ 1 file changed, 7 insertions(+) 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.