mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 18:43:34 +08:00
Automated style fixes in order to bring the code a little bit closer to compliance with MISRA C++ rules. No changes in logic.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
} else { \
|
||||
*dst &= reverse_mask[dst_offset_modulo] | \
|
||||
reverse_mask_xor[dst_offset_modulo + src_len + 1]; \
|
||||
c &= reverse_mask[dst_offset_modulo + src_len]; \
|
||||
c &= reverse_mask[dst_offset_modulo + src_len]; \
|
||||
src_len = 0; \
|
||||
} } while (0)
|
||||
|
||||
|
||||
@@ -38,9 +38,13 @@ int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
*/
|
||||
const int write_res = buf_.write(bit_offset_ / 8, tmp, bytelen);
|
||||
if (write_res < 0)
|
||||
{
|
||||
return write_res;
|
||||
}
|
||||
if (write_res < bytelen)
|
||||
{
|
||||
return ResultOutOfBuffer;
|
||||
}
|
||||
|
||||
bit_offset_ = new_bit_offset;
|
||||
return ResultOk;
|
||||
@@ -55,9 +59,13 @@ int BitStream::read(uint8_t* bytes, const int bitlen)
|
||||
|
||||
const int read_res = buf_.read(bit_offset_ / 8, tmp, bytelen);
|
||||
if (read_res < 0)
|
||||
{
|
||||
return read_res;
|
||||
}
|
||||
if (read_res < bytelen)
|
||||
{
|
||||
return ResultOutOfBuffer;
|
||||
}
|
||||
|
||||
std::fill(bytes, bytes + bitlenToBytelen(bitlen), 0);
|
||||
copyBitArray(tmp, bit_offset_ % 8, bitlen, bytes, 0);
|
||||
@@ -72,14 +80,20 @@ std::string BitStream::toString() const
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
if (1 != buf_.read(offset, &byte, 1))
|
||||
{
|
||||
break;
|
||||
}
|
||||
for (int i = 7; i >= 0; i--) // Most significant goes first
|
||||
{
|
||||
os << !!(byte & (1 << i));
|
||||
}
|
||||
os << " ";
|
||||
}
|
||||
std::string output = os.str();
|
||||
if (output.length())
|
||||
{
|
||||
output.erase(output.length() - 1, 1);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,27 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
|
||||
{
|
||||
uint16_t hbits = signbit(value) << 15;
|
||||
if (value == 0.0f)
|
||||
{
|
||||
return hbits;
|
||||
}
|
||||
if (isnanf(value))
|
||||
{
|
||||
return hbits | 0x7FFF;
|
||||
}
|
||||
if (isinff(value))
|
||||
{
|
||||
return hbits | 0x7C00;
|
||||
}
|
||||
int exp;
|
||||
std::frexp(value, &exp);
|
||||
if (exp > 16)
|
||||
{
|
||||
return hbits | 0x7C00;
|
||||
}
|
||||
if (exp < -13)
|
||||
{
|
||||
value = std::ldexp(value, 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = std::ldexp(value, 11 - exp);
|
||||
@@ -50,14 +60,22 @@ float IEEE754Converter::halfToNativeNonIeee(uint16_t value)
|
||||
float out;
|
||||
int abs = value & 0x7FFF;
|
||||
if (abs > 0x7C00)
|
||||
{
|
||||
out = std::numeric_limits<float>::has_quiet_NaN ? std::numeric_limits<float>::quiet_NaN() : 0.0f;
|
||||
}
|
||||
else if (abs == 0x7C00)
|
||||
{
|
||||
out = std::numeric_limits<float>::has_infinity ?
|
||||
std::numeric_limits<float>::infinity() : std::numeric_limits<float>::max();
|
||||
std::numeric_limits<float>::infinity() : std::numeric_limits<float>::max();
|
||||
}
|
||||
else if (abs > 0x3FF)
|
||||
{
|
||||
out = std::ldexp(static_cast<float>((value & 0x3FF) | 0x400), (abs >> 10) - 25);
|
||||
}
|
||||
else
|
||||
{
|
||||
out = std::ldexp(static_cast<float>(abs), -24);
|
||||
}
|
||||
return (value & 0x8000) ? -out : out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user