From 583b77ee9f1ad6bb77340ebb5ba51eb9a88ff51c Mon Sep 17 00:00:00 2001 From: JosiahWI Date: Fri, 5 Nov 2021 08:17:34 -0500 Subject: [PATCH] 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. --- src/noise.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/noise.cpp b/src/noise.cpp index 46067e09d..ee6ddf871 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -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;