1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

comment noise2d bitshift

While working through the code I was momentarily concerned that the right bitshift in noise2d could fill ones in some cases. It turns out that with signed integers, this is indeed true, but this one is shifting an unsigned integer, so the behavior is as expected. I put a comment here to clarify this, in case someone else wonders the same thing down the line.
This commit is contained in:
JosiahWI 2021-11-05 08:17:34 -05:00
parent 9572ad1d9f
commit 583b77ee9f
No known key found for this signature in database
GPG key ID: C7BB8573A4ABC4B9

View file

@ -167,6 +167,7 @@ float noise2d(int x, int y, s32 seed)
{
unsigned int n = (NOISE_MAGIC_X * x + NOISE_MAGIC_Y * y
+ NOISE_MAGIC_SEED * seed) & 0x7fffffff;
// Right bit shift on an unsigned type zero-fills.
n = (n >> 13) ^ n;
n = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
return 1.f - (float)(int)n / 0x40000000;