U suffix for unsigned constants

This commit is contained in:
Pavel Kirienko
2014-04-18 20:17:54 +04:00
parent fd71f55933
commit c9ede31d56
3 changed files with 45 additions and 45 deletions
+2 -2
View File
@@ -24,8 +24,8 @@ namespace uavcan
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset)
{
static const unsigned char reverse_mask[] = { 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
static const unsigned char reverse_mask_xor[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
static const unsigned char reverse_mask[] = { 0x55U, 0x80U, 0xc0U, 0xe0U, 0xf0U, 0xf8U, 0xfcU, 0xfeU, 0xffU };
static const unsigned char reverse_mask_xor[] = { 0xffU, 0x7fU, 0x3fU, 0x1fU, 0x0fU, 0x07U, 0x03U, 0x01U, 0x00U };
if (src_len > 0)
{
+11 -11
View File
@@ -60,17 +60,17 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
}
if (isnan(value))
{
return hbits | 0x7FFF;
return hbits | 0x7FFFU;
}
if (isinf(value))
{
return hbits | 0x7C00;
return hbits | 0x7C00U;
}
int exp;
std::frexp(value, &exp);
if (exp > 16)
{
return hbits | 0x7C00;
return hbits | 0x7C00U;
}
if (exp < -13)
{
@@ -81,8 +81,8 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
value = std::ldexp(value, 11 - exp);
hbits |= ((exp + 14) << 10);
}
const int ival = static_cast<int>(value);
hbits |= static_cast<uint16_t>(std::abs(ival) & 0x3FF);
const int32_t ival = static_cast<int32_t>(value);
hbits |= static_cast<uint16_t>(std::abs(ival) & 0x3FFU);
float diff = std::abs(value - static_cast<float>(ival));
hbits += diff >= 0.5f;
return hbits;
@@ -91,25 +91,25 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
float IEEE754Converter::halfToNativeNonIeee(uint16_t value)
{
float out;
int abs = value & 0x7FFF;
if (abs > 0x7C00)
unsigned abs = value & 0x7FFFU;
if (abs > 0x7C00U)
{
out = std::numeric_limits<float>::has_quiet_NaN ? std::numeric_limits<float>::quiet_NaN() : 0.0f;
}
else if (abs == 0x7C00)
else if (abs == 0x7C00U)
{
out = std::numeric_limits<float>::has_infinity ?
std::numeric_limits<float>::infinity() : std::numeric_limits<float>::max();
}
else if (abs > 0x3FF)
else if (abs > 0x3FFU)
{
out = std::ldexp(static_cast<float>((value & 0x3FF) | 0x400), (abs >> 10) - 25);
out = std::ldexp(static_cast<float>((value & 0x3FFU) | 0x400U), (abs >> 10) - 25);
}
else
{
out = std::ldexp(static_cast<float>(abs), -24);
}
return (value & 0x8000) ? -out : out;
return (value & 0x8000U) ? -out : out;
}
}