Skip to content

Commit e389dbb

Browse files
committed
Fix conversion errors
1 parent e9b0200 commit e389dbb

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

include/boost/decimal/dpd_conversion.hpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -233,72 +233,72 @@ constexpr auto encode_dpd(std::uint8_t d1, std::uint8_t d2, std::uint8_t d3) ->
233233
return result;
234234
}
235235

236-
constexpr auto decode_dpd(std::uint32_t dpd_bits, std::uint8_t &d3, std::uint8_t &d2, std::uint8_t &d1) -> void
236+
constexpr auto decode_dpd(std::uint32_t dpd_bits, std::uint8_t& d3, std::uint8_t& d2, std::uint8_t& d1) -> void
237237
{
238238
// DPD decoding logic as per IEEE 754-2008
239239
std::uint8_t b[10] {};
240240
for (int i = 0; i < 10; ++i)
241241
{
242-
b[i] = (dpd_bits >> (9 - i)) & 0b1;
242+
b[i] = static_cast<std::uint8_t>((dpd_bits >> (9 - i)) & 0b1);
243243
}
244244

245245
// See table 3.3 for the flow of decoding
246246
// Values are b6, b7, b8, b3, b4
247247
// 0XXXX
248248
if (b[6] == 0U)
249249
{
250-
d1 = 4U * b[0] + 2U * b[1] + b[2];
251-
d2 = 4U * b[3] + 2U * b[4] + b[5];
252-
d3 = 4U * b[7] + 2U * b[8] + b[9];
250+
d1 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[2]);
251+
d2 = static_cast<std::uint8_t>((b[3] << 2U) + (b[4] << 1U) + b[5]);
252+
d3 = static_cast<std::uint8_t>((b[7] << 2U) + (b[8] << 1U) + b[9]);
253253
}
254254
// 100XX
255255
else if (b[6] == 1U && b[7] == 0U && b[8] == 0U)
256256
{
257-
d1 = 4U * b[0] + 2U * b[1] + b[2];
258-
d2 = 4U * b[3] + 2U * b[4] + b[5];
259-
d3 = 8U + b[9];
257+
d1 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[2]);
258+
d2 = static_cast<std::uint8_t>((b[3] << 2U) + (b[4] << 1U) + b[5]);
259+
d3 = static_cast<std::uint8_t>(8) + b[9];
260260
}
261261
// 101XX
262262
else if (b[6] == 1U && b[7] == 0U && b[8] == 1U)
263263
{
264-
d1 = 4U * b[0] + 2U * b[1] + b[2];
265-
d2 = 8U + b[5];
266-
d3 = 4U * b[3] + 2U * b[4] + b[9];
264+
d1 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[2]);
265+
d2 = static_cast<std::uint8_t>(8) + b[5];
266+
d3 = static_cast<std::uint8_t>((b[3] << 2U) + (b[4] << 1U) + b[9]);
267267
}
268268
// 110XX
269269
else if (b[6] == 1U && b[7] == 1U && b[8] == 0U)
270270
{
271-
d1 = 8U + b[2];
272-
d2 = 4U * b[3] + 2U * b[4] + b[5];
273-
d3 = 4U * b[0] + 2U * b[1] + b[9];
271+
d1 = static_cast<std::uint8_t>(8) + b[2];
272+
d2 = static_cast<std::uint8_t>((b[3] << 2U) + (b[4] << 1U) + b[5]);
273+
d3 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[9]);
274274
}
275275
// 11100
276276
else if (b[6] == 1U && b[7] == 1U && b[8] == 1U && b[3] == 0U && b[4] == 0U)
277277
{
278-
d1 = 8U + b[2];
279-
d2 = 8U + b[5];
280-
d3 = 4U * b[0] + 2U * b[1] + b[9];
278+
d1 = static_cast<std::uint8_t>(8) + b[2];
279+
d2 = static_cast<std::uint8_t>(8) + b[5];
280+
d3 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[9]);
281281
}
282282
// 11101
283283
else if (b[6] == 1U && b[7] == 1U && b[8] == 1U && b[3] == 0U && b[4] == 1U)
284284
{
285-
d1 = 8U + b[2];
286-
d2 = 4U * b[0] + 2U * b[1] + b[5];
287-
d3 = 8U + b[9];
285+
d1 = static_cast<std::uint8_t>(8) + b[2];
286+
d2 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[5]);
287+
d3 = static_cast<std::uint8_t>(8) + b[9];
288288
}
289289
// 11110
290290
else if (b[6] == 1U && b[7] == 1U && b[8] == 1U && b[3] == 1U && b[4] == 0U)
291291
{
292-
d1 = 4U * b[0] + 2U * b[1] + b[2];
293-
d2 = 8U + b[5];
294-
d3 = 8U + b[9];
292+
d1 = static_cast<std::uint8_t>((b[0] << 2U) + (b[1] << 1U) + b[2]);
293+
d2 = static_cast<std::uint8_t>(8) + b[5];
294+
d3 = static_cast<std::uint8_t>(8) + b[9];
295295
}
296296
// 11111
297297
else if (b[6] == 1U && b[7] == 1U && b[8] == 1U && b[3] == 1U && b[4] == 1U)
298298
{
299-
d1 = 8U + b[2];
300-
d2 = 8U + b[5];
301-
d3 = 8U + b[9];
299+
d1 = static_cast<std::uint8_t>(8) + b[2];
300+
d2 = static_cast<std::uint8_t>(8) + b[5];
301+
d3 = static_cast<std::uint8_t>(8) + b[9];
302302
}
303303
else
304304
{
@@ -338,8 +338,8 @@ constexpr auto to_dpd_d32(DecimalType val) noexcept
338338
auto temp_sig {significand};
339339
for (int i = 6; i >= 0; --i)
340340
{
341-
d[i] = temp_sig % 10;
342-
temp_sig /= 10;
341+
d[i] = static_cast<std::uint8_t>(temp_sig % 10U);
342+
temp_sig /= 10U;
343343
}
344344
BOOST_DECIMAL_ASSERT(d[0] >= 0 && d[0] <= 9);
345345
BOOST_DECIMAL_ASSERT(temp_sig == 0);
@@ -466,7 +466,7 @@ constexpr auto from_dpd_d32(std::uint32_t dpd) noexcept
466466
// leading exp bits are 2*G2 + G3
467467
// Must be equal to 0, 1 or 2
468468
leading_biased_exp_bits = 2U * ((combination_field_bits & 0b00100) >> 2U) + ((combination_field_bits & 0b00010) >> 1U);
469-
BOOST_DECIMAL_ASSERT(leading_biased_exp_bits >= 0U && leading_biased_exp_bits <= 2U);
469+
BOOST_DECIMAL_ASSERT(leading_biased_exp_bits <= 2U);
470470
}
471471
// Case 2: 3.5.2.c.1.ii
472472
// Combination field bits are 0XXXX or 10XXX
@@ -475,12 +475,12 @@ constexpr auto from_dpd_d32(std::uint32_t dpd) noexcept
475475
// d0 = 4 * G2 + 2 * G3 + G4
476476
// Must be in the range 0-7
477477
d0 = combination_field_bits & 0b00111;
478-
BOOST_DECIMAL_ASSERT(d0 >= 0 && d0 <= 7);
478+
BOOST_DECIMAL_ASSERT(d0 <= 7);
479479

480480
// Leading exp bits are 2 * G0 + G1
481481
// Must be equal to 0, 1 or 2
482482
leading_biased_exp_bits = (combination_field_bits & 0b11000) >> 3U;
483-
BOOST_DECIMAL_ASSERT(leading_biased_exp_bits >= 0U && leading_biased_exp_bits <= 2U);
483+
BOOST_DECIMAL_ASSERT(leading_biased_exp_bits <= 2U);
484484
}
485485

486486
// Now that we have the bits we can calculate the exponents value

0 commit comments

Comments
 (0)