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:
parent
9572ad1d9f
commit
583b77ee9f
1 changed files with 1 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue