From 1c47825d70ca0e9f2802e6d461cc68b3f2446b40 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 2 Sep 2014 14:49:56 +0200 Subject: [PATCH] Fix number rounding, clarify comment and change var. names --- TileGenerator.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index b045d50..d862d04 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -39,16 +39,16 @@ static inline int color2int(Color c) return rgb2int(c.r, c.g, c.b, c.a); } -// rounds n (upwards) to a multiple of f while preserving the sign-bit of n +// rounds n (away from 0) to a multiple of f while preserving the sign of n static inline int round_multiple_nosign(int n, int f) { - int nn, ns; - nn = (n >= 0) ? n : -n; - ns = (n >= 0) ? 1 : -1; - if (nn % f == 0) - return n; // n == nn * ns + int abs_n, sign; + abs_n = (n >= 0) ? n : -n; + sign = (n >= 0) ? 1 : -1; + if (abs_n % f == 0) + return n; // n == abs_n * sign else - return ns * (n + f - (n % f)); + return sign * (abs_n + f - (abs_n % f)); } static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)