build: remove implicit type casting warnings

This commit is contained in:
Danny Robson 2014-07-02 15:47:09 +10:00
parent d1ed7107ae
commit bce3abac40
7 changed files with 15 additions and 12 deletions

View File

@ -47,8 +47,11 @@ fixed<INT, FRAC>::to_double (void) const
template <unsigned int INT, unsigned int FRAC>
float
fixed<INT, FRAC>::to_float (void) const
{ return m_value / std::pow (2.0f, FRAC); }
fixed<INT, FRAC>::to_float (void) const {
return static_cast<float> (
m_value / std::pow (2.0f, FRAC)
);
}
template <unsigned int INT, unsigned int FRAC>

View File

@ -82,7 +82,7 @@ ieee_float<E, S>::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<floating_t> (0.001);
const floating_t diff = fabs (a - b);
const floating_t diff = static_cast<floating_t> (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.

View File

@ -138,14 +138,14 @@ sign (T val) {
template <>
int
sign (float val) {
return copysign (1.0, val);
return static_cast<int> (copysign (1.0f, val));
}
template <>
int
sign (double val) {
return copysign (1.0, val);
return static_cast<int> (copysign (1.0, val));
}

View File

@ -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<uint8_t>::max ();
pixels[x + y * width] = static_cast<uint8_t> (v * std::numeric_limits<uint8_t>::max ());
}
}

View File

@ -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<uintmax_t> (std::pow (modifier_factor, (int)specified));
get_arg (data.substr(0, cursor + 1), m_data);
*m_data *= multiplier;
} catch (...) {

View File

@ -60,11 +60,11 @@ region<T>::diameter (void) const {
template <typename T>
void
region<T>::scale (double factor) {
x -= (w * factor - w) / 2.0;
y -= (h * factor - h) / 2.0;
x -= static_cast<T> ((w * factor - w) / 2.0);
y -= static_cast<T> ((h * factor - h) / 2.0);
w *= factor;
h *= factor;
w = static_cast<T> (w * factor);
h = static_cast<T> (h * factor);
}

View File

@ -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<uint64_t> (seconds * SECOND);
}