Code modernization: src/m* (part 2)
[oweals/minetest.git] / src / noise.cpp
index e75fb8278b3dc61c6422989f614428592bcf6fe6..e6ca8a4951cf669c8312275f2b859fc34d2f1297 100644 (file)
@@ -47,8 +47,8 @@ typedef float (*Interp3dFxn)(
                float x, float y, float z);
 
 float cos_lookup[16] = {
-       1.0,  0.9238,  0.7071,  0.3826, 0, -0.3826, -0.7071, -0.9238,
-       1.0, -0.9238, -0.7071, -0.3826, 0,  0.3826,  0.7071,  0.9238
+       1.0f,  0.9238f,  0.7071f,  0.3826f, .0f, -0.3826f, -0.7071f, -0.9238f,
+       1.0f, -0.9238f, -0.7071f, -0.3826f, .0f,  0.3826f,  0.7071f,  0.9238f
 };
 
 FlagDesc flagdesc_noiseparams[] = {
@@ -130,7 +130,9 @@ s32 PcgRandom::range(s32 min, s32 max)
        if (max < min)
                throw PrngException("Invalid range (max < min)");
 
-       u32 bound = max - min + 1;
+       // We have to cast to s64 because otherwise this could overflow,
+       // and signed overflow is undefined behavior.
+       u32 bound = (s64)max - (s64)min + 1;
        return range(bound) + min;
 }