From bce3abac409fbba3607d5b0220a5dc6a184b720b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 2 Jul 2014 15:47:09 +1000 Subject: [PATCH] build: remove implicit type casting warnings --- fixed.cpp | 7 +++++-- float.cpp | 2 +- maths.cpp | 4 ++-- noise.cpp | 2 +- options.cpp | 2 +- region.cpp | 8 ++++---- time.cpp | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fixed.cpp b/fixed.cpp index a5747d89..d121e143 100644 --- a/fixed.cpp +++ b/fixed.cpp @@ -47,8 +47,11 @@ fixed::to_double (void) const template float -fixed::to_float (void) const - { return m_value / std::pow (2.0f, FRAC); } +fixed::to_float (void) const { + return static_cast ( + m_value / std::pow (2.0f, FRAC) + ); +} template diff --git a/float.cpp b/float.cpp index ffafb0d0..a2eccd84 100644 --- a/float.cpp +++ b/float.cpp @@ -82,7 +82,7 @@ ieee_float::almost_equal (floating_t a, floating_t b) { // Static cast to avoid integer casting warnings when using uint16_t for half static const floating_t epsilon = static_cast (0.001); - const floating_t diff = fabs (a - b); + const floating_t diff = static_cast (std::fabs (a - b)); // * Use an exact equality first so that infinities are not indirectly compared. This would generate NaNs in the diff. // * Do not use gte or lte. This stops an infinite from making infinities on both sides of the inequality. diff --git a/maths.cpp b/maths.cpp index 5ae25e7e..4e7f422e 100644 --- a/maths.cpp +++ b/maths.cpp @@ -138,14 +138,14 @@ sign (T val) { template <> int sign (float val) { - return copysign (1.0, val); + return static_cast (copysign (1.0f, val)); } template <> int sign (double val) { - return copysign (1.0, val); + return static_cast (copysign (1.0, val)); } diff --git a/noise.cpp b/noise.cpp index da627b1e..a5df1d99 100644 --- a/noise.cpp +++ b/noise.cpp @@ -33,6 +33,6 @@ util::noise::image2d (uint8_t *restrict pixels, for (size_t y = 0; y < height; ++y) for (size_t x = 0; x < width; ++x) { double v = p.eval (x, y); - pixels[x + y * width] = v * std::numeric_limits::max (); + pixels[x + y * width] = static_cast (v * std::numeric_limits::max ()); } } diff --git a/options.cpp b/options.cpp index 3cb3ec89..de113c89 100644 --- a/options.cpp +++ b/options.cpp @@ -239,7 +239,7 @@ bytesoption::execute (const std::string& data) { // after reading the specifiers. --cursor; - multiplier = std::pow (modifier_factor, (int)specified); + multiplier = static_cast (std::pow (modifier_factor, (int)specified)); get_arg (data.substr(0, cursor + 1), m_data); *m_data *= multiplier; } catch (...) { diff --git a/region.cpp b/region.cpp index 606d1045..f61212e0 100644 --- a/region.cpp +++ b/region.cpp @@ -60,11 +60,11 @@ region::diameter (void) const { template void region::scale (double factor) { - x -= (w * factor - w) / 2.0; - y -= (h * factor - h) / 2.0; + x -= static_cast ((w * factor - w) / 2.0); + y -= static_cast ((h * factor - h) / 2.0); - w *= factor; - h *= factor; + w = static_cast (w * factor); + h = static_cast (h * factor); } diff --git a/time.cpp b/time.cpp index 09b8bb45..8254d465 100644 --- a/time.cpp +++ b/time.cpp @@ -95,7 +95,7 @@ delta_clock::seconds (void) { // ---------------------------------------------------------------------------- util::period_query::period_query (double seconds) { m_time.start = nanoseconds (); - m_time.period = seconds * SECOND; + m_time.period = static_cast (seconds * SECOND); }