Skip to content

Commit

Permalink
Fix clang-tidy type promotion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Feb 26, 2024
1 parent 229389b commit 9fcd7f2
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/client/clientenvironment.cpp
Expand Up @@ -182,7 +182,7 @@ void ClientEnvironment::step(float dtime)
Stuff that has a maximum time increment
*/

u32 steps = ceil(dtime / dtime_max_increment);
u32 steps = std::ceil(dtime / dtime_max_increment);
f32 dtime_part = dtime / steps;
for (; steps > 0; --steps) {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/client/clientmap.cpp
Expand Up @@ -1305,7 +1305,7 @@ void ClientMap::updateTransparentMeshBuffers()
ScopeProfiler sp(g_profiler, "CM::updateTransparentMeshBuffers", SPT_AVG);
u32 sorted_blocks = 0;
u32 unsorted_blocks = 0;
f32 sorting_distance_sq = pow(m_cache_transparency_sorting_distance * BS, 2.0f);
f32 sorting_distance_sq = std::pow(m_cache_transparency_sorting_distance * BS, 2.0f);


// Update the order of transparent mesh buffers in each mesh
Expand Down
2 changes: 1 addition & 1 deletion src/client/content_cao.cpp
Expand Up @@ -1216,7 +1216,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
}
}

if (node && fabs(m_prop.automatic_rotate) > 0.001f) {
if (node && std::abs(m_prop.automatic_rotate) > 0.001f) {
// This is the child node's rotation. It is only used for automatic_rotate.
v3f local_rot = node->getRotation();
local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG *
Expand Down
10 changes: 5 additions & 5 deletions src/client/game.cpp
Expand Up @@ -2648,7 +2648,7 @@ f32 Game::getSensitivityScaleFactor() const
// Multiply by a constant such that it becomes 1.0 at 72 degree FOV and
// 16:9 aspect ratio to minimize disruption of existing sensitivity
// settings.
return tan(fov_y / 2.0f) * 1.3763818698f;
return std::tan(fov_y / 2.0f) * 1.3763819f;
}

void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
Expand Down Expand Up @@ -2711,8 +2711,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
client->activeObjectsReceived() && !player->isDead()) {
control.movement_speed = 1.0f;
// sideways movement only
float dx = sin(control.movement_direction);
control.movement_direction = atan2(dx, 1.0f);
float dx = std::sin(control.movement_direction);
control.movement_direction = std::atan2(dx, 1.0f);
}

/* For touch, simulate holding down AUX1 (fast move) if the user has
Expand Down Expand Up @@ -4250,14 +4250,14 @@ void Game::updateShadows()
if (!shadow)
return;

float in_timeofday = fmod(runData.time_of_day_smooth, 1.0f);
float in_timeofday = std::fmod(runData.time_of_day_smooth, 1.0f);

float timeoftheday = getWickedTimeOfDay(in_timeofday);
bool is_day = timeoftheday > 0.25 && timeoftheday < 0.75;
bool is_shadow_visible = is_day ? sky->getSunVisible() : sky->getMoonVisible();
shadow->setShadowIntensity(is_shadow_visible ? client->getEnv().getLocalPlayer()->getLighting().shadow_intensity : 0.0f);

timeoftheday = fmod(timeoftheday + 0.75f, 0.5f) + 0.25f;
timeoftheday = std::fmod(timeoftheday + 0.75f, 0.5f) + 0.25f;
const float offset_constant = 10000.0f;

v3f light = is_day ? sky->getSunDirection() : sky->getMoonDirection();
Expand Down
6 changes: 4 additions & 2 deletions src/client/joystick_controller.cpp
Expand Up @@ -318,12 +318,14 @@ float JoystickController::getAxisWithoutDead(JoystickAxis axis)

float JoystickController::getMovementDirection()
{
return atan2(getAxisWithoutDead(JA_SIDEWARD_MOVE), -getAxisWithoutDead(JA_FORWARD_MOVE));
return std::atan2(getAxisWithoutDead(JA_SIDEWARD_MOVE),
-getAxisWithoutDead(JA_FORWARD_MOVE));
}

float JoystickController::getMovementSpeed()
{
float speed = sqrt(pow(getAxisWithoutDead(JA_FORWARD_MOVE), 2) + pow(getAxisWithoutDead(JA_SIDEWARD_MOVE), 2));
float speed = std::sqrt(std::pow(getAxisWithoutDead(JA_FORWARD_MOVE), 2) +
std::pow(getAxisWithoutDead(JA_SIDEWARD_MOVE), 2));
if (speed > 1.0f)
speed = 1.0f;
return speed;
Expand Down
3 changes: 2 additions & 1 deletion src/client/localplayer.cpp
Expand Up @@ -600,7 +600,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
}
}

speedH = v3f(sin(control.movement_direction), 0.0f, cos(control.movement_direction));
speedH = v3f(std::sin(control.movement_direction), 0.0f,
std::cos(control.movement_direction));

if (m_autojump) {
// release autojump after a given time
Expand Down
4 changes: 2 additions & 2 deletions src/client/shadows/dynamicshadowsrender.cpp
Expand Up @@ -171,8 +171,8 @@ f32 ShadowRenderer::getMaxShadowFar() const

void ShadowRenderer::setShadowIntensity(float shadow_intensity)
{
m_shadow_strength = pow(shadow_intensity, 1.0f / m_shadow_strength_gamma);
if (m_shadow_strength > 1E-2)
m_shadow_strength = std::pow(shadow_intensity, 1.0f / m_shadow_strength_gamma);
if (m_shadow_strength > 1e-2f)
enable();
else
disable();
Expand Down
2 changes: 1 addition & 1 deletion src/client/sky.cpp
Expand Up @@ -680,7 +680,7 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day)

float tod = wicked_time_of_day < 0.5f ? wicked_time_of_day : (1.0f - wicked_time_of_day);
float day_opacity = clamp(m_star_params.day_opacity, 0.0f, 1.0f);
float starbrightness = (0.25f - fabs(tod)) * 20.0f;
float starbrightness = (0.25f - std::abs(tod)) * 20.0f;
float alpha = clamp(starbrightness, day_opacity, 1.0f);

m_star_color = m_star_params.starcolor;
Expand Down
2 changes: 1 addition & 1 deletion src/server/luaentity_sao.cpp
Expand Up @@ -203,7 +203,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}
}

if (fabs(m_prop.automatic_rotate) > 0.001f) {
if (std::abs(m_prop.automatic_rotate) > 0.001f) {
m_rotation_add_yaw = modulo360f(m_rotation_add_yaw + dtime * core::RADTODEG *
m_prop.automatic_rotate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tileanimation.cpp
Expand Up @@ -31,11 +31,11 @@ void TileAnimationParams::serialize(std::ostream &os, u16 protocol_ver) const
if (type == TAT_VERTICAL_FRAMES) {
writeU16(os, vertical_frames.aspect_w);
writeU16(os, vertical_frames.aspect_h);
writeF32(os, need_abs ? fabs(vertical_frames.length) : vertical_frames.length);
writeF32(os, need_abs ? std::abs(vertical_frames.length) : vertical_frames.length);
} else if (type == TAT_SHEET_2D) {
writeU8(os, sheet_2d.frames_w);
writeU8(os, sheet_2d.frames_h);
writeF32(os, need_abs ? fabs(sheet_2d.frame_length) : sheet_2d.frame_length);
writeF32(os, need_abs ? std::abs(sheet_2d.frame_length) : sheet_2d.frame_length);
}
}

Expand Down

0 comments on commit 9fcd7f2

Please sign in to comment.