summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorNicholas-Baron <nicholas.baron.ten@gmail.com>2021-04-15 00:36:14 -0700
committerAndreas Kling <kling@serenityos.org>2021-04-16 19:01:54 +0200
commit73dd293ec4ffcfefae9db8e10eaaa84d4a4be4a8 (patch)
tree835bd47b8c14f8af6b070f1adbeef630db28d5a9 /Userland
parent6606d70826b21c803742ed2b971d061b7f3497e3 (diff)
downloadserenity-73dd293ec4ffcfefae9db8e10eaaa84d4a4be4a8.zip
Everywhere: Add `-Wdouble-promotion` warning
This warning informs of float-to-double conversions. The best solution seems to be to do math *either* in 32-bit *or* in 64-bit, and only to cross over when absolutely necessary.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applets/ResourceGraph/main.cpp4
-rw-r--r--Userland/Applications/MouseSettings/MouseSettingsWindow.cpp2
-rw-r--r--Userland/Applications/PixelPaint/BrushTool.cpp2
-rw-r--r--Userland/Applications/PixelPaint/FilterParams.h4
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp7
-rw-r--r--Userland/Applications/PixelPaint/LineTool.cpp10
-rw-r--r--Userland/Applications/PixelPaint/SprayTool.cpp2
-rw-r--r--Userland/Applications/QuickShow/QSWidget.cpp7
-rw-r--r--Userland/Demos/Cube/Cube.cpp12
-rw-r--r--Userland/DevTools/Profiler/main.cpp2
-rw-r--r--Userland/Games/Chess/ChessWidget.cpp15
-rw-r--r--Userland/Games/Solitaire/SolitaireWidget.cpp2
-rw-r--r--Userland/Libraries/LibGfx/Gamma.h10
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp2
-rw-r--r--Userland/Libraries/LibGfx/Path.cpp8
-rw-r--r--Userland/Libraries/LibGfx/Rect.cpp2
-rw-r--r--Userland/Libraries/LibM/math.cpp16
-rw-r--r--Userland/Libraries/LibTTF/Glyf.cpp40
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h2
-rw-r--r--Userland/Libraries/LibWeb/Dump.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp12
-rw-r--r--Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp2
-rw-r--r--Userland/Services/WindowServer/ClientConnection.cpp7
-rw-r--r--Userland/Services/WindowServer/Screen.h6
24 files changed, 93 insertions, 87 deletions
diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp
index d686190246..f4e19525dd 100644
--- a/Userland/Applets/ResourceGraph/main.cpp
+++ b/Userland/Applets/ResourceGraph/main.cpp
@@ -74,7 +74,7 @@ private:
m_last_cpu_idle = idle;
float cpu = (float)busy_diff / (float)(busy_diff + idle_diff);
m_history.enqueue(cpu);
- m_tooltip = String::format("CPU usage: %.1f%%", 100 * cpu);
+ m_tooltip = String::formatted("CPU usage: {:.1}%", 100 * cpu);
} else {
m_history.enqueue(-1);
m_tooltip = StringView("Unable to determine CPU usage");
@@ -87,7 +87,7 @@ private:
double total_memory = allocated + available;
double memory = (double)allocated / total_memory;
m_history.enqueue(memory);
- m_tooltip = String::format("Memory: %.1f MiB of %.1f MiB in use", (float)(allocated / MiB), (float)(total_memory / MiB));
+ m_tooltip = String::formatted("Memory: {} MiB of {:.1} MiB in use", allocated / MiB, total_memory / MiB);
} else {
m_history.enqueue(-1);
m_tooltip = StringView("Unable to determine memory usage");
diff --git a/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp b/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp
index e31b657725..1fe132d3a4 100644
--- a/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp
+++ b/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp
@@ -68,7 +68,7 @@ MouseSettingsWindow::MouseSettingsWindow()
m_speed_slider->on_change = [&](const int value) {
m_speed_label->set_text(String::formatted("{} %", value));
};
- const int slider_value = speed_slider_scale * GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::GetMouseAcceleration>()->factor();
+ const int slider_value = float { speed_slider_scale } * GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::GetMouseAcceleration>()->factor();
m_speed_slider->set_value(slider_value);
m_scroll_length_spinbox = *main_widget.find_descendant_of_type_named<GUI::SpinBox>("scroll_length_spinbox");
diff --git a/Userland/Applications/PixelPaint/BrushTool.cpp b/Userland/Applications/PixelPaint/BrushTool.cpp
index df0eec7acc..66638da0f3 100644
--- a/Userland/Applications/PixelPaint/BrushTool.cpp
+++ b/Userland/Applications/PixelPaint/BrushTool.cpp
@@ -82,7 +82,7 @@ void BrushTool::draw_point(Gfx::Bitmap& bitmap, const Gfx::Color& color, const G
if (distance >= m_size)
continue;
- auto falloff = (1.0 - (distance / (float)m_size)) * (1.0f / (100 - m_hardness));
+ auto falloff = (1.0 - double { distance / m_size }) * (1.0 / (100 - m_hardness));
auto pixel_color = color;
pixel_color.set_alpha(falloff * 255);
bitmap.set_pixel(x, y, bitmap.get_pixel(x, y).blend(pixel_color));
diff --git a/Userland/Applications/PixelPaint/FilterParams.h b/Userland/Applications/PixelPaint/FilterParams.h
index 398caecf9f..8440d27e5c 100644
--- a/Userland/Applications/PixelPaint/FilterParams.h
+++ b/Userland/Applications/PixelPaint/FilterParams.h
@@ -127,8 +127,8 @@ struct FilterParameters<Gfx::SpatialGaussianBlurFilter<N>> {
for (auto x = -offset; x <= offset; x++) {
for (auto y = -offset; y <= offset; y++) {
- auto r = sqrt(x * x + y * y);
- kernel.elements()[x + offset][y + offset] = (exp(-(r * r) / s)) / (M_PI * s);
+ auto r = sqrtf(x * x + y * y);
+ kernel.elements()[x + offset][y + offset] = (expf(-(r * r) / s)) / (float { M_PI } * s);
}
}
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 0198b49eca..e91cbcf275 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -380,9 +380,10 @@ void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, floa
if (m_scale > 100.0f)
m_scale = 100.0f;
- auto focus_point = Gfx::FloatPoint(
- m_pan_origin.x() - ((float)position.x() - (float)width() / 2.0) / old_scale,
- m_pan_origin.y() - ((float)position.y() - (float)height() / 2.0) / old_scale);
+ Gfx::FloatPoint focus_point {
+ m_pan_origin.x() - (position.x() - width() / 2.0f) / old_scale,
+ m_pan_origin.y() - (position.y() - height() / 2.0f) / old_scale
+ };
m_pan_origin = Gfx::FloatPoint(
focus_point.x() - m_scale / old_scale * (focus_point.x() - m_pan_origin.x()),
diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp
index 7c3e37e836..2f5738872a 100644
--- a/Userland/Applications/PixelPaint/LineTool.cpp
+++ b/Userland/Applications/PixelPaint/LineTool.cpp
@@ -36,15 +36,15 @@ namespace PixelPaint {
static Gfx::IntPoint constrain_line_angle(const Gfx::IntPoint& start_pos, const Gfx::IntPoint& end_pos, float angle_increment)
{
- float current_angle = atan2(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + M_PI * 2.;
+ float current_angle = atan2f(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + float { M_PI * 2 };
- float constrained_angle = ((int)((current_angle + angle_increment / 2.) / angle_increment)) * angle_increment;
+ float constrained_angle = ((int)((current_angle + angle_increment / 2) / angle_increment)) * angle_increment;
auto diff = end_pos - start_pos;
float line_length = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
- return { start_pos.x() + (int)(cos(constrained_angle) * line_length),
- start_pos.y() + (int)(sin(constrained_angle) * line_length) };
+ return { start_pos.x() + (int)(cosf(constrained_angle) * line_length),
+ start_pos.y() + (int)(sinf(constrained_angle) * line_length) };
}
LineTool::LineTool()
@@ -90,7 +90,7 @@ void LineTool::on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEven
if (!m_constrain_angle) {
m_line_end_position = layer_event.position();
} else {
- const float ANGLE_STEP = M_PI / 8.0f;
+ constexpr auto ANGLE_STEP = M_PI / 8;
m_line_end_position = constrain_line_angle(m_line_start_position, layer_event.position(), ANGLE_STEP);
}
m_editor->update();
diff --git a/Userland/Applications/PixelPaint/SprayTool.cpp b/Userland/Applications/PixelPaint/SprayTool.cpp
index 51d5a7e83b..523a7a0850 100644
--- a/Userland/Applications/PixelPaint/SprayTool.cpp
+++ b/Userland/Applications/PixelPaint/SprayTool.cpp
@@ -70,7 +70,7 @@ void SprayTool::paint_it()
m_editor->update();
const double minimal_radius = 2;
const double base_radius = minimal_radius * m_thickness;
- for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0f); i++) {
+ for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0); i++) {
double radius = base_radius * nrand();
double angle = 2 * M_PI * nrand();
const int xpos = m_last_pos.x() + radius * cos(angle);
diff --git a/Userland/Applications/QuickShow/QSWidget.cpp b/Userland/Applications/QuickShow/QSWidget.cpp
index 7a52e43fe6..8b2ffbdccf 100644
--- a/Userland/Applications/QuickShow/QSWidget.cpp
+++ b/Userland/Applications/QuickShow/QSWidget.cpp
@@ -235,9 +235,10 @@ void QSWidget::mousewheel_event(GUI::MouseEvent& event)
// We want the image after scaling to be panned in such a way that the cursor
// will still point to the same image pixel. Basically, we need to solve
// (m_pan_origin + focus_point) / old_scale_factor = (new_m_pan_origin + focus_point) / new_scale_factor.
- auto focus_point = Gfx::FloatPoint(
- (float)event.x() - (float)width() / 2.0,
- (float)event.y() - (float)height() / 2.0);
+ Gfx::FloatPoint focus_point {
+ event.x() - width() / 2.0f,
+ event.y() - height() / 2.0f
+ };
// A little algebra shows that new m_pan_origin equals to:
m_pan_origin = (m_pan_origin + focus_point) * (new_scale_factor / old_scale_factor) - focus_point;
diff --git a/Userland/Demos/Cube/Cube.cpp b/Userland/Demos/Cube/Cube.cpp
index 807fcf8595..0758c71981 100644
--- a/Userland/Demos/Cube/Cube.cpp
+++ b/Userland/Demos/Cube/Cube.cpp
@@ -177,12 +177,12 @@ void Cube::timer_event(Core::TimerEvent&)
normal.normalize();
// Perspective projection
- a.set_x(WIDTH / 2 + a.x() / (1 + a.z() * 0.35) * WIDTH / 3);
- a.set_y(HEIGHT / 2 - a.y() / (1 + a.z() * 0.35) * WIDTH / 3);
- b.set_x(WIDTH / 2 + b.x() / (1 + b.z() * 0.35) * WIDTH / 3);
- b.set_y(HEIGHT / 2 - b.y() / (1 + b.z() * 0.35) * WIDTH / 3);
- c.set_x(WIDTH / 2 + c.x() / (1 + c.z() * 0.35) * WIDTH / 3);
- c.set_y(HEIGHT / 2 - c.y() / (1 + c.z() * 0.35) * WIDTH / 3);
+ a.set_x(WIDTH / 2 + a.x() / (1 + a.z() * 0.35f) * WIDTH / 3);
+ a.set_y(HEIGHT / 2 - a.y() / (1 + a.z() * 0.35f) * WIDTH / 3);
+ b.set_x(WIDTH / 2 + b.x() / (1 + b.z() * 0.35f) * WIDTH / 3);
+ b.set_y(HEIGHT / 2 - b.y() / (1 + b.z() * 0.35f) * WIDTH / 3);
+ c.set_x(WIDTH / 2 + c.x() / (1 + c.z() * 0.35f) * WIDTH / 3);
+ c.set_y(HEIGHT / 2 - c.y() / (1 + c.z() * 0.35f) * WIDTH / 3);
float winding = (b.x() - a.x()) * (c.y() - a.y()) - (b.y() - a.y()) * (c.x() - a.x());
if (winding < 0)
diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp
index 76c8aff332..96912eacc8 100644
--- a/Userland/DevTools/Profiler/main.cpp
+++ b/Userland/DevTools/Profiler/main.cpp
@@ -194,7 +194,7 @@ static bool prompt_to_stop_profiling(pid_t pid, const String& process_name)
Core::ElapsedTimer clock;
clock.start();
auto update_timer = Core::Timer::construct(100, [&] {
- timer_label.set_text(String::format("%.1f seconds", (float)clock.elapsed() / 1000.0f));
+ timer_label.set_text(String::formatted("{:.1} seconds", clock.elapsed() / 1000.0f));
});
auto& stop_button = widget.add<GUI::Button>("Stop");
diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp
index e3b31b33e3..c96ef0715c 100644
--- a/Userland/Games/Chess/ChessWidget.cpp
+++ b/Userland/Games/Chess/ChessWidget.cpp
@@ -111,15 +111,18 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
float dx = B.x() - A.x();
float dy = A.y() - B.y();
float phi = atan2f(dy, dx);
- float hdx = h * cos(phi);
- float hdy = h * sin(phi);
+ float hdx = h * cosf(phi);
+ float hdy = h * sinf(phi);
- Gfx::FloatPoint A1(A.x() - (w1 / 2) * cos(M_PI_2 - phi), A.y() - (w1 / 2) * sin(M_PI_2 - phi));
- Gfx::FloatPoint B3(A.x() + (w1 / 2) * cos(M_PI_2 - phi), A.y() + (w1 / 2) * sin(M_PI_2 - phi));
+ const auto cos_pi_2_phi = cosf(float { M_PI_2 } - phi);
+ const auto sin_pi_2_phi = sinf(float { M_PI_2 } - phi);
+
+ Gfx::FloatPoint A1(A.x() - (w1 / 2) * cos_pi_2_phi, A.y() - (w1 / 2) * sin_pi_2_phi);
+ Gfx::FloatPoint B3(A.x() + (w1 / 2) * cos_pi_2_phi, A.y() + (w1 / 2) * sin_pi_2_phi);
Gfx::FloatPoint A2(A1.x() + (dx - hdx), A1.y() - (dy - hdy));
Gfx::FloatPoint B2(B3.x() + (dx - hdx), B3.y() - (dy - hdy));
- Gfx::FloatPoint A3(A2.x() - w2 * cos(M_PI_2 - phi), A2.y() - w2 * sin(M_PI_2 - phi));
- Gfx::FloatPoint B1(B2.x() + w2 * cos(M_PI_2 - phi), B2.y() + w2 * sin(M_PI_2 - phi));
+ Gfx::FloatPoint A3(A2.x() - w2 * cos_pi_2_phi, A2.y() - w2 * sin_pi_2_phi);
+ Gfx::FloatPoint B1(B2.x() + w2 * cos_pi_2_phi, B2.y() + w2 * sin_pi_2_phi);
auto path = Gfx::Path();
path.move_to(A);
diff --git a/Userland/Games/Solitaire/SolitaireWidget.cpp b/Userland/Games/Solitaire/SolitaireWidget.cpp
index fbf1cc7eb1..0a2e04c643 100644
--- a/Userland/Games/Solitaire/SolitaireWidget.cpp
+++ b/Userland/Games/Solitaire/SolitaireWidget.cpp
@@ -92,7 +92,7 @@ void SolitaireWidget::create_new_animation_card()
card->set_position({ rand() % (SolitaireWidget::width - Card::width), rand() % (SolitaireWidget::height / 8) });
int x_sgn = card->position().x() > (SolitaireWidget::width / 2) ? -1 : 1;
- m_animation = Animation(card, rand_float() + .4, x_sgn * ((rand() % 3) + 2), .6 + rand_float() * .4);
+ m_animation = Animation(card, rand_float() + .4f, x_sgn * ((rand() % 3) + 2), .6f + rand_float() * .4f);
}
void SolitaireWidget::start_game_over_animation()
diff --git a/Userland/Libraries/LibGfx/Gamma.h b/Userland/Libraries/LibGfx/Gamma.h
index f0f3b86f25..345e30bff5 100644
--- a/Userland/Libraries/LibGfx/Gamma.h
+++ b/Userland/Libraries/LibGfx/Gamma.h
@@ -95,7 +95,7 @@ inline f32x4 gamma_accurate_lerp4(f32x4 v1, f32x4 v2, float mix)
// Assumes x is in range [0, 1]
constexpr float gamma_to_linear(float x)
{
- return (0.8 + 0.2 * x) * x * x;
+ return (0.8f + 0.2f * x) * x * x;
}
// Transform scalar from linear space to gamma2.2 space
@@ -105,7 +105,7 @@ inline float linear_to_gamma(float x)
// Source for approximation: https://mimosa-pudica.net/fast-gamma/
constexpr float a = 0.00279491;
constexpr float b = 1.15907984;
- float c = (b / sqrt(1 + a)) - 1;
+ float c = (b / sqrtf(1 + a)) - 1;
return ((b / __builtin_sqrtf(x + a)) - c) * x;
}
@@ -135,9 +135,9 @@ inline Color gamma_accurate_blend(Color a, Color b, float mix)
return Color(out[0], out[1], out[2]);
# else
return {
- static_cast<u8>(255. * gamma_accurate_lerp(a.red() / 255., b.red() / 255., mix)),
- static_cast<u8>(255. * gamma_accurate_lerp(a.green() / 255., b.green() / 255., mix)),
- static_cast<u8>(255. * gamma_accurate_lerp(a.blue() / 255., b.blue() / 255., mix)),
+ static_cast<u8>(255.f * gamma_accurate_lerp(a.red() / 255.f, b.red() / 255.f, mix)),
+ static_cast<u8>(255.f * gamma_accurate_lerp(a.green() / 255.f, b.green() / 255.f, mix)),
+ static_cast<u8>(255.f * gamma_accurate_lerp(a.blue() / 255.f, b.blue() / 255.f, mix)),
};
# endif
}
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp
index e16792f716..2ad3624c7a 100644
--- a/Userland/Libraries/LibGfx/Painter.cpp
+++ b/Userland/Libraries/LibGfx/Painter.cpp
@@ -299,7 +299,7 @@ void Painter::draw_ellipse_intersecting(const IntRect& rect, Color color, int th
return (sin(theta) * rect.height() / sqrt(2)) + rect.center().y();
};
- for (float theta = 0; theta < 2 * M_PI; theta += increment) {
+ for (auto theta = 0.0; theta < 2 * M_PI; theta += increment) {
draw_line({ ellipse_x(theta), ellipse_y(theta) }, { ellipse_x(theta + increment), ellipse_y(theta + increment) }, color, thickness);
}
}
diff --git a/Userland/Libraries/LibGfx/Path.cpp b/Userland/Libraries/LibGfx/Path.cpp
index 9bb4e7fa53..18378d3be8 100644
--- a/Userland/Libraries/LibGfx/Path.cpp
+++ b/Userland/Libraries/LibGfx/Path.cpp
@@ -75,8 +75,8 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
// Find (cx, cy), theta_1, theta_delta
// Step 1: Compute (x1', y1')
- auto x_avg = (last_point.x() - next_point.x()) / 2.0f;
- auto y_avg = (last_point.y() - next_point.y()) / 2.0f;
+ auto x_avg = static_cast<double>(last_point.x() - next_point.x()) / 2.0;
+ auto y_avg = static_cast<double>(last_point.y() - next_point.y()) / 2.0;
auto x1p = x_axis_rotation_c * x_avg + x_axis_rotation_s * y_avg;
auto y1p = -x_axis_rotation_s * x_avg + x_axis_rotation_c * y_avg;
@@ -118,7 +118,7 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
auto theta_delta = theta_2 - theta_1;
- if (!sweep && theta_delta > 0.0f) {
+ if (!sweep && theta_delta > 0.0) {
theta_delta -= 2 * M_PI;
} else if (sweep && theta_delta < 0) {
theta_delta += 2 * M_PI;
@@ -226,7 +226,7 @@ String Path::to_string() const
break;
case Segment::Type::EllipticalArcTo: {
auto& arc = static_cast<const EllipticalArcSegment&>(segment);
- builder.appendf(", %s, %s, %f, %f, %f",
+ builder.appendff(", {}, {}, {}, {}, {}",
arc.radii().to_string().characters(),
arc.center().to_string().characters(),
arc.x_axis_rotation(),
diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp
index 0a9ce4fc3b..ff135e6afd 100644
--- a/Userland/Libraries/LibGfx/Rect.cpp
+++ b/Userland/Libraries/LibGfx/Rect.cpp
@@ -160,7 +160,7 @@ String IntRect::to_string() const
template<>
String FloatRect::to_string() const
{
- return String::format("[%f,%f %fx%f]", x(), y(), width(), height());
+ return String::formatted("[{},{} {}x{}]", x(), y(), width(), height());
}
}
diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp
index dc162a5873..12facc0850 100644
--- a/Userland/Libraries/LibM/math.cpp
+++ b/Userland/Libraries/LibM/math.cpp
@@ -172,9 +172,9 @@ static FloatType internal_to_integer(FloatType x, RoundingMode rounding_mode)
// We could do this ourselves, but this saves us from manually
// handling overflow.
if (extractor.sign)
- extractor.d -= 1.0;
+ extractor.d -= static_cast<FloatType>(1.0);
else
- extractor.d += 1.0;
+ extractor.d += static_cast<FloatType>(1.0);
}
return extractor.d;
@@ -339,7 +339,7 @@ static FloatT internal_gamma(FloatT x) NOEXCEPT
}
// Stirling approximation
- return sqrtl(2.0 * M_PI / x) * powl(x / M_E, x);
+ return sqrtl(2.0 * M_PI / static_cast<long double>(x)) * powl(static_cast<long double>(x) / M_E, static_cast<long double>(x));
}
extern "C" {
@@ -386,7 +386,7 @@ double cos(double angle) NOEXCEPT
float cosf(float angle) NOEXCEPT
{
- return sinf(angle + M_PI_2);
+ return sinf(angle + static_cast<float>(M_PI_2));
}
long double sinl(long double angle) NOEXCEPT
@@ -636,7 +636,7 @@ double fmod(double index, double period) NOEXCEPT
float fmodf(float index, float period) NOEXCEPT
{
- return index - trunc(index / period) * period;
+ return index - truncf(index / period) * period;
}
// FIXME: These aren't exactly like fmod, but these definitions are probably good enough for now
@@ -818,7 +818,7 @@ double acos(double x) NOEXCEPT
float acosf(float x) NOEXCEPT
{
- return M_PI_2 - asinf(x);
+ return static_cast<float>(M_PI_2) - asinf(x);
}
long double fabsl(long double value) NOEXCEPT
@@ -1104,9 +1104,9 @@ double lgamma_r(double value, int* sign) NOEXCEPT
float lgammaf_r(float value, int* sign) NOEXCEPT
{
- if (value == 1.0 || value == 2.0)
+ if (value == 1.0f || value == 2.0f)
return 0.0;
- if (isinf(value) || value == 0.0)
+ if (isinf(value) || value == 0.0f)
return INFINITY;
float result = logf(internal_gamma(value));
*sign = signbit(result) ? -1 : 1;
diff --git a/Userland/Libraries/LibTTF/Glyf.cpp b/Userland/Libraries/LibTTF/Glyf.cpp
index de1b5a292c..8c07ed5030 100644
--- a/Userland/Libraries/LibTTF/Glyf.cpp
+++ b/Userland/Libraries/LibTTF/Glyf.cpp
@@ -214,7 +214,7 @@ Rasterizer::Rasterizer(Gfx::IntSize size)
{
m_data.resize(m_size.width() * m_size.height());
for (int i = 0; i < m_size.width() * m_size.height(); i++) {
- m_data[i] = 0.0;
+ m_data[i] = 0.0f;
}
}
@@ -234,13 +234,13 @@ RefPtr<Gfx::Bitmap> Rasterizer::accumulate()
for (int x = 0; x < m_size.width(); x++) {
accumulator += m_data[y * m_size.width() + x];
float value = accumulator;
- if (value < 0.0) {
+ if (value < 0.0f) {
value = -value;
}
- if (value > 1.0) {
+ if (value > 1.0f) {
value = 1.0;
}
- u8 alpha = value * 255.0;
+ u8 alpha = value * 255.0f;
bitmap->set_pixel(x, y, base_color.with_alpha(alpha));
}
}
@@ -250,31 +250,31 @@ RefPtr<Gfx::Bitmap> Rasterizer::accumulate()
void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
{
// FIXME: Shift x and y according to dy/dx
- if (p0.x() < 0.0) {
+ if (p0.x() < 0.0f) {
p0.set_x(roundf(p0.x()));
}
- if (p0.y() < 0.0) {
+ if (p0.y() < 0.0f) {
p0.set_y(roundf(p0.y()));
}
- if (p1.x() < 0.0) {
+ if (p1.x() < 0.0f) {
p1.set_x(roundf(p1.x()));
}
- if (p1.y() < 0.0) {
+ if (p1.y() < 0.0f) {
p1.set_y(roundf(p1.y()));
}
- if (!(p0.x() >= 0.0 && p0.y() >= 0.0 && p0.x() <= m_size.width() && p0.y() <= m_size.height())) {
+ if (!(p0.x() >= 0.0f && p0.y() >= 0.0f && p0.x() <= m_size.width() && p0.y() <= m_size.height())) {
dbgln("!P0({},{})", p0.x(), p0.y());
return;
}
- if (!(p1.x() >= 0.0 && p1.y() >= 0.0 && p1.x() <= m_size.width() && p1.y() <= m_size.height())) {
+ if (!(p1.x() >= 0.0f && p1.y() >= 0.0f && p1.x() <= m_size.width() && p1.y() <= m_size.height())) {
dbgln("!P1({},{})", p1.x(), p1.y());
return;
}
- VERIFY(p0.x() >= 0.0 && p0.y() >= 0.0 && p0.x() <= m_size.width() && p0.y() <= m_size.height());
- VERIFY(p1.x() >= 0.0 && p1.y() >= 0.0 && p1.x() <= m_size.width() && p1.y() <= m_size.height());
+ VERIFY(p0.x() >= 0.0f && p0.y() >= 0.0f && p0.x() <= m_size.width() && p0.y() <= m_size.height());
+ VERIFY(p1.x() >= 0.0f && p1.y() >= 0.0f && p1.x() <= m_size.width() && p1.y() <= m_size.height());
// If we're on the same Y, there's no need to draw
if (p0.y() == p1.y()) {
@@ -300,8 +300,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
float dy = min(y + 1.0f, p1.y()) - max((float)y, p0.y());
float directed_dy = dy * direction;
float x_next = x_cur + dy * dxdy;
- if (x_next < 0.0) {
- x_next = 0.0;
+ if (x_next < 0.0f) {
+ x_next = 0.0f;
}
float x0 = x_cur;
float x1 = x_next;
@@ -313,19 +313,19 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
float x1_ceil = ceil(x1);
u32 x0i = x0_floor;
- if (x1_ceil <= x0_floor + 1.0) {
+ if (x1_ceil <= x0_floor + 1.0f) {
// If x0 and x1 are within the same pixel, then area to the right is (1 - (mid(x0, x1) - x0_floor)) * dy
- float area = ((x0 + x1) * 0.5) - x0_floor;
- m_data[line_offset + x0i] += directed_dy * (1.0 - area);
+ float area = ((x0 + x1) * 0.5f) - x0_floor;
+ m_data[line_offset + x0i] += directed_dy * (1.0f - area);
m_data[line_offset + x0i + 1] += directed_dy * area;
} else {
- float dydx = 1.0 / dxdy;
+ float dydx = 1.0f / dxdy;
if (dydx < 0)
dydx = -dydx;
- float x0_right = 1.0 - (x0 - x0_floor);
+ float x0_right = 1.0f - (x0 - x0_floor);
u32 x1_floor_i = floor(x1);
- float area_upto_here = 0.5 * x0_right * x0_right * dydx;
+ float area_upto_here = 0.5f * x0_right * x0_right * dydx;
m_data[line_offset + x0i] += direction * area_upto_here;
for (u32 x = x0i + 1; x < x1_floor_i; x++) {
m_data[line_offset + x] += direction * dydx;
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index 322d741227..c7ca87bbf3 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -73,7 +73,7 @@ public:
if (is_undefined())
return fallback_for_undefined;
if (is_percentage())
- return make_px(raw_value() / 100.0 * reference_for_percent);
+ return make_px(raw_value() / 100.0f * reference_for_percent);
if (is_relative())
return make_px(to_px(layout_node));
return *this;
diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp
index a9f721dfef..e0353009bd 100644
--- a/Userland/Libraries/LibWeb/Dump.cpp
+++ b/Userland/Libraries/LibWeb/Dump.cpp
@@ -189,7 +189,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
if (show_box_model) {
// Dump the horizontal box properties
- builder.appendf(" [%g+%g+%g %g %g+%g+%g]",
+ builder.appendff(" [{}+{}+{} {} {}+{}+{}]",
box.box_model().margin.left,
box.box_model().border.left,
box.box_model().padding.left,
@@ -199,7 +199,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
box.box_model().margin.right);
// And the vertical box properties
- builder.appendf(" [%g+%g+%g %g %g+%g+%g]",
+ builder.appendff(" [{}+{}+{} {} {}+{}+{}]",
box.box_model().margin.top,
box.box_model().border.top,
box.box_model().padding.top,
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index da74eb1f50..db4c3052f8 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -219,13 +219,13 @@ DOM::ExceptionOr<void> CanvasRenderingContext2D::ellipse(float x, float y, float
if (radius_y < 0)
return DOM::IndexSizeError::create(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
- if ((!counter_clockwise && (end_angle - start_angle) >= M_TAU)
- || (counter_clockwise && (start_angle - end_angle) >= M_TAU)) {
+ if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau)
+ || (counter_clockwise && (start_angle - end_angle) >= tau)) {
start_angle = 0;
- end_angle = M_TAU;
+ end_angle = tau;
} else {
- start_angle = fmodf(start_angle, M_TAU);
- end_angle = fmodf(end_angle, M_TAU);
+ start_angle = fmodf(start_angle, tau);
+ end_angle = fmodf(end_angle, tau);
}
// Then, figure out where the ends of the arc are.
@@ -263,7 +263,7 @@ DOM::ExceptionOr<void> CanvasRenderingContext2D::ellipse(float x, float y, float
m_path.move_to(start_point);
- auto delta_theta = end_angle - start_angle;
+ double delta_theta = end_angle - start_angle;
// FIXME: This is still goofy for some values.
m_path.elliptical_arc_to(end_point, { radius_x, radius_y }, rotation, delta_theta > M_PI, !counter_clockwise);
diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
index a6a718aa8d..d97bc13852 100644
--- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
+++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp
@@ -516,7 +516,7 @@ Gfx::Path& SVGPathElement::get_path()
case PathInstructionType::EllipticalArc: {
double rx = data[0];
double ry = data[1];
- double x_axis_rotation = data[2] * M_DEG2RAD;
+ double x_axis_rotation = double { data[2] } * M_DEG2RAD;
double large_arc_flag = data[3];
double sweep_flag = data[4];
auto& last_point = path.segments().last().point();
diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp
index 0a4bdc3ed3..926f6cf212 100644
--- a/Userland/Services/WindowServer/ClientConnection.cpp
+++ b/Userland/Services/WindowServer/ClientConnection.cpp
@@ -616,7 +616,7 @@ void ClientConnection::handle(const Messages::WindowServer::DidFinishPainting& m
auto& window = *(*it).value;
for (auto& rect : message.rects())
window.invalidate(rect);
- if (window.has_alpha_channel() && window.alpha_hit_threshold() > 0.0)
+ if (window.has_alpha_channel() && window.alpha_hit_threshold() > 0.0f)
WindowManager::the().reevaluate_hovered_window(&window);
WindowSwitcher::the().refresh_if_needed();
@@ -940,11 +940,12 @@ OwnPtr<Messages::WindowServer::GetGlobalCursorPositionResponse> ClientConnection
OwnPtr<Messages::WindowServer::SetMouseAccelerationResponse> ClientConnection::handle(const Messages::WindowServer::SetMouseAcceleration& message)
{
- if (message.factor() < mouse_accel_min || message.factor() > mouse_accel_max) {
+ double factor = message.factor();
+ if (factor < mouse_accel_min || factor > mouse_accel_max) {
did_misbehave("SetMouseAcceleration with bad acceleration factor");
return {};
}
- WindowManager::the().set_acceleration_factor(message.factor());
+ WindowManager::the().set_acceleration_factor(factor);
return make<Messages::WindowServer::SetMouseAccelerationResponse>();
}
diff --git a/Userland/Services/WindowServer/Screen.h b/Userland/Services/WindowServer/Screen.h
index b43ba22cea..54d088e466 100644
--- a/Userland/Services/WindowServer/Screen.h
+++ b/Userland/Services/WindowServer/Screen.h
@@ -35,9 +35,9 @@ struct MousePacket;
namespace WindowServer {
-const double mouse_accel_max = 3.5;
-const double mouse_accel_min = 0.5;
-const unsigned scroll_step_size_min = 1;
+constexpr double mouse_accel_max = 3.5;
+constexpr double mouse_accel_min = 0.5;
+constexpr unsigned scroll_step_size_min = 1;
class Screen {
public: