Skip to content

Commit 1c47825

Browse files
committedSep 2, 2014
Fix number rounding, clarify comment and change var. names
1 parent b7f0a8a commit 1c47825

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎TileGenerator.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ static inline int color2int(Color c)
3939
return rgb2int(c.r, c.g, c.b, c.a);
4040
}
4141

42-
// rounds n (upwards) to a multiple of f while preserving the sign-bit of n
42+
// rounds n (away from 0) to a multiple of f while preserving the sign of n
4343
static inline int round_multiple_nosign(int n, int f)
4444
{
45-
int nn, ns;
46-
nn = (n >= 0) ? n : -n;
47-
ns = (n >= 0) ? 1 : -1;
48-
if (nn % f == 0)
49-
return n; // n == nn * ns
45+
int abs_n, sign;
46+
abs_n = (n >= 0) ? n : -n;
47+
sign = (n >= 0) ? 1 : -1;
48+
if (abs_n % f == 0)
49+
return n; // n == abs_n * sign
5050
else
51-
return ns * (n + f - (n % f));
51+
return sign * (abs_n + f - (abs_n % f));
5252
}
5353

5454
static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)

1 commit comments

Comments
 (1)

Zeno- commented on Sep 2, 2014

@Zeno-

Coulda thanked me :p

Please sign in to comment.