Prevent shift overflow in FloatTo7e3/FloatTo6e4 (#129)
This commit is contained in:
parent
00b785eea1
commit
c7261a0951
@ -37,7 +37,7 @@ namespace
|
|||||||
{
|
{
|
||||||
// The number is too small to be represented as a normalized 7e3.
|
// The number is too small to be represented as a normalized 7e3.
|
||||||
// Convert it to a denormalized value.
|
// Convert it to a denormalized value.
|
||||||
uint32_t Shift = 125U - (IValue >> 23U);
|
uint32_t Shift = std::min<uint32_t>(125U - (IValue >> 23U), 24U);
|
||||||
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
|
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -103,7 +103,7 @@ namespace
|
|||||||
{
|
{
|
||||||
// The number is too small to be represented as a normalized 6e4.
|
// The number is too small to be represented as a normalized 6e4.
|
||||||
// Convert it to a denormalized value.
|
// Convert it to a denormalized value.
|
||||||
uint32_t Shift = 121U - (IValue >> 23U);
|
uint32_t Shift = std::min<uint32_t>(121U - (IValue >> 23U), 24U);
|
||||||
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
|
IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user