mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Fix many issues reported by clang-tidy (#7189)
* Fix many issues reported by clang-tidy We have many issues in code related to some performance to float <-> double. Clang-tidy reported it in performance-type-promotion-in-math-fn I fixed many of them. It's not ready for a promote to blocking Also fix some value which should be const-ref
This commit is contained in:
parent
e98fd934ce
commit
2481ea27ce
14 changed files with 61 additions and 52 deletions
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "test.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "exceptions.h"
|
||||
#include "noise.h"
|
||||
|
||||
|
@ -61,7 +62,7 @@ void TestNoise::testNoise2dPoint()
|
|||
for (u32 x = 0; x != 10; x++, i++) {
|
||||
float actual = NoisePerlin2D(&np_normal, x, y, 1337);
|
||||
float expected = expected_2d_results[i];
|
||||
UASSERT(fabs(actual - expected) <= 0.00001);
|
||||
UASSERT(std::fabs(actual - expected) <= 0.00001);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +75,7 @@ void TestNoise::testNoise2dBulk()
|
|||
for (u32 i = 0; i != 10 * 10; i++) {
|
||||
float actual = noisevals[i];
|
||||
float expected = expected_2d_results[i];
|
||||
UASSERT(fabs(actual - expected) <= 0.00001);
|
||||
UASSERT(std::fabs(actual - expected) <= 0.00001);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ void TestNoise::testNoise3dPoint()
|
|||
for (u32 x = 0; x != 10; x++, i++) {
|
||||
float actual = NoisePerlin3D(&np_normal, x, y, z, 1337);
|
||||
float expected = expected_3d_results[i];
|
||||
UASSERT(fabs(actual - expected) <= 0.00001);
|
||||
UASSERT(std::fabs(actual - expected) <= 0.00001);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +102,7 @@ void TestNoise::testNoise3dBulk()
|
|||
for (u32 i = 0; i != 10 * 10 * 10; i++) {
|
||||
float actual = noisevals[i];
|
||||
float expected = expected_3d_results[i];
|
||||
UASSERT(fabs(actual - expected) <= 0.00001);
|
||||
UASSERT(std::fabs(actual - expected) <= 0.00001);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "test.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "util/numeric.h"
|
||||
#include "exceptions.h"
|
||||
#include "noise.h"
|
||||
|
@ -157,7 +158,7 @@ void TestRandom::testPcgRandomNormalDist()
|
|||
int range = (max - min + 1);
|
||||
float mean = (max + min) / 2;
|
||||
float variance = ((range * range - 1) / 12) / num_trials;
|
||||
float stddev = sqrt(variance);
|
||||
float stddev = std::sqrt(variance);
|
||||
|
||||
static const float prediction_intervals[] = {
|
||||
0.68269f, // 1.0
|
||||
|
@ -180,7 +181,7 @@ void TestRandom::testPcgRandomNormalDist()
|
|||
accum += bins[j - min];
|
||||
|
||||
float actual = (float)accum / num_samples;
|
||||
UASSERT(fabs(actual - prediction_intervals[i]) < 0.02);
|
||||
UASSERT(std::fabs(actual - prediction_intervals[i]) < 0.02f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "test.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "settings.h"
|
||||
#include "noise.h"
|
||||
|
||||
|
@ -174,14 +175,14 @@ void TestSettings::testAllSettings()
|
|||
|
||||
NoiseParams np;
|
||||
UASSERT(s.getNoiseParams("np_terrain", np) == true);
|
||||
UASSERT(fabs(np.offset - 5) < 0.001);
|
||||
UASSERT(fabs(np.scale - 40) < 0.001);
|
||||
UASSERT(fabs(np.spread.X - 250) < 0.001);
|
||||
UASSERT(fabs(np.spread.Y - 250) < 0.001);
|
||||
UASSERT(fabs(np.spread.Z - 250) < 0.001);
|
||||
UASSERT(std::fabs(np.offset - 5) < 0.001f);
|
||||
UASSERT(std::fabs(np.scale - 40) < 0.001f);
|
||||
UASSERT(std::fabs(np.spread.X - 250) < 0.001f);
|
||||
UASSERT(std::fabs(np.spread.Y - 250) < 0.001f);
|
||||
UASSERT(std::fabs(np.spread.Z - 250) < 0.001f);
|
||||
UASSERT(np.seed == 12341);
|
||||
UASSERT(np.octaves == 5);
|
||||
UASSERT(fabs(np.persist - 0.7) < 0.001);
|
||||
UASSERT(std::fabs(np.persist - 0.7) < 0.001f);
|
||||
|
||||
np.offset = 3.5;
|
||||
np.octaves = 6;
|
||||
|
|
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "test.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "util/numeric.h"
|
||||
#include "util/string.h"
|
||||
|
||||
|
@ -111,13 +112,13 @@ void TestUtilities::testAngleWrapAround()
|
|||
UASSERT(fabs(modulo360f(-365.5) - (-5.5)) < 0.001);
|
||||
|
||||
for (float f = -720; f <= -360; f += 0.25) {
|
||||
UASSERT(fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001);
|
||||
UASSERT(std::fabs(modulo360f(f) - modulo360f(f + 360)) < 0.001);
|
||||
}
|
||||
|
||||
for (float f = -1440; f <= 1440; f += 0.25) {
|
||||
UASSERT(fabs(modulo360f(f) - fmodf(f, 360)) < 0.001);
|
||||
UASSERT(fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001);
|
||||
UASSERT(fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001);
|
||||
UASSERT(std::fabs(modulo360f(f) - fmodf(f, 360)) < 0.001);
|
||||
UASSERT(std::fabs(wrapDegrees_180(f) - ref_WrapDegrees180(f)) < 0.001);
|
||||
UASSERT(std::fabs(wrapDegrees_0_360(f) - ref_WrapDegrees_0_360(f)) < 0.001);
|
||||
UASSERT(wrapDegrees_0_360(fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue