Skip to content

Commit 4827f75

Browse files
committedApr 3, 2018
Fix more clang-tidy reported problems for performance-type-promotion-in-math-fn
Based on https://travis-ci.org/minetest/minetest/jobs/361714253 output
1 parent 67a4cb7 commit 4827f75

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed
 

‎src/localplayer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "localplayer.h"
21-
21+
#include <cmath>
2222
#include "event.h"
2323
#include "collision.h"
2424
#include "nodedef.h"
@@ -941,8 +941,8 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
941941
v2f node_p2df(pf.X, pf.Z);
942942
f32 distance_f = player_p2df.getDistanceFrom(node_p2df);
943943
f32 max_axis_distance_f = MYMAX(
944-
fabs(player_p2df.X - node_p2df.X),
945-
fabs(player_p2df.Y - node_p2df.Y));
944+
std::fabs(player_p2df.X - node_p2df.X),
945+
std::fabs(player_p2df.Y - node_p2df.Y));
946946

947947
if (distance_f > min_distance_f ||
948948
max_axis_distance_f > 0.5 * BS + sneak_max + 0.1 * BS)

‎src/minimap.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "minimap.h"
21+
#include <cmath>
2122
#include "client.h"
2223
#include "clientmap.h"
2324
#include "settings.h"
@@ -428,8 +429,8 @@ v3f Minimap::getYawVec()
428429
{
429430
if (data->minimap_shape_round) {
430431
return v3f(
431-
cos(m_angle * core::DEGTORAD),
432-
sin(m_angle * core::DEGTORAD),
432+
std::cos(m_angle * core::DEGTORAD),
433+
std::sin(m_angle * core::DEGTORAD),
433434
1.0);
434435
}
435436

@@ -531,8 +532,8 @@ void Minimap::drawMinimap()
531532
core::rect<s32> img_rect(0, 0, imgsize.Width, imgsize.Height);
532533
static const video::SColor col(255, 255, 255, 255);
533534
static const video::SColor c[4] = {col, col, col, col};
534-
f32 sin_angle = sin(m_angle * core::DEGTORAD);
535-
f32 cos_angle = cos(m_angle * core::DEGTORAD);
535+
f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
536+
f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
536537
s32 marker_size2 = 0.025 * (float)size;
537538
for (std::list<v2f>::const_iterator
538539
i = m_active_markers.begin();

‎src/noise.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ float noise2d_perlin_abs(float x, float y, s32 seed,
324324
float f = 1.0;
325325
float g = 1.0;
326326
for (int i = 0; i < octaves; i++) {
327-
a += g * fabs(noise2d_gradient(x * f, y * f, seed + i, eased));
327+
a += g * std::fabs(noise2d_gradient(x * f, y * f, seed + i, eased));
328328
f *= 2.0;
329329
g *= persistence;
330330
}
@@ -354,7 +354,7 @@ float noise3d_perlin_abs(float x, float y, float z, s32 seed,
354354
float f = 1.0;
355355
float g = 1.0;
356356
for (int i = 0; i < octaves; i++) {
357-
a += g * fabs(noise3d_gradient(x * f, y * f, z * f, seed + i, eased));
357+
a += g * std::fabs(noise3d_gradient(x * f, y * f, z * f, seed + i, eased));
358358
f *= 2.0;
359359
g *= persistence;
360360
}
@@ -364,7 +364,7 @@ float noise3d_perlin_abs(float x, float y, float z, s32 seed,
364364

365365
float contour(float v)
366366
{
367-
v = fabs(v);
367+
v = std::fabs(v);
368368
if (v >= 1.0)
369369
return 0.0;
370370
return (1.0 - v);
@@ -389,7 +389,7 @@ float NoisePerlin2D(NoiseParams *np, float x, float y, s32 seed)
389389
np->flags & (NOISE_FLAG_DEFAULTS | NOISE_FLAG_EASED));
390390

391391
if (np->flags & NOISE_FLAG_ABSVALUE)
392-
noiseval = fabs(noiseval);
392+
noiseval = std::fabs(noiseval);
393393

394394
a += g * noiseval;
395395
f *= np->lacunarity;
@@ -416,7 +416,7 @@ float NoisePerlin3D(NoiseParams *np, float x, float y, float z, s32 seed)
416416
np->flags & NOISE_FLAG_EASED);
417417

418418
if (np->flags & NOISE_FLAG_ABSVALUE)
419-
noiseval = fabs(noiseval);
419+
noiseval = std::fabs(noiseval);
420420

421421
a += g * noiseval;
422422
f *= np->lacunarity;
@@ -522,9 +522,9 @@ void Noise::resizeNoiseBuf(bool is3d)
522522

523523
// + 2 for the two initial endpoints
524524
// + 1 for potentially crossing a boundary due to offset
525-
size_t nlx = (size_t)ceil(num_noise_points_x) + 3;
526-
size_t nly = (size_t)ceil(num_noise_points_y) + 3;
527-
size_t nlz = is3d ? (size_t)ceil(num_noise_points_z) + 3 : 1;
525+
size_t nlx = (size_t)std::ceil(num_noise_points_x) + 3;
526+
size_t nly = (size_t)std::ceil(num_noise_points_y) + 3;
527+
size_t nlz = is3d ? (size_t)std::ceil(num_noise_points_z) + 3 : 1;
528528

529529
delete[] noise_buf;
530530
try {
@@ -561,8 +561,8 @@ void Noise::gradientMap2D(
561561
Interp2dFxn interpolate = eased ?
562562
biLinearInterpolation : biLinearInterpolationNoEase;
563563

564-
x0 = floor(x);
565-
y0 = floor(y);
564+
x0 = std::floor(x);
565+
y0 = std::floor(y);
566566
u = x - (float)x0;
567567
v = y - (float)y0;
568568
orig_u = u;
@@ -626,9 +626,9 @@ void Noise::gradientMap3D(
626626
Interp3dFxn interpolate = (np.flags & NOISE_FLAG_EASED) ?
627627
triLinearInterpolation : triLinearInterpolationNoEase;
628628

629-
x0 = floor(x);
630-
y0 = floor(y);
631-
z0 = floor(z);
629+
x0 = std::floor(x);
630+
y0 = std::floor(y);
631+
z0 = std::floor(z);
632632
u = x - (float)x0;
633633
v = y - (float)y0;
634634
w = z - (float)z0;
@@ -730,7 +730,7 @@ float *Noise::perlinMap2D(float x, float y, float *persistence_map)
730730
g *= np.persist;
731731
}
732732

733-
if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) {
733+
if (std::fabs(np.offset - 0.f) > 0.00001 || std::fabs(np.scale - 1.f) > 0.00001) {
734734
for (size_t i = 0; i != bufsize; i++)
735735
result[i] = result[i] * np.scale + np.offset;
736736
}
@@ -768,7 +768,7 @@ float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map)
768768
g *= np.persist;
769769
}
770770

771-
if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) {
771+
if (std::fabs(np.offset - 0.f) > 0.00001 || std::fabs(np.scale - 1.f) > 0.00001) {
772772
for (size_t i = 0; i != bufsize; i++)
773773
result[i] = result[i] * np.scale + np.offset;
774774
}
@@ -785,12 +785,12 @@ void Noise::updateResults(float g, float *gmap,
785785
if (np.flags & NOISE_FLAG_ABSVALUE) {
786786
if (persistence_map) {
787787
for (size_t i = 0; i != bufsize; i++) {
788-
result[i] += gmap[i] * fabs(gradient_buf[i]);
788+
result[i] += gmap[i] * std::fabs(gradient_buf[i]);
789789
gmap[i] *= persistence_map[i];
790790
}
791791
} else {
792792
for (size_t i = 0; i != bufsize; i++)
793-
result[i] += g * fabs(gradient_buf[i]);
793+
result[i] += g * std::fabs(gradient_buf[i]);
794794
}
795795
} else {
796796
if (persistence_map) {

0 commit comments

Comments
 (0)