mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-12 08:05:18 +02: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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user