Skip to content

Commit

Permalink
Fix various clang-tidy reported performance-type-promotion-in-math-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Apr 3, 2018
1 parent baca933 commit 67a4cb7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/collision.cpp
Expand Up @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "collision.h"
#include <cmath>
#include "mapblock.h"
#include "map.h"
#include "nodedef.h"
Expand Down Expand Up @@ -564,7 +565,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
box.MinEdge += *pos_f;
box.MaxEdge += *pos_f;
}
if (fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15f * BS) {
if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15f * BS) {
result.touching_ground = true;

if (box_info.is_object)
Expand Down
5 changes: 3 additions & 2 deletions src/content_sao.cpp
Expand Up @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "genericobject.h"
#include "settings.h"
#include <algorithm>
#include <cmath>

std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;

Expand Down Expand Up @@ -411,8 +412,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
move_d += m_last_sent_move_precision;
float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity);
if(move_d > minchange || vel_d > minchange ||
fabs(m_yaw - m_last_sent_yaw) > 1.0){
if (move_d > minchange || vel_d > minchange ||
std::fabs(m_yaw - m_last_sent_yaw) > 1.0) {
sendPosition(true, false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mapgen/mapgen_carpathian.cpp
Expand Up @@ -347,11 +347,11 @@ float MapgenCarpathian::terrainLevelAtPoint(s16 x, s16 z)

// Ridged mountains
float ridge_mnt = hilliness * (1.f - std::fabs(n_ridge_mnt));
float ridged_mountains = pow(rter, 3.f) * ridge_mnt;
float ridged_mountains = std::pow(rter, 3.f) * ridge_mnt;

// Step (terraced) mountains
float step_mnt = hilliness * getSteps(n_step_mnt);
float step_mountains = pow(ster, 3.f) * step_mnt;
float step_mountains = std::pow(ster, 3.f) * step_mnt;

// Final terrain level
float mountains = hills + ridged_mountains + step_mountains;
Expand Down
3 changes: 1 addition & 2 deletions src/mapgen/mapgen_v7.cpp
Expand Up @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_sao.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker
#include "settings.h" // For g_settings
#include "emerge.h"
#include "dungeongen.h"
Expand Down Expand Up @@ -575,7 +574,7 @@ void MapgenV7::generateRidgeTerrain()

float altitude = y - water_level;
float height_mod = (altitude + 17) / 2.5;
float width_mod = width - fabs(uwatern);
float width_mod = width - std::fabs(uwatern);
float nridge = noise_ridge->result[index] * MYMAX(altitude, 0) / 7.0;

if (nridge + width_mod * height_mod < 0.6)
Expand Down
2 changes: 1 addition & 1 deletion src/mapgen/mapgen_valleys.cpp
Expand Up @@ -433,7 +433,7 @@ int MapgenValleys::getSpawnLevelAtPoint(v2s16 p)
{
// Check to make sure this isn't a request for a location in a river.
float rivers = NoisePerlin2D(&noise_rivers->np, p.X, p.Y, seed);
if (fabs(rivers) < river_size_factor)
if (std::fabs(rivers) < river_size_factor)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point

s16 level_at_point = terrainLevelAtPoint(p.X, p.Y);
Expand Down
13 changes: 7 additions & 6 deletions src/server/serveractiveobjectmap.cpp
Expand Up @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "serveractiveobjectmap.h"
#include <cmath>
#include "constants.h"
#include "log.h"
#include "serverobject.h"
Expand All @@ -27,12 +28,12 @@ static constexpr float granularity = 16.0 * BS;
static aabb3s16 calcBox(const aabb3f &cb)
{
return aabb3s16(
floor(cb.MinEdge.X / granularity),
floor(cb.MinEdge.Y / granularity),
floor(cb.MinEdge.Z / granularity),
ceil(cb.MaxEdge.X / granularity),
ceil(cb.MaxEdge.Y / granularity),
ceil(cb.MaxEdge.Z / granularity));
std::floor(cb.MinEdge.X / granularity),
std::floor(cb.MinEdge.Y / granularity),
std::floor(cb.MinEdge.Z / granularity),
std::ceil(cb.MaxEdge.X / granularity),
std::ceil(cb.MaxEdge.Y / granularity),
std::ceil(cb.MaxEdge.Z / granularity));
}

void ServerActiveObjectMap::addObject(ServerActiveObject *object)
Expand Down
3 changes: 2 additions & 1 deletion src/unittest/test_utilities.cpp
Expand Up @@ -119,7 +119,8 @@ void TestUtilities::testAngleWrapAround()
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);
UASSERT(wrapDegrees_0_360(
std::fabs(wrapDegrees_180(f) - wrapDegrees_0_360(f))) < 0.001);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/numeric.cpp
Expand Up @@ -172,6 +172,6 @@ s16 adjustDist(s16 dist, float zoom_fov)
return dist;

// new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3)
return round(dist * cbrt((1.0f - cos(default_fov / 2.0f)) /
(1.0f - cos(zoom_fov / 2.0f))));
return round(dist * cbrt((1.0f - std::cos(default_fov / 2.0f)) /
(1.0f - std::cos(zoom_fov / 2.0f))));
}

1 comment on commit 67a4cb7

@paramat
Copy link
Contributor

@paramat paramat commented on 67a4cb7 Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-//#include "profiler.h" // For TimeTaker
Please don't remove these, left in intentionally to allow generation time to be quickly profiled by uncommenting some lines.

Please sign in to comment.