Fix various clang-tidy reported performance-type-promotion-in-math-fn
authorLoïc Blot <loic.blot@unix-experience.fr>
Tue, 3 Apr 2018 16:16:17 +0000 (18:16 +0200)
committerLoïc Blot <loic.blot@unix-experience.fr>
Tue, 3 Apr 2018 16:16:17 +0000 (18:16 +0200)
src/collision.cpp
src/content_sao.cpp
src/mapgen/mapgen_carpathian.cpp
src/mapgen/mapgen_v7.cpp
src/mapgen/mapgen_valleys.cpp
src/server/serveractiveobjectmap.cpp
src/unittest/test_utilities.cpp
src/util/numeric.cpp

index 24d22e8252ab44a3d1a75d40d079bfd936c85b11..e966ad19deb84289c6d0d6034c3342013420a692 100644 (file)
@@ -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"
@@ -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)
index 0e0c19fceb5292cb4393d28bbcd2b8e5dca2b40e..8f77d54c44c481286de19bc3181b0e466a56887d 100644 (file)
@@ -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;
 
@@ -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);
                }
        }
index db276ffbae1462154ae7409ed7ff5280fbf403bb..1e12eafc360e962c73f022aec60adde6a6967bb7 100644 (file)
@@ -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;
index fba2defef819fc41394ce44029b14a2860f2ba29..a99a50f297d4d2514d46590affa904e5e66234f6 100644 (file)
@@ -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"
@@ -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)
index 54643583b3fca13606d69a8a70625902d035cfa0..bef4629a8019a40c39b5abae1d33946de91cc1db 100644 (file)
@@ -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);
index e2def776dd1553478ec5d1c2f5b99cd83768cf06..ac89d5d18d2c21bc8b5fbb058b1f7dfbe1d84469 100644 (file)
@@ -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"
@@ -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)
index 95c34a9c7e3e8224a8a6372ca993f4f03abf9832..315cbf0fc3854cd7542e6857e3a41f448165e7a0 100644 (file)
@@ -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);
        }
 }
 
index 12c91be913ff05ce3a2529781703998d0e40cf30..cb984d8cb5b60879f7f11bb158c2162afca11848 100644 (file)
@@ -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))));
 }