Commit bd2452c9 authored by Dominik Charousset's avatar Dominik Charousset

Fix conversion warnings

parent 74812501
......@@ -92,14 +92,14 @@ typename ieee_754_trait<T>::packed_type pack754(T f) {
}
fnorm = fnorm - static_cast<T>(1);
// calculate 2^significandbits
auto pownum = static_cast<result_type>(1) << significandbits;
auto pownum = static_cast<T>(result_type{1} << significandbits);
// calculate the binary form (non-float) of the significand data
auto significand = static_cast<result_type>(fnorm * (pownum + trait::p5));
// get the biased exponent
auto exp = shift + ((1 << (trait::expbits - 1)) - 1); // shift + bias
// return the final answer
return (sign << (trait::bits - 1)) |
(exp << (trait::bits - trait::expbits - 1)) | significand;
return (sign << (trait::bits - 1))
| (exp << (trait::bits - trait::expbits - 1)) | significand;
}
template <class T>
......@@ -109,11 +109,10 @@ typename ieee_754_trait<T>::float_type unpack754(T i) {
using result_type = typename trait::float_type;
if (i == 0) return trait::zero;
auto significandbits = trait::bits - trait::expbits - 1; // -1 for sign bit
// pull the significand
result_type result =
(i & ((static_cast<T>(1) << significandbits) - 1)); // mask
result /= (static_cast<T>(1) << significandbits); // convert back to float
result += static_cast<result_type>(1); // add the one back on
// pull the significand: mask, convert back to float + add the one back on
auto result = static_cast<result_type>(i & ((T{1} << significandbits) - 1));
result /= static_cast<result_type>(T{1} << significandbits);
result += static_cast<result_type>(1);
// deal with the exponent
auto si = static_cast<signed_type>(i);
auto bias = (1 << (trait::expbits - 1)) - 1;
......
......@@ -68,8 +68,9 @@ void host_id_from_string(const std::string& hash,
for (size_t i = 0; i < node_id.size(); ++i) {
// read two characters, each representing 4 bytes
auto& val = node_id[i];
val = static_cast<uint8_t>(hex_char_value(*j++) << 4);
val |= hex_char_value(*j++);
val = static_cast<uint8_t>(hex_char_value(j[0]) << 4)
| hex_char_value(j[1]);
j += 2;
}
}
......@@ -84,8 +85,9 @@ bool equal(const std::string& hash, const node_id::host_id_type& node_id) {
for (size_t i = 0; i < node_id.size(); ++i) {
// read two characters, each representing 4 bytes
uint8_t val;
val = static_cast<uint8_t>(hex_char_value(*j++) << 4);
val |= hex_char_value(*j++);
val = static_cast<uint8_t>(hex_char_value(j[0]) << 4)
| hex_char_value(j[1]);
j += 2;
if (val != node_id[i]) {
return false;
}
......
......@@ -65,6 +65,8 @@ namespace {
using byte = unsigned char;
using dword = uint32_t;
static_assert(sizeof(dword) == sizeof(unsigned), "platform not supported");
// macro definitions
// collect four bytes into one word:
......@@ -95,28 +97,28 @@ using dword = uint32_t;
#define GG(a, b, c, d, e, x, s) \
{ \
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL; \
(a) += G((b), (c), (d)) + (x) + 0x5a827999U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define HH(a, b, c, d, e, x, s) \
{ \
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL; \
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define II(a, b, c, d, e, x, s) \
{ \
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL; \
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcU; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define JJ(a, b, c, d, e, x, s) \
{ \
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL; \
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eU; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
......@@ -130,28 +132,28 @@ using dword = uint32_t;
#define GGG(a, b, c, d, e, x, s) \
{ \
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL; \
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define HHH(a, b, c, d, e, x, s) \
{ \
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL; \
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define III(a, b, c, d, e, x, s) \
{ \
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL; \
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
#define JJJ(a, b, c, d, e, x, s) \
{ \
(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL; \
(a) += J((b), (c), (d)) + (x) + 0x50a28be6U; \
(a) = ROL((a), (s)) + (e); \
(c) = ROL((c), 10); \
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment