Skip to content

Commit

Permalink
Add IntCastRounded for float argument (#1433)
Browse files Browse the repository at this point in the history
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 <sw@weilnetz.de>
  • Loading branch information
stweil authored and zdenop committed Mar 27, 2018
1 parent 6bbfc3b commit 9e74ed3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ccutil/helpers.h
Expand Up @@ -180,6 +180,11 @@ inline int IntCastRounded(double x) {
return x >= 0.0 ? static_cast<int>(x + 0.5) : -static_cast<int>(-x + 0.5);
}

// Return a float cast to int with rounding.
inline int IntCastRounded(float x) {
return x >= 0.0f ? static_cast<int>(x + 0.5f) : -static_cast<int>(-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<char*>(ptr);
Expand Down

0 comments on commit 9e74ed3

Please sign in to comment.