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> template <unsigned int INT, unsigned int FRAC>
float float
fixed<INT, FRAC>::to_float (void) const fixed<INT, FRAC>::to_float (void) const {
{ return m_value / std::pow (2.0f, FRAC); } return static_cast<float> (
m_value / std::pow (2.0f, FRAC)
);
}
template <unsigned int INT, unsigned int 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) { floating_t b) {
// Static cast to avoid integer casting warnings when using uint16_t for half // Static cast to avoid integer casting warnings when using uint16_t for half
static const floating_t epsilon = static_cast<floating_t> (0.001); 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. // * 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. // * 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 <> template <>
int int
sign (float val) { sign (float val) {
return copysign (1.0, val); return static_cast<int> (copysign (1.0f, val));
} }
template <> template <>
int int
sign (double val) { 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 y = 0; y < height; ++y)
for (size_t x = 0; x < width; ++x) { for (size_t x = 0; x < width; ++x) {
double v = p.eval (x, y); 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. // after reading the specifiers.
--cursor; --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); get_arg (data.substr(0, cursor + 1), m_data);
*m_data *= multiplier; *m_data *= multiplier;
} catch (...) { } catch (...) {

View File

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

View File

@ -95,7 +95,7 @@ delta_clock::seconds (void) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
util::period_query::period_query (double seconds) { util::period_query::period_query (double seconds) {
m_time.start = nanoseconds (); m_time.start = nanoseconds ();
m_time.period = seconds * SECOND; m_time.period = static_cast<uint64_t> (seconds * SECOND);
} }