From 9e74ed3730e1945a0229c5f13b13856b64afa608 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 27 Mar 2018 14:34:06 +0200 Subject: [PATCH] Add IntCastRounded for float argument (#1433) The method is called with a float argument several times, and the previous implementation which only supported a double argument resulted in type conversions and compiler warnings. Signed-off-by: Stefan Weil --- ccutil/helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ccutil/helpers.h b/ccutil/helpers.h index ce44dcdb50..5005f6e73f 100644 --- a/ccutil/helpers.h +++ b/ccutil/helpers.h @@ -180,6 +180,11 @@ inline int IntCastRounded(double x) { return x >= 0.0 ? static_cast(x + 0.5) : -static_cast(-x + 0.5); } +// Return a float cast to int with rounding. +inline int IntCastRounded(float x) { + return x >= 0.0f ? static_cast(x + 0.5f) : -static_cast(-x + 0.5f); +} + // Reverse the order of bytes in a n byte quantity for big/little-endian switch. inline void ReverseN(void* ptr, int num_bytes) { char* cptr = static_cast(ptr);